我在logcat中遇到了一个奇怪的错误,我已经尝试了我能想到的所有方法来解决它,但仍然无法解决。
以下是logcat:
11-08 12:30:26.184: E/AndroidRuntime(4396): FATAL EXCEPTION: main
11-08 12:30:26.184: E/AndroidRuntime(4396): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dm.test/com.dm.test.ui.BitCanvasActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class com.dm.test.ui.BitCanvasActivity$CanvasView
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1696)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.os.Looper.loop(Looper.java:123)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.ActivityThread.main(ActivityThread.java:3806)
11-08 12:30:26.184: E/AndroidRuntime(4396): at java.lang.reflect.Method.invokeNative(Native Method)
11-08 12:30:26.184: E/AndroidRuntime(4396): at java.lang.reflect.Method.invoke(Method.java:507)
11-08 12:30:26.184: E/AndroidRuntime(4396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-08 12:30:26.184: E/AndroidRuntime(4396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-08 12:30:26.184: E/AndroidRuntime(4396): at dalvik.system.NativeStart.main(Native Method)
11-08 12:30:26.184: E/AndroidRuntime(4396): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class com.dm.test.ui.BitCanvasActivity$CanvasView
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.createView(LayoutInflater.java:508)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.inflate(LayoutInflater.java:383)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-08 12:30:26.184: E/AndroidRuntime(4396): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.Activity.setContentView(Activity.java:1716)
11-08 12:30:26.184: E/AndroidRuntime(4396): at com.dm.test.ui.BitCanvasActivity.onCreate(BitCanvasActivity.java:55)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
11-08 12:30:26.184: E/AndroidRuntime(4396): ... 11 more
11-08 12:30:26.184: E/AndroidRuntime(4396): Caused by: java.lang.NoSuchMethodException: CanvasView(Context,AttributeSet)
11-08 12:30:26.184: E/AndroidRuntime(4396): at java.lang.Class.getMatchingConstructor(Class.java:643)
11-08 12:30:26.184: E/AndroidRuntime(4396): at java.lang.Class.getConstructor(Class.java:472)
11-08 12:30:26.184: E/AndroidRuntime(4396): at android.view.LayoutInflater.createView(LayoutInflater.java:480)
11-08 12:30:26.184: E/AndroidRuntime(4396): ... 21 more
这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bitdraw="http://schemas.android.com/apk/res/com.dm.test" >
<view
class="com.dm.test.ui.BitCanvasActivity$CanvasView"
android:id="@+id/backgroundz"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.dm.test.widget.ActionButtons
android:id="@+id/btn_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="135dp"
android:layout_gravity="bottom|center_horizontal" />
<com.dm.test.widget.ColorPicker
android:id="@+id/color_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal"
bitdraw:colors="@array/color_picker_colors"
bitdraw:cols="3"
bitdraw:fils="5" />
</merge>
在 .java 文件的第 55 行是这样的:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.bit_canvas ); //line 55
mActionButtons = ( ActionButtons ) findViewById(R.id.btn_actions);
mColorPicker = ( ColorPicker ) findViewById( R.id.color_picker );
这是内部类的一部分:
public class CanvasView extends View {
public CanvasView(Context c) {
super(c);
}
public CanvasView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CanvasView (Context c, AttributeSet atr, int defstyle){
super(c, atr,defstyle);
}
@Override
protected void onDraw(Canvas canvas) { ... }
任何帮助都将不胜感激,因为我已经没有任何思路了:S