Android出错The application has stopped unexpectedly
最近学习安卓开发,照视频教程上写了一个程序,写完了ECLIPSE也没有报错,但是运行时模拟器上却出现Theapplicationhasstoppedunexpectedl...
最近学习安卓开发,照视频教程上写了一个程序,写完了ECLIPSE也没有报错,但是运行时模拟器上却出现The application has
stopped unexpectedly,麻烦大侠帮忙看下:
Activity:
package com.adongmyview.app;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Android_4_1Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_android_4_1);
MyView myview=new MyView(this);
this.setContentView(myview);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.android_4_1, menu);
return true;
}
}
自建类myview:
package com.adongmyview.app;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class MyView extends View{
Paint paint;
public MyView(Context context) {
super(context);
// TODO 自动生成的构造函数存根
paint.setColor(Color.WHITE);
paint.setTextSize(20);
paint.setAntiAlias(true);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawColor(Color.GRAY);
canvas.drawRect(10,10,110,110,paint);
canvas.drawText("此为自定义VIEW", 60, 170, paint);
}
} 展开
stopped unexpectedly,麻烦大侠帮忙看下:
Activity:
package com.adongmyview.app;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Android_4_1Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_android_4_1);
MyView myview=new MyView(this);
this.setContentView(myview);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.android_4_1, menu);
return true;
}
}
自建类myview:
package com.adongmyview.app;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class MyView extends View{
Paint paint;
public MyView(Context context) {
super(context);
// TODO 自动生成的构造函数存根
paint.setColor(Color.WHITE);
paint.setTextSize(20);
paint.setAntiAlias(true);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawColor(Color.GRAY);
canvas.drawRect(10,10,110,110,paint);
canvas.drawText("此为自定义VIEW", 60, 170, paint);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询