1

I'm a beginner to android, I believe my code is all fine but when loading the application in the emulator the application crash's and needs to be force closed. I get the bellow logcat, Ive searched the error but to be honest I don't understand enough to convert their other solutions to suit mine ( i did try )

Edit :from what I can tell from other threads I may need to add something to the manifest ?

Could someone explain to me what I should be looking for in my code with the bellow logcat or at least point me to somethings I could try ?

if there is anything else i can do to help resolve this problem id be much obliged it seams quite a few of my projects are plagues by this same error.

Thanks for all the help in advance, this is my first post so be nice :)

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);
}
} 

Manifest

<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>

Bumping thread due to being open 1 week.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Baggerz
  • 387
  • 6
  • 11
  • 24

1 Answers1

0

I think this may just be a problem associated with using a GLSurfaceView with the Android emulator. Try it with an actual device and see what happens.