aspose file tools*
The moose likes Android and the fly likes Newbie learning sprites in android java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Newbie learning sprites in android java" Watch "Newbie learning sprites in android java" New topic
Author

Newbie learning sprites in android java

wayne ferguson
Greenhorn

Joined: Feb 22, 2013
Posts: 4
I am currently learning how to develop apps and games in java for android devices. My problem is I have taken the tutorial of the android developers website on how to draw sprites. I have imported there source into eclipse and just changed the image to mine. all works great. But I have created my own app and moved the code into my version. but for some reason it just crashes. any help appreciated. I have attached the orig code (walking Elaine) to import into eclipse and my code (Ship Shapes)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
The first step always is to check the logcat output; if an app crashes, there will be an exception stack trace in there that should point you in the right direction.

By the way, you didn't attach anything (not that you could - attachments are limited to images.)


Ping & DNS - my free Android networking tools app
wayne ferguson
Greenhorn

Joined: Feb 22, 2013
Posts: 4
Ill post my code and the logcat error when I get back in bout an hour. But I'm very confused as both sets of code are identical so don't get y it crashing lol
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
That's where the stack trace comes in :-)
wayne ferguson
Greenhorn

Joined: Feb 22, 2013
Posts: 4
This is my logcat can you please explain how I find the error from this thanks.

02-22 12:50:16.260: D/dalvikvm(272): newInstance failed: no <init>()
02-22 12:50:16.260: D/AndroidRuntime(272): Shutting down VM
02-22 12:50:16.270: W/dalvikvm(272): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-22 12:50:16.300: E/AndroidRuntime(272): FATAL EXCEPTION: main
02-22 12:50:16.300: E/AndroidRuntime(272): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.appzheaven.shipshapes/com.appzheaven.shipshapes.MainGameActivity}: java.lang.InstantiationException: com.appzheaven.shipshapes.MainGameActivity
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.os.Looper.loop(Looper.java:123)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-22 12:50:16.300: E/AndroidRuntime(272): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 12:50:16.300: E/AndroidRuntime(272): at java.lang.reflect.Method.invoke(Method.java:521)
02-22 12:50:16.300: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-22 12:50:16.300: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-22 12:50:16.300: E/AndroidRuntime(272): at dalvik.system.NativeStart.main(Native Method)
02-22 12:50:16.300: E/AndroidRuntime(272): Caused by: java.lang.InstantiationException: com.appzheaven.shipshapes.MainGameActivity
02-22 12:50:16.300: E/AndroidRuntime(272): at java.lang.Class.newInstanceImpl(Native Method)
02-22 12:50:16.300: E/AndroidRuntime(272): at java.lang.Class.newInstance(Class.java:1429)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-22 12:50:16.300: E/AndroidRuntime(272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)

here is my code

MainGameActivity.java


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
02-22 12:50:16.260: D/dalvikvm(272): newInstance failed: no <init>()

02-22 12:50:16.300: E/AndroidRuntime(272): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.appzheaven.shipshapes/com.appzheaven.shipshapes.MainGameActivity}

This means that the MainGameActivity can't be instantiated because it doesn't have a no-argument constructor. Activities shouldn't have a constructor, so that the compiler will insert the default constructor that is missing here. Any initialization should then be done in the onCreate method.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Newbie learning sprites in android java