据说看这种错误要看最后一个,java.lang.NoSuchMethodException:
原因很简单,底下这个构造方法应该是public的,而我没写权限,变成了default
加上public后问题解决,
还有自定义View时,构造方法时要调用super(context, attrs); 方法
总结:细节,细心很重要.........
异常如下
04-09 10:09:52.838: ERROR/AndroidRuntime(600): Uncaught handler: thread main exiting due to uncaught exception
04-09 10:09:52.877: ERROR/AndroidRuntime(600): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uyu.gesturepro/com.uyu.gesturepro.gesturepro}: android.view.InflateException: Binary XML file line #22: Error inflating class com.uyu.gesturepro.My_SurfaceView
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.os.Looper.loop(Looper.java:123)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.ActivityThread.main(ActivityThread.java:4203)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at java.lang.reflect.Method.invokeNative(Native Method)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at java.lang.reflect.Method.invoke(Method.java:521)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at dalvik.system.NativeStart.main(Native Method)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.uyu.gesturepro.My_SurfaceView
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.createView(LayoutInflater.java:502)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.Activity.setContentView(Activity.java:1620)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at com.uyu.gesturepro.gesturepro.onCreate(gesturepro.java:35)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): ... 11 more
04-09 10:09:52.877: ERROR/AndroidRuntime(600): Caused by: java.lang.NoSuchMethodException: My_SurfaceView(Context,AttributeSet)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at java.lang.Class.getMatchingConstructor(Class.java:669)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at java.lang.Class.getConstructor(Class.java:484)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): at android.view.LayoutInflater.createView(LayoutInflater.java:474)
04-09 10:09:52.877: ERROR/AndroidRuntime(600): ... 22 more