我的项目似乎在调试变体中工作正常但在我尝试使用发布版本签名版本时崩溃。我创建的其他一些应用程序也出现了同样的问题。
我的logcat :
08-11 14:46:08.142 3809-3809/com.example.android.courtcounter W/System: ClassLoader referenced unknown path: /data/app/com.example.android.courtcounter-1/lib/x86
08-11 14:46:08.342 3809-3809/com.example.android.courtcounter W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-11 14:46:08.919 3809-3829/com.example.android.courtcounter D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[08-11 14:46:08.923 3809: 3809 D/ ]
HostConnection::get() New Host Connection established 0xaa3dbfb0, tid 3809
[08-11 14:46:08.980 3809: 3829 D/ ]
HostConnection::get() New Host Connection established 0xae3c7330, tid 3829
08-11 14:46:09.012 3809-3829/com.example.android.courtcounter I/OpenGLRenderer: Initialized EGL, version 1.4
08-11 14:46:15.091 3809-3809/com.example.android.courtcounter D/AndroidRuntime: Shutting down VM
08-11 14:46:15.091 3809-3809/com.example.android.courtcounter E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.courtcounter, PID: 3809
java.lang.IllegalStateException: Could not find method point2A(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.courtcounter.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"
android:padding="0dp"
android:text="Team A"
android:textSize="14sp" />
<TextView
android:id="@+id/scoreA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#000000"
android:padding="16dp"
android:fontFamily="sans-serif-light"
android:text="0"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:onClick="point2A"
android:text="+2 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:onClick="point3A"
android:text="+3 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:onClick="freeThrowA"
android:text="Free Throw" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#666666"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingBottom="0dp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"
android:text="Team B"
android:textSize="14sp" />
<TextView
android:id="@+id/scoreB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="16dp"
android:fontFamily="sans-serif-light"
android:textColor="#000000"
android:text="0"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:onClick="point2B"
android:text="+2 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:onClick="point3B"
android:text="+3 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:onClick="freeThrowB"
android:text="Free Throw" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:layout_margin="4dp"
android:onClick="reset"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
MainActivity.java
package com.example.android.courtcounter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
int pointsA=0, pointsB=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//Team A Methods//
void point2A(View view)
{
pointsA+=2;
displayA();
}
void point3A(View view)
{
pointsA+=3;
displayA();
}
public void freeThrowA(View view)
{
pointsA+=1;
displayA();
}
public void displayA()
{
TextView scoreView = (TextView) findViewById(R.id.scoreA);
scoreView.setText(String.valueOf(pointsA));
}
//Team B methods//
void point2B(View view)
{
pointsB+=2;
displayB();
}
void point3B(View view)
{
pointsB+=3;
displayB();
}
public void freeThrowB(View view)
{
pointsB+=1;
displayB();
}
public void displayB()
{
TextView scoreView = (TextView)
findViewById(R.id.scoreB);
scoreView.setText(String.valueOf(pointsB));
}
//Reset//
void reset(View view)
{
pointsA=0;
pointsB=0;
displayB();
displayA();
}
}
答案 0 :(得分:1)
尝试在所有方法之前添加public
。