Android 当按钮用于调用新活动时,应用程序崩溃
我正在使用一个按钮转到应用程序中的“关于”页面,但每当单击该按钮时,应用程序就会崩溃。没有gradle生成错误 在父类中,我使用了以下代码。这段代码在过去对我来说没有任何问题。每当我将鼠标悬停在按钮2上时,它会声明从未使用过“button2(android.view.view)”,我已经导入了上面的android view.viewAndroid 当按钮用于调用新活动时,应用程序崩溃,android,android-studio,android-activity,android-button,Android,Android Studio,Android Activity,Android Button,我正在使用一个按钮转到应用程序中的“关于”页面,但每当单击该按钮时,应用程序就会崩溃。没有gradle生成错误 在父类中,我使用了以下代码。这段代码在过去对我来说没有任何问题。每当我将鼠标悬停在按钮2上时,它会声明从未使用过“button2(android.view.view)”,我已经导入了上面的android view.view public void button2(View view){ Intent intent = new Intent(this, prepo.class);
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>
已解决,xml中的更改来自
android:onClick="button2 (BitRates)"
对此
android:onClick="button2" />
将按钮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" />
上述代码所做的是,它将触发活动的方法
按钮2
。早些时候,它正在搜索以下方法名称:button2(比特率)
在您的acitvity中发布错误日志!在布局xml中发布logcat errors@MrPoolUse onClick,如下所示:onClick=“button2”,并检查发布的错误日志为什么不使用按钮的onClickListener?
android:onClick="button2" />
<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" />