Я делаю игру для Android, в которую я сделал модель в Java (на Eclipse).
Я на самом деле пытаюсь нарисовать сетку, но когда я работаю, у меня есть java.lang.runtimeexception: невозможно начать активность
Я не понимаю, где проблема, она говорит, что проблема - это из SetContentView (r.layout.Activity_main)
Тогда это моя игра, которую я рисую и делаю действия: < /p>
public class GameView extends SurfaceView implements SurfaceHolder.Callback{
Game gam;
Paint paint=new Paint();
int canvasWidth;
int cellSize;
public GameView(Context context, AttributeSet attributeSet){
super(context,attributeSet);
getHolder().addCallback(this);
getGam(context);
}
public GameView(Context context){
super(context);
getHolder().addCallback(this);
this.getGam(context);
}
public final void getGam(Context context){
gam=(Game)(context.getApplicationContext());
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
canvasWidth=width;
cellSize=width/5;
reDraw();
}
public void reDraw(){
Canvas c=getHolder().lockCanvas();
if(c!=null){
this.onDraw(c);
getHolder().unlockCanvasAndPost(c);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int x=(int)event.getX();
int y=(int)event.getY();
int action=event.getAction();
TenGame theGame=gam.getTenGame();
switch(action){
case MotionEvent.ACTION_DOWN:{
theGame.getSelectedGroup();
}
default:
return false;
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void onDraw(Canvas canvas){
paint.reset();
TenGame theGame=gam.getTenGame();
canvas.drawColor(Color.GRAY);
paint.setColor(Color.BLACK);
for(int x=0;x
< /code>
Это мое сообщение об ошибке:
< /p>
E/AndroidRuntime: FATAL EXCEPTION: main
Process: e.khoig.test2, PID: 15920
java.lang.RuntimeException: Unable to start activity ComponentInfo{e.khoig.test2/e.khoig.test2.MainActivity}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class e.khoig.test2.GameView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class e.khoig.test2.GameView
Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class e.khoig.test2.GameView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:461)
at android.app.Activity.setContentView(Activity.java:2737)
at e.khoig.test2.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to e.khoig.test2.Game
at e.khoig.test2.GameView.getGam(GameView.java:34)
at e.khoig.test2.GameView.(GameView.java:24)
Подробнее здесь: https://stackoverflow.com/questions/550 ... t-activity
Android Studio: java.lang.runtimeexception: невозможно начать деятельность ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Android Studio: java.lang.runtimeexception: невозможно начать деятельность
Anonymous » » в форуме JAVA - 0 Ответы
- 0 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Java.lang.RuntimeException: невозможно начать действие ComponentInfo pt2
Anonymous » » в форуме JAVA - 0 Ответы
- 46 Просмотры
-
Последнее сообщение Anonymous
-