Page 2 of 3

Re: Android App Force closed when building an AlertDialog

Posted: Mon Aug 29, 2011 6:29 pm
by m0skit0
irfanhb7 wrote:He is probably missing some block of code and as it is an exception, it must be put between a try and catch statement.
I am happy that Wololo agrees with me and that is what matters to me.
You don't need any try/catch statement dude. You say that just because it's an exception and you want to catch it. Catching it won't solve the problem. In fact it's useless. The question is finding what's causing that NullPointerException, and the stack trace is spit. I work programming with Java, so please don't talk nonsense. And I'm happy you're happy! :D

@failbit: can you put a breakpoint here

Code: Select all

MobileSkatActivity.context = getApplicationContext();
and see what value MobileSkatActivity.context has?

Re: Android App Force closed when building an AlertDialog

Posted: Tue Aug 30, 2011 11:17 am
by irfanhb7
O.k that was something nonsense I still have a point and I can also give a ex.

Re: Android App Force closed when building an AlertDialog

Posted: Tue Aug 30, 2011 1:23 pm
by failbit
I'm new to android programming with eclipse so maybe I made a mistake by debugging but when I watched the getApplicationContext() methode it gives me a NullPointerException. It seems that it doesn't make the app closing but the context variable is null. A little bit confusing :D .

Re: Android App Force closed when building an AlertDialog

Posted: Tue Aug 30, 2011 10:48 pm
by m0skit0
failbit wrote:when I watched the getApplicationContext() methode it gives me a NullPointerException
I don't understand what you mean. You mean getApplicationContext() returns a null pointer or that when you call it it gives a NullPointerException?

Re: Android App Force closed when building an AlertDialog

Posted: Wed Aug 31, 2011 5:06 am
by irfanhb7
You need to be more descriptive .

Re: Android App Force closed when building an AlertDialog

Posted: Wed Aug 31, 2011 12:16 pm
by failbit
What I mean is that MobileSkatActivity.context stays null after calling getApplicationContext(). But I can't watch the variables in my main class directly because when I start debugging I can't do anything(step in, step over or watching variables)until I touch the "game" button. If I do so it only shows me the variables in my Bid class so I have to give a variable in the Bid class the value of MobileSkatActivity.context to see which value it has.

Re: Android App Force closed when building an AlertDialog

Posted: Wed Aug 31, 2011 1:49 pm
by m0skit0
No, MobileSkatActivity.context = getApplicationContext(); should execute before that. You can put a breakpoint on that line if you want the debugger to stop when it reaches that.

Anyway, if MobileSkatActivity.context is null, then getApplicationContext() is not returning what you want.

Re: Android App Force closed when building an AlertDialog

Posted: Wed Aug 31, 2011 2:16 pm
by failbit
Yes I can put a breakpoint but the debugger doesn't stop! I put a breakpoint before the super.onCreate(savedInstanceState); line. So I thought that it should'nt show the main screen because the debugger should stop before the creation. But It shows the screen and doesn't care for my breakpoints! After that I have to touch the button in my menu because without doing this it does'nt show me any objects and I can't step in or over and so on.

Re: Android App Force closed when building an AlertDialog

Posted: Wed Aug 31, 2011 9:51 pm
by m0skit0
I see you have two activities declared. Are you sure MobileSkatActivity is the main activity?

Re: Android App Force closed when building an AlertDialog

Posted: Thu Sep 01, 2011 12:15 pm
by failbit
I see only MobileSkatActivity what is the other one? There is no other source file which could be an activity(if you are looking for a main methode on android it is the onCreate() methode, I think)