我创建了一个android项目。我试图开新活动。但我得到了错误。
我的代码:
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="141dp"
android:id="@+id/btn1"
android:onClick="onClickA" />
public void onClickA()
{
startActivity(new Intent(this,LoginActivity.class));
}
错误
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.i, PID: 1635
java.lang.IllegalStateException: Could not find method onClickA(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'btn1'
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:5609)
at android.view.View$PerformClick.run(View.java:22259)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
你能帮忙解决这个错误吗?
谢谢。
答案 0 :(得分:1)
将方法代码更改为
public void onClickA(View v)
{
startActivity(new Intent(this,LoginActivity.class));
}
答案 1 :(得分:1)
docker run -i -t -d -p 8000:8000 c4ba9ec8e613 /bin/bash
docker attach c4ba9ec8e613