1

您好,我在我的应用程序中使用 tabhost,它在 4.0 及更高版本中运行良好,但是当我尝试在 2.3.3 中运行它时,它返回一个空指针异常并强制关闭应用程序

这是我遇到错误的代码:

        TextView t = new TextView(this) ;
            t=  (TextView) getTabWidget().getChildAt(i).findViewById(android.R.id.title);
        t.setTextColor(Color. parseColor("#ffffff"));

        if (i == 0) tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#00aedb"));

        else tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#0d82df"));

这是我的 logcat 输出:

05-16 12:29:27.009: E/AndroidRuntime(534): FATAL EXCEPTION: main 05-16 12:29:27.009: E/AndroidRuntime(534): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.moneyminder/com.example.moneyminder.MainActivity}: java.lang.NullPointerException 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.os.Handler.dispatchMessage(Handler.java:99) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.os.Looper.loop(Looper.java:123) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.ActivityThread.main(ActivityThread.java:3683) 05-16 12:29:27.009: E/AndroidRuntime(534): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 12:29:27.009: E/AndroidRuntime(534): at java.lang.reflect.Method.invoke(Method.java:507) 05-16 12:29:27.009: E/AndroidRuntime(534): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 05-16 12:29:27.009: E/AndroidRuntime(534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 05-16 12:29:27.009: E/AndroidRuntime(534): at dalvik.system.NativeStart.main(Native Method) 05-16 12:29:27.009: E/AndroidRuntime(534): Caused by: java.lang.NullPointerException 05-16 12:29:27.009: E/AndroidRuntime(534): at com.example.moneyminder.MainActivity.onCreate(MainActivity.java:78) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-16 12:29:27.009: E/AndroidRuntime(534): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 05-16 12:29:27.009: E/AndroidRuntime(534): ... 11 more

4

0 回答 0