开发者

Crash when starting activity (via tabhost) - exception thrown before first line

I'm trying to create a fairly simple application with a tabbed layout. At the moment, I have three tabs - two are blank textview activities, while the third attempts to do something a little more complex: scrape some data (a JSON array) from a website, and display it as a list.

The app starts fine, and the blank tabs can be used without issue. When switching to the final tab, however, the app crashes and an exception is thrown:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.tabapp/com.tabapp.Tab3}: java.lang.NullPointerException

To try and narrow down what's happening (beyond Java's adorable "raaaargh something doesn't exist!"), I inclu开发者_如何转开发ded Log.d commands all over the place. The very first line in onCreate() in the faulty activity is a Log.d, and that message never appears when the app runs. So, the crash occurs when the activity is called, but the first line isn't being executed, so presumably the problem isn't in the activity itself.

I've checked the manifest, and all of the activities are (to the best of my limited knowledge) defined properly.

I'm very new to Android development and Stack Overflow; apologies if I've missed any important info.


Solved, and it was a case of not seeing trees due to the whacking great forest being in the way. I was creating the activity's TextView outside of a method (rather than just initialising the variable). Moved it into onCreate() and all is well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜