Graphics

Put your problem here if it does not fit any of the other categories.

Graphics

Postby MakyOnCover » Sun Jan 22, 2012 7:49 pm

Why can I only do two methods onDraw() on my project.
I created the main onDraw(Canvas canvas) method, then I created other class with the method onDraw(Canvas canvas) and after that I tried to create other method onDraw(Canvas canvas) and the emulator gives me always a error!
Why does it happen?
MakyOnCover
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 31, 2011 7:49 pm

Top

Re: Graphics

Postby Phyll » Mon Jan 23, 2012 12:24 am

Hi MakyOnCover,

I was wondering how you were making out with your bullets. I found another project that more or less shows what I was talking about. Not exactly the same thing but it uses the principles. It's not too bad. Its a rehash of an example I had found on the internet and was made to handle multiple objects in an array like I suggested. This one draws the objects but it could use bitmaps too.

As for your error, do you have a logcat error message? Or some of the code? It seems like any view can only have one onDraw method and that's how the drawing gets done. It would seem to me that any other onDraws would only take care of the view they were part of.

Hope this helps.

Phyll
Attachments
BouncingBall.zip
Bouncing Ball Example
(54.43 KiB) Downloaded 16 times
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Graphics

Postby MakyOnCover » Mon Jan 23, 2012 2:35 pm

It's a logcat erro and it says like:
"the application "app's name" (process com...)has stopped unexpectedly. Please try again. Force close"
cause I'm doing like:
(on the main onDraw(Canvas canvas))
While(...){
object1.onDraw(canvas);
object2.onDraw(canvas);
}

but if I delete the object2.onDraw(canvas), the app works, or if I pass all the code inside the onDraw(canvas) method from the class of that object2 and put inside the main onDraw(canvas) it also works.

(sorry the english)

This may be stupid but, how can I see this project (the coding)?
MakyOnCover
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 31, 2011 7:49 pm

Re: Graphics

Postby Phyll » Mon Jan 23, 2012 3:48 pm

Hi MakyOnCover,

Yes, I think you really need to see the code in the bouncing ball example. It needs to be unzipped. In Windows right click on its name in Windows Explorer and choose Extract All to make a folder with everything unzipped.

Then, in Eclipse use File/Import from the menu to create a new project from the Existing code. Then you should be able to view the code and run the app to see how it keeps three balls moving at the same time. There's also a clever way to do the slope that avoids calculating the line.

As far as your error goes, you need to look further down in the logcat to see what caused it. From your description it sounds like something in Object2 causes it. It seems like an error in the code, maybe a calculation or nullpointer.

The logcat will usually show (going up from the end) the cleanup after the error, the code that executed before the error, the code that caused the error (usually with a line number in the code), the exception name etc. about the error and a few lines of cleanup from servicing the error. Most errors that cause the app to stop, show this stack dump so you get an idea what happend before, during and after the error.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Graphics

Postby MakyOnCover » Mon Jan 23, 2012 6:12 pm

It gives me a logcat problem when I create the object2.oDraw(Canvas canvas); how can I solve it, if it has a solution.
I saw the example and I tried to do that with the ondraw method but I can't cause of that logcat problem.
MakyOnCover
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 31, 2011 7:49 pm

Re: Graphics

Postby BUKsAPPs » Mon Jan 23, 2012 9:00 pm

Did you remember to initialize object2?

Have you done an object2 = new Object();
and everything else you did to object1 up to that point?

BUKsAPPs
http://buksweb.com/
BUKsAPPs
Claustrum Lite - Area capture game
R:P:S Academy - play Rock/Paper/Scissors online
BUKsAPPs
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Sat Jan 16, 2010 9:01 pm
Location: USA

Top

Re: Graphics

Postby Phyll » Mon Jan 23, 2012 9:13 pm

Hi MakyOnCover,

Why don't you show us the code here so we can properly analyze it. It seems to me that there is a variable that is initialized if it is in the overriden ondraw, but is not initialized in the object2.ondraw. Maby some kind of global variable that is local in object2.ondraw. Without the logcat for the error, I'm just shooting in the dark.

If you can do it, you could zip it up and send it in a PM (the whole project so far) and I'll see what that error looks like and probably get it fixed.

Help us help you.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Graphics

Postby MakyOnCover » Mon Jan 23, 2012 9:36 pm

hey, I already solved!! It was a beginner error: I forgot to make the object2!! xD
Sorry for losing your time!!
Thank you guys you were really helpfull!!
I'm really grateful!!
MakyOnCover
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Dec 31, 2011 7:49 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 31 guests