我尝试在我的Android工作室中绘制一个绘图应用程序但是当我尝试在我的手机或模拟器上运行它时。该应用程序突然停止。这是我在布局上的content_main活动xml文件的副本。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFCCCCCC"
android:orientation="vertical"
tools:context=".MainActivity">
<com.example.chadymaebarinan.drawingview
android:id="@+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/new_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/start_new"
android:src="@drawable/new_pic" />
<ImageButton
android:id="@+id/draw_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/brush"
android:src="@drawable/brush" />
<ImageButton
android:id="@+id/erase_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/erase"
android:src="@drawable/eraser" />
<ImageButton
android:id="@+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="@string/save"
android:src="@drawable/save" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="@+id/paint_colors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF660000"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:tag="#FF660000"
android:src="@drawable/paint"/>
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FFFF0000"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FFFF0000" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FFFF6600"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FFFF6600" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FFFFCC00"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FFFFCC00" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF009900"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FF009900" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF009999"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FF009999" />
</LinearLayout>
<!-- Bottom Row -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF0000FF"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FF0000FF" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF990099"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FF990099" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FFFF6666"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FFFF6666" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FFFFFFFF"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FFFFFFFF" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF787878"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FF787878" />
<ImageButton
android:layout_width="@dimen/large_brush"
android:layout_height="@dimen/large_brush"
android:layout_margin="2dp"
android:background="#FF000000"
android:contentDescription="@string/paint"
android:onClick="paintClicked"
android:src="@drawable/paint"
android:tag="#FF000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
当我尝试运行模拟器时,这是完整的LogCat结果
03-20 14:16:47.259 2807-2807/? I/art: Not late-enabling -Xcheck:jni (already on)
03-20 14:16:47.259 2807-2807/? I/art: Late-enabling JIT
03-20 14:16:47.283 2807-2807/? I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
03-20 14:16:47.315 2807-2814/? E/art: Failed sending reply to debugger: Broken pipe
03-20 14:16:47.315 2807-2814/? I/art: Debugger is no longer active
03-20 14:16:47.321 2807-2807/? W/System: ClassLoader referenced unknown path: /data/app/com.example.chadymaebarinan.drawingview-2/lib/x86
03-20 14:16:47.355 2807-2807/? D/AndroidRuntime: Shutting down VM
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: FATAL EXCEPTION: main
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: Process: com.example.chadymaebarinan.drawingview, PID: 2807
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chadymaebarinan.drawingview/com.example.chadymaebarina n.drawingview.MainActivity}: android.view.InflateException: Binary XML file line #19: Binary XML file line #10: Error inflating class com.example.chadymaebarinan.drawingview
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #19: Binary XML file line #10: Error inflating class com.example.chadymaebarinan.drawingview
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.example.chadymaebarinan.drawingview.MainActivity.onCreate(MainActivity.java:28)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.example.chadymaebarinan.drawingview
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.example.chadymaebarinan.drawingview.MainActivity.onCreate(MainActivity.java:28)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.chadymaebarinan.drawingview" on path: DexPathList[[zip file "/data/app/com.example.chadymaebarinan.drawingview- 2/base.apk"],nativeLibraryDirectories= [/data/app/com.example.chadymaebarinan.drawingview-2/lib/x86, /vendor/lib, /system/lib]]
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:583)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.example.chadymaebarinan.drawingview.MainActivity.onCreate(MainActivity.java:28)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: Suppressed: java.lang.ClassNotFoundException: com.example.chadymaebarinan.drawingview
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.Class.classForName(Native Method)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: ... 27 more
03-20 14:16:47.355 2807-2807/? E/AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
03-20 14:16:50.535 2807-2807/? I/Process: Sending signal. PID: 2807 SIG: 9
没有想法,如何修复此代码。我认为这与我的布局文件有关。
<com.example.chadymaebarinan.drawingview
android:id="@+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:background="#FFFFFFFF" />
但我不知道:(请告诉我如何解决错误。非常感谢你!
更新:这是我的drawingview类
package com.example.chadymaebarinan.drawingview;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
public class DrawingView extends View {
private Path drawPath;
//drawing and canvas paint
private Paint drawPaint, canvasPaint;
//initial color
private int paintColor = 0xFF660000;
//canvas
private Canvas drawCanvas;
//canvas bitmap
private Bitmap canvasBitmap;
public DrawingView(Context context, AttributeSet attrs){
super(context, attrs);
setupDrawing();
}
private void setupDrawing(){
drawPath = new Path();
drawPaint = new Paint();
drawPaint.setColor(paintColor);
drawPaint.setAntiAlias(true);
drawPaint.setStrokeWidth(20);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeJoin(Paint.Join.ROUND);
drawPaint.setStrokeCap(Paint.Cap.ROUND);
canvasPaint = new Paint(Paint.DITHER_FLAG);
//get drawing area setup for interaction
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
//view given size
super.onSizeChanged(w, h, oldw, oldh);
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);
canvas.drawPath(drawPath, drawPaint);
//draw view
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//detect user touch
float touchX = event.getX();
float touchY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
drawPath.moveTo(touchX, touchY);
break;
case MotionEvent.ACTION_MOVE:
drawPath.lineTo(touchX, touchY);
break;
case MotionEvent.ACTION_UP:
drawCanvas.drawPath(drawPath, drawPaint);
drawPath.reset();
break;
default:
return false;
}
invalidate();
return true;
}
public void setColor(String newColor){
invalidate();
paintColor = Color.parseColor(newColor);
drawPaint.setColor(paintColor);
//set color
}
}
答案 0 :(得分:4)
您缺少XML上的类名
您的包名称是com.example.chadymaebarinan.drawingview
...因此您获得了ClassNotFoundException。
更改XML以使用DrawingView类的全名。
<com.example.chadymaebarinan.drawingview.DrawingView
android:id="@+id/drawing"
android:layout_width="fill_parent"
答案 1 :(得分:2)
尝试实现类的3个构造函数而不是一个。
public DrawingView(Context context) {
super(context);
setupDrawing();
}
public DrawingView(Context context, AttributeSet attrs) {
super(context,attrs);
setupDrawing();
}
public DrawingView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setupDrawing();
}
如果没有帮助,请尝试调试DrawingView
类代码。