Null Pointer Exception when inflating from XML (Not using TabActivity)
I'm currently trying to debug my Android App. I've built out the first screen and it's using a Tab Host. I had made a few minor modifications to TabHost to add a few extra methods (full source to follow) to work with some other parts of my App.
However, when I try to run the following I get a null pointer exception on Inflate and it doesn't really tell me anything about why. I downloaded the full Android source for my SDK and added it in eclipse to step through the inflation process and find if I could get any more info about the error that way.
I found exactly what line was causing the error (source included below) but when stepping through the debugger something strange happened. The logic is an if/else case where if == true it should return a New Parser() object, I ran that code and it successfully stepped through the constructor of Parser, yet after returning from that, the next instruction stepped right out of the statement group to the line below returning null.
The constructor appears to have run properly (it's located in XmlBlock.java in case you're wondering) yet it still steps t开发者_如何学Pythono the next line and returns null and I have no idea why this is. I've searched for solutions but so far the only similar problem was encountered by someone using a TabActivity which is not suitable for my Application. I need Tabs and their views to be generated by objects I've defined within my project (similar to IOS style View Controllers) and not separate processes via using Intents to launch new Activities.
Can someone please have a look at my source and tell me what I'm doing wrong here because no one else can seem to tell me what the problem is? Here's another direct link to the source involved: http://pastebin.com/9VRE2UGW
Okay, well it looks like my REAL problem here was that I wasn't looking in the Android DDMS perspective for my Debug info. I'd originally thought the Java Debug perspective would give me all the necessary info. The real cause of this exception was elsewhere in the program. Now that I'm reading the logcat I should be able to solve the rest of this on my own since that was my real problem (inadequate information).
I suspect this line is wrong:
TabBarController UITabBarController =
(TabBarController)interfaceBuilder.inflate(R.layout.tab_bar , null);
Because your R.layout.tab_bar
represents a TabHost
:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/tabhost">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:layout_alignParentBottom="true" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabcontent">
</FrameLayout>
</RelativeLayout>
</TabHost>
精彩评论