0
我得到一个非常简单的错误。我创建了一个测试按钮和一个onClick方法来改变布局。以一种简单的方式做到了,所以你可以更好地理解我的问题。在父代或祖先上下文中找不到Onclick方法
这是我的按钮方法
public void accountButton (View v){
setContentView(R.layout.activity_start);
}
,这是我的按钮
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:id="@+id/button"
android:layout_below="@+id/welcomeTxt"
android:layout_centerHorizontal="true"
android:layout_marginTop="149dp"
android:onClick="accountButton"
android:nestedScrollingEnabled="true" />
的xml文件,我得到以下错误,当我按一下按钮
的Java。 lang.IllegalStateException:无法找到方法 accountButton(View)在父代或祖先上下文中的 安卓:onclick属性定义的视图类 android.support.v7.widget.AppCompatButton ID为 '按钮'
安置自己的活动代码太方法。 –