Surfaceview - 致命异常:主要

时间:2012-10-22 21:37:24

标签: exception android-emulator surfaceview main

我是android的初学者,我相信我的代码都很好但是当在模拟器中加载应用程序时,应用程序崩溃并且需要强制关闭。我得到了轰鸣声logcat,我搜索了错误,但说实话我不明白,他们的其他解决方案转换为适合我的(我确实尝试过)

编辑:从我从其他线程可以看出,我可能需要在清单中添加一些内容吗?

有人可以在我的代码中用波纹管logcat向我解释我应该寻找什么,或者至少指出我可以尝试的事情吗?

如果还有其他任何我可以做的来帮助解决这个问题,那么我很不得不接受这个问题。我的项目很多都是由同样的错误造成的。

感谢您提前获得的所有帮助,这是我的第一篇文章,所以很高兴:)

LogCat

10-22 20:59:20.258: D/AndroidRuntime(307): Shutting down VM

10-22 20:59:20.258: W/dalvikvm(307): threadid=1: thread exiting with uncaught        
exception (group=0x4001d800)

10-22 20:59:20.348: E/AndroidRuntime(307): FATAL EXCEPTION: main

10-22 20:59:20.348: E/AndroidRuntime(307): java.lang.RuntimeException: Unable to       
instantiate activity 
ComponentInfo{com.example.w1_t2_surfaceview/com.example.w1_t2_surfaceview.MyGame}:    
java.lang.ClassNotFoundException: com.example.w1_t2_surfaceview.MyGame in loader    
dalvik.system.PathClassLoader[/data/app/com.example.w1_t2_surfaceview-2.apk]

10-22 20:59:20.348: E/AndroidRuntime(307):  at   
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.app.ActivityThread.access$2300(ActivityThread.java:125)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.os.Handler.dispatchMessage(Handler.java:99)

10-22 20:59:20.348: E/AndroidRuntime(307):  at android.os.Looper.loop(Looper.java:123)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.app.ActivityThread.main(ActivityThread.java:4627)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
java.lang.reflect.Method.invokeNative(Native Method)

10-22 20:59:20.348: E/AndroidRuntime(307):  at
java.lang.reflect.Method.invoke(Method.java:521)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

10-22 20:59:20.348: E/AndroidRuntime(307):  at dalvik.system.NativeStart.main(Native 
Method)

10-22 20:59:20.348: E/AndroidRuntime(307): Caused by:   
java.lang.ClassNotFoundException: com.example.w1_t2_surfaceview.MyGame in loader 
dalvik.system.PathClassLoader[/data/app/com.example.w1_t2_surfaceview-2.apk]

10-22 20:59:20.348: E/AndroidRuntime(307):  at   
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
java.lang.ClassLoader.loadClass(ClassLoader.java:573)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
java.lang.ClassLoader.loadClass(ClassLoader.java:532)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.app.Instrumentation.newActivity(Instrumentation.java:1021)

10-22 20:59:20.348: E/AndroidRuntime(307):  at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)

10-22 20:59:20.348: E/AndroidRuntime(307):  ... 11 more

MyGame Class     package com.example.game;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class MyGame extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(new GameView(this));
}
}

Gameview Class     package com.example.game;     import com.example.w1_t2_surfaceview.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color; 
import android.view.SurfaceView;


public class GameView extends SurfaceView {
private Bitmap bmp;

public GameView(Context context) {
      super(context);
      bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
}
@Override
protected void onDraw(Canvas canvas) {
    canvas.drawColor(Color.CYAN);
    canvas.drawBitmap(bmp, 10, 10, null);
}
} 

清单
    

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />

<application android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MyGame"
        android:label="@string/title_surfaceview" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

Strings.XML

<resources>
<string name="app_name">W1_T2_SurfaceView</string>
<string name="title_surfaceview">Surface View 2</string>
</resources>

由于开放1周而导致线程崩溃。

1 个答案:

答案 0 :(得分:0)

我认为这可能只是与使用Android模拟器的GLSurfaceView相关的问题。尝试使用实际设备,看看会发生什么。