I have been programmi开发者_如何学JAVAng for Android with decent success, but one thing I have noticed is that when I get NullPointerExceptions the stack trace is worthless. They are always of this format:
Thread [<1> main] (Suspended (exception NullPointerException))
ViewRoot.draw(boolean) line: 1431
ViewRoot.performTraversals() line: 1163
ViewRoot.handleMessage(Message) line: 1727
ViewRoot(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4627
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: not available [native method]
Usually stack traces tell you right where the code blew up, but I always seem to get the most generic one possible. Am I missing something obvious? Thanks.
If you are using Eclipse, look at LogCat in the DDMS or Debug perspectives. It will show you the stack trace of the exception itself and that of the code that caused it.
NativeStart.main(String[]) line: not available [native method]
I'm not 100% sure here, but maybe you are calling an API that doesn't exist yet?
For example, are you trying to make an Android 2.2 call on a phone/emulator that is running a lower version of Android (2.1, 1.6, 1.5)?
精彩评论