Advertising (This ad goes away for registered users. You can Login or Register)

Android App Force closed when building an AlertDialog

Programming for your favorite smartphone or tablet? Post here
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Android App Force closed when building an AlertDialog

Post 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?
Advertising
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
irfanhb7
Posts: 466
Joined: Wed Jan 26, 2011 2:46 pm
Location: In your nightmares

Re: Android App Force closed when building an AlertDialog

Post by irfanhb7 »

O.k that was something nonsense I still have a point and I can also give a ex.
Advertising
Languages I know : C , C++ & Java
Image
Boy : There is something wrong with my phone.
Girl : What ?
Boy: It don't have your Phone Number.
Image
failbit
Posts: 48
Joined: Fri Apr 08, 2011 1:43 pm

Re: Android App Force closed when building an AlertDialog

Post 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 .
MIPS: Misleading Information to Promote Sales
Play Skat on your PSP:
viewtopic.php?f=26&t=5085
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Android App Force closed when building an AlertDialog

Post 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?
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
irfanhb7
Posts: 466
Joined: Wed Jan 26, 2011 2:46 pm
Location: In your nightmares

Re: Android App Force closed when building an AlertDialog

Post by irfanhb7 »

You need to be more descriptive .
Languages I know : C , C++ & Java
Image
Boy : There is something wrong with my phone.
Girl : What ?
Boy: It don't have your Phone Number.
Image
failbit
Posts: 48
Joined: Fri Apr 08, 2011 1:43 pm

Re: Android App Force closed when building an AlertDialog

Post 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.
MIPS: Misleading Information to Promote Sales
Play Skat on your PSP:
viewtopic.php?f=26&t=5085
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Android App Force closed when building an AlertDialog

Post 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.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
failbit
Posts: 48
Joined: Fri Apr 08, 2011 1:43 pm

Re: Android App Force closed when building an AlertDialog

Post 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.
MIPS: Misleading Information to Promote Sales
Play Skat on your PSP:
viewtopic.php?f=26&t=5085
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Android App Force closed when building an AlertDialog

Post by m0skit0 »

I see you have two activities declared. Are you sure MobileSkatActivity is the main activity?
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
failbit
Posts: 48
Joined: Fri Apr 08, 2011 1:43 pm

Re: Android App Force closed when building an AlertDialog

Post 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)
MIPS: Misleading Information to Promote Sales
Play Skat on your PSP:
viewtopic.php?f=26&t=5085
Locked

Return to “Programming”