代码:
public class HomeActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
public void onClick() {
Intent i=new Intent(this,Login.class);
startActivity(i);
}
}
崩溃:
---------崩溃开始
06-30 18:57:36.762 3115-3115/com.example.aakash.rozgari E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aakash.rozgari, PID: 3115
java.lang.IllegalStateException: Could not find method onClick(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:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25883)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6642)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
06-30 18:57:36.796 3115-3115/com.example.aakash.rozgari I/Process: Sending signal. PID: 3115 SIG: 9
答案 0 :(得分:0)
正如@ADM在对您的“答案” @Akash的评论中所述,您的onClick
方法没有正确的onClick method signature,因此java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context
异常。