【发布时间】:2017-01-01 14:42:08
【问题描述】:
我得到一个非常简单的错误。我创建了一个测试按钮和一个 onClick 方法来更改布局。我以一种简单的方式做到了,这样你就可以更好地理解我的问题。
这是我的按钮方法:
public void accountButton (View v){
setContentView(R.layout.activity_start);
}
这是我的按钮的 xml 文件:
<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" />
单击按钮时出现以下错误:
java.lang.IllegalStateException:找不到方法 accountButton(View) 在父或祖先上下文中 android:onClick 属性定义在视图类上 android.support.v7.widget.AppCompatButton 与 id '按钮'
【问题讨论】:
-
也发布您的活动代码。
标签: java android buttonclick android-appcompat