-3

I'm trying to paint a ball on the screen, but it force closes. Something is going wrong.

Ball b = new Ball();

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ingame);
    start();
}

private void start() {
    Ball b = new Ball();
}

public void paint(Graphics g) {
    b.paint(g);
    g.setColor(Color.GREEN);
    g.fillOval(x-radius, y-radius, radius*2, radius*2);
}

Here's my LogCat:

10-15 21:02:45.492: E/dalvikvm(7847): Could not find class 'com.game.src.Ball', referenced from method com.jordan.bungee.bounce.Cracka. 10-15 21:02:45.492: W/dalvikvm(7847): VFY: unable to resolve new-instance 417 (Lcom/game/src/Ball;) in Lcom/jordan/bungee/bounce/Cracka; 10-15 21:02:45.492: D/dalvikvm(7847): VFY: replacing opcode 0x22 at 0x002b 10-15 21:02:45.492: D/dalvikvm(7847): VFY: dead code 0x002d-0032 in Lcom/jordan/bungee/bounce/Cracka;. ()V 10-15 21:02:45.496: E/dalvikvm(7847): Could not find class 'com.game.src.Ball', referenced from method com.jordan.bungee.bounce.Cracka.start 10-15 21:02:45.496: W/dalvikvm(7847): VFY: unable to resolve new-instance 417 (Lcom/game/src/Ball;) in Lcom/jordan/bungee/bounce/Cracka;

10-15 21:02:45.496: D/dalvikvm(7847): VFY: replacing opcode 0x22 at 0x0000

10-15 21:02:45.500: D/dalvikvm(7847): VFY: dead code 0x0002-0005 in Lcom/jordan/bungee/bounce/Cracka;.start ()V

10-15 21:02:45.500: W/dalvikvm(7847): VFY: unable to find class referenced in signature (Ljava/awt/Graphics;)

10-15 21:02:45.503: I/dalvikvm(7847): Could not find method com.game.src.Ball.paint, referenced from method com.jordan.bungee.bounce.Cracka.paint

10-15 21:02:45.503: W/dalvikvm(7847): VFY: unable to resolve virtual method 3021: Lcom/game/src/Ball;.paint (Ljava/awt/Graphics;)V

10-15 21:02:45.503: D/dalvikvm(7847): VFY: replacing opcode 0x6e at 0x0002

10-15 21:02:45.503: D/dalvikvm(7847): VFY: dead code 0x0005-001f in Lcom/jordan/bungee/bounce/Cracka;.paint (Ljava/awt/Graphics;)V

10-15 21:02:45.507: D/AndroidRuntime(7847): Shutting down VM

10-15 21:02:45.507: W/dalvikvm(7847): threadid=1: thread exiting with uncaught exception (group=0x4001e578) 10-15 21:02:45.527: E/AndroidRuntime(7847): FATAL EXCEPTION: main

10-15 21:02:45.527: E/AndroidRuntime(7847): java.lang.NoClassDefFoundError: com.game.src.Ball

10-15 21:02:45.527: E/AndroidRuntime(7847): at com.jordan.bungee.bounce.Cracka.(Cracka.java:22)

10-15 21:02:45.527: E/AndroidRuntime(7847): at java.lang.Class.newInstanceImpl(Native Method)

10-15 21:02:45.527: E/AndroidRuntime(7847): at java.lang.Class.newInstance(Class.java:1409)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.app.ActivityThread.access$1500(ActivityThread.java:117)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.os.Handler.dispatchMessage(Handler.java:99)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.os.Looper.loop(Looper.java:130)

10-15 21:02:45.527: E/AndroidRuntime(7847): at android.app.ActivityThread.main(ActivityThread.java:3687)

10-15 21:02:45.527: E/AndroidRuntime(7847): at java.lang.reflect.Method.invokeNative(Native Method)

10-15 21:02:45.527: E/AndroidRuntime(7847): at java.lang.reflect.Method.invoke(Method.java:507)

10-15 21:02:45.527: E/AndroidRuntime(7847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)

10-15 21:02:45.527: E/AndroidRuntime(7847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)

10-15 21:02:45.527: E/AndroidRuntime(7847): at dalvik.system.NativeStart.main(Native Method)

Jordan
  • 249
  • 3
  • 8
  • 2
    What is the error that's being thrown? Check your LogCat to find the root cause. Post that, and we'll try to help. – Blumer Oct 15 '12 at 21:17
  • 3
    Please post the LogCat errors so we can see what is happening. – Sam Oct 15 '12 at 21:18
  • @Jordan - in Eclipse (I'm guessing you're using it since you had the eclipse tag), one of the windows on the bottom should be called "LogCat". Set the filter to 'Error', then when the app crashes it should print 20-30 lines in red detailing the crash. Highlight those lines and copy them into your post. – Tim Oct 15 '12 at 21:31
  • One thing for sure. The error is not in the code you've shown since the only code of yours which is called is start() and all that does is create a new instance of Ball. So, either you have not shown the relevant code or the error is in the constructor for Ball. – Simon Oct 15 '12 at 21:41
  • @Simon thats all the code I had... I'm putting the LogCat in my original post right now. – Jordan Oct 16 '12 at 01:54
  • That's not all the code you have. Where is the code for the Ball class without which the app would not compile? – Simon Oct 16 '12 at 05:44
  • um... I don't have a ball class. (Just to let you know, I am only 14, trying to get into Android development) What should I put in that class for it to work? – Jordan Oct 16 '12 at 20:13

1 Answers1

0

I'm not sure why you're defining a local variable b in your start() method since you've already defined one as a class member. The one you created in start() will be lost as soon as start() returns.

Also: the member object you create will be instantiated long before onCreate() is called. Is there enough context available when the Activity is created for Ball() to be created successfully? Without seeing the source code to Ball() we can't tell.

Your logcat output indicates that the class for Ball was not found. Did you write it? Did you put it in the right directory where Eclipse could find it?

This question and your follow-ups seem to indicate that you're extremely new to Android programming, and possibly new to Java. If you're new to Java, I would think good and hard about trying to learn Android so soon. Android is not a programming environment for beginners.

That said, I suggest you start out by doing some of the tutorials to familiarize yourself with the system. Then, to write your own application, find a tutorial that most closely resembled what you're trying to do, copy it, and start making modifications. I almost always start new projects by copying old projects. This way, you know that filesystem layout and so forth is probably correct to begin it.

Finally, at the bottom of your Eclipse window, you'll see a tab labeled "Problems". This can be very useful for finding out what's gone wrong. In your case, the explanation to why Ball wasn't found is likely to be there. And of course, check your Console and Logcat tabs as well.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112