Android运行时错误:无法执行android:onClick的方法

时间:2016-08-26 06:37:22

标签: android-studio

我是Android开发的新手,在运行我的应用时遇到了这个错误:

FATAL EXCEPTION: main
  Process: com.example.brayo.allgps, PID: 2204
  java.lang.IllegalStateException: Could not execute method for android:onClick
      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
      at android.view.View.performClick(View.java:5198)
      at android.view.View$PerformClick.run(View.java:21147)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
   Caused by: java.lang.reflect.InvocationTargetException
      at java.lang.reflect.Method.invoke(Native Method)
      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
      at android.view.View.performClick(View.java:5198) 
      at android.view.View$PerformClick.run(View.java:21147) 
      at android.os.Handler.handleCallback(Handler.java:739) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.brayo.allgps/com.example.brayo.allgps.GPSDraw}; have you declared this activity in your AndroidManifest.xml?
      at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
      at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
      at android.app.Activity.startActivityForResult(Activity.java:3917)
      at android.app.Activity.startActivityForResult(Activity.java:3877)
      at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
      at android.app.Activity.startActivity(Activity.java:4200)
      at android.app.Activity.startActivity(Activity.java:4168)
      at com.example.brayo.allgps.MainActivity.onClickSwitchActivity(MainActivity.java:111)
      at java.lang.reflect.Method.invoke(Native Method) 
      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270) 
      at android.view.View.performClick(View.java:5198) 
      at android.view.View$PerformClick.run(View.java:21147) 
      at android.os.Handler.handleCallback(Handler.java:739) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
08-26 07:58:08.086 2204-2212/com.example.brayo.allgps W/art: Suspending all threads took: 458.626ms

1 个答案:

答案 0 :(得分:0)

通过查看错误日志,您似乎已声明了视图的onClick属性(可能是按钮),但尚未在您的活动类中定义该函数。

请更新您的活动和XML布局文件。