以下是运行Android 4.2.2的Android设备名称i2上收到的堆栈跟踪。 如下所示,我认为发生这种情况的根本原因是导致空指针异常,其下面是所有的android api调用。我该如何测试并调试它?帮助!
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.insight/com.example.android.appit.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.TabHost
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.TabHost
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.UILibrary.CustomUI.Activities.BaseFragmentActivity.setContentView(BaseFragmentActivity.java:90)
at com.UILibrary.CustomUI.TabPager.FragmentTabsPager.onCreate(FragmentTabsPager.java:59)
at com.example.android.appit.MainActivity.onCreate(MainActivity.java:370)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 23 more
Caused by: java.lang.NullPointerException
at android.view.ViewConfiguration.<init>(ViewConfiguration.java:285)
at android.view.ViewConfiguration.get(ViewConfiguration.java:323)
at android.view.View.<init>(View.java:3241)
at android.view.View.<init>(View.java:3286)
at android.view.ViewGroup.<init>(ViewGroup.java:436)
at android.widget.FrameLayout.<init>(FrameLayout.java:101)
at android.widget.FrameLayout.<init>(FrameLayout.java:97)
at android.widget.TabHost.<init>(TabHost.java:80)
... 26 more
public class MainActivity extends FragmentTabsPager {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//
}
}
public class FragmentTabsPager extends BaseFragmentActivity {
protected TabHost mTabHost;
ViewPager mViewPager;
TabsAdapter mTabsAdapter;
TabWidget mTabsBar;
boolean mTabBarHidden = false;
int mTabBarHeight = 0;
TextView layout_Title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_tabs_pager);
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
mTabHost.setup();
mTabsBar = (TabWidget)findViewById(android.R.id.tabs);
mViewPager = (ViewPager)findViewById(R.id.pager);
//
}
public class BaseFragmentActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT >= 11){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Log.d("HardwareAcceleration","Hardware acceleration enabled");
}
contentId = LAYOUT_ID;
}
@Override
public void setContentView(int layoutResID) {
LayoutInflater inflater = this.getLayoutInflater();
View v = inflater.inflate(layoutResID, null);
SetBaseView(v);
}
}
R.layout.fragment_tabs_pager
-------------------------------
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000" >
<LinearLayout
android:id="@+id/tabContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rlTabs"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/TabbackGround"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@android:id/tabs"
android:layout_alignLeft="@android:id/tabs"
android:layout_alignRight="@android:id/tabs"
android:layout_alignTop="@android:id/tabs"
android:background="#00000000" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dip"
android:orientation="horizontal"
android:padding="0dip" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@android:id/tabs" />
</RelativeLayout>
</LinearLayout>
</TabHost>