LOGCAT在运行我的应用程序时显示此错误

时间:2019-07-06 08:36:07

标签: java android

LOGCAT错误阻止我打开MAP活动并停止 工作。

2019-07-03 17:12:01.642 29273-29273/com.example.ess E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.ess, PID: 29273
    java.lang.IllegalStateException: Could not find method map(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatImageView with id 'imageView5'
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:424)
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:381)
        at android.view.View.performClick(View.java:6993)
        at android.view.View$PerformClick.run(View.java:26512)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7025)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

1 个答案:

答案 0 :(得分:0)

您在布局xml中应用了android:onClick=map属性。
如您在日志中所见,它位于ImageView android.support.v7.widget.AppCompatImageView中,带有android:id=@+id/imageView5

所以:

  • 删除此行:android:onClick="map",并使用OnClickListener
  • 处理点击
  • 在应用布局的“活动”中创建此方法:
public void map(View v) {}