1
私のアプリケーションのaboutページに移動するのに、ボタンをクリックするたびにアプリケーションがクラッシュします。グラデルビルドのエラーはありません。ボタンを使用して新しいアクティビティを呼び出すと、アプリケーションがクラッシュする
親クラスでは、このコードを使用しました。このコードは過去に何の問題もなく私のために働いてきました。ボタン2の上にマウスを置くと、 'button2(android.view.View)'が使用されることはありません。上記のAndroidビューをインポートしました。
public void button2(View view){
Intent intent = new Intent(this, prepo.class);
startActivity(intent);
}
これをAndroidマニフェストで使用しました。
<activity
android:name=".prepo"
android:label="About"
android:parentActivityName=".BitRates">
</activity>
親クラスのmy xmlは次のとおりです。
<Button
android:text="About"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView6"
android:layout_centerHorizontal="true"
android:id="@+id/button2"
style="@style/Widget.AppCompat.Button.Borderless"
android:background="?android:attr/colorBackground"
android:backgroundTint="?android:attr/colorBackground"
android:onClick="button2 (BitRates)" />
私はこれをアプリケーションの開発に使用していますが、エラーやクラッシュはなく機能しています。
編集:
エラーログ。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.name, PID: 3101
java.lang.IllegalStateException: Could not find method button2 (BitRates)(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'button2'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:307)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:266)
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)
Application terminated.
はこれにこの
android:onClick="button2" />
エラーログを投稿してください! – Sid
あなたのlogcatエラーを投稿する@MrPool – SaravInfern
レイアウトXMLでonroid = onClick = "button2"のようにonClickを使用し、 –