0

可能重复:
带有 TabWidgets 的 Android 2.1 NullPointerException

我开发了一个 Android 应用程序,它在列表视图中显示目标列表,然后单击其中一个列表项后,它会打开一个选项卡小部件,其中包含 3 个选项卡(详细信息、地图、照片)应用程序是为 api 7 开发的。并且正在工作在所有具有 api 8 及更高版本的设备上都可以。但是当我在具有 android 2.1.1 的 Micromax a60 上打开相同的应用程序时,它正在强制关闭。

下面是我在强制关闭后得到的日志猫。我试图理解它但失败了。现在,如果这个问题没有解决,我将不得不将 micromax a60 升级到 2.2。

谁能帮我解决这个问题?

    01-18 12:42:36.377: E/AndroidRuntime(2505): Uncaught handler: thread main exiting due to uncaught exception
    01-18 12:42:36.387: E/AndroidRuntime(2505): java.lang.NullPointerException
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.widget.TabWidget.dispatchDraw(TabWidget.java:206)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.View.draw(View.java:6538)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.View.draw(View.java:6538)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1837)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewRoot.draw(ViewRoot.java:1349)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.os.Handler.dispatchMessage(Handler.java:99)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.os.Looper.loop(Looper.java:123)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at android.app.ActivityThread.main(ActivityThread.java:4363)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at java.lang.reflect.Method.invokeNative(Native Method)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at java.lang.reflect.Method.invoke(Method.java:521)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    01-18 12:42:36.387: E/AndroidRuntime(2505):     at dalvik.system.NativeStart.main(Native Method)
    01-18 12:42:36.407: E/dalvikvm(2505): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

另一件事是此列表视图位于选项卡小部件的一个选项卡中。它还打开了一个标签小部件。这会是个问题吗?也许..

单击列表项时调用此方法:

    private void showTargetReport(String result) {
    Intent intent = new Intent(ActivityUnreadReportListForEmployee.this,
            ActivityTargetDetails.class);
    intent.putExtra("TARGET_DETAILS", result);
    if (other_target)
        intent.putExtra("OTHER_TARGET", true);
    else
        intent.putExtra("OTHER_TARGET", false);
    startActivity(intent);
}

而这个方法是在ActivityTargetDetails.class打开的时候调用的

    private void showTabs() {
        try {
    setContentView(R.layout.activity_main);

    myContext = this;
    Resources res = getResources(); // Resource object to get Drawables

    tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Resusable TabSpec for each tab
    Intent intent; // Reusable Intent for each tab

    /**********************************************************************/

    if (other_target) {
        // Create an Intent to launch an Activity for the tab (to be
        // reused)
        // Initialize a TabSpec for each tab and add it to the TabHost
        intent = new Intent().setClass(this,
                ActivityTargetInfoOtherTarget.class);
        intent.putExtra("EMPLOYEE_DETAILS", employeeDetails);
        intent.putExtra("TARGET_DETAILS", targetDetails);
        spec = tabHost
                .newTabSpec("Target Details")
                .setIndicator("Details",
                        res.getDrawable(R.drawable.details))
                .setContent(intent);
        tabHost.addTab(spec);
    } else {
        // Create an Intent to launch an Activity for the tab (to be
        // reused)
        // Initialize a TabSpec for each tab and add it to the TabHost
        intent = new Intent().setClass(this, ActivityTargetInfo.class);
        intent.putExtra("EMPLOYEE_DETAILS", employeeDetails);
        intent.putExtra("TARGET_DETAILS", targetDetails);
        intent.putExtra("LOCATION_DETAILS", locationDetails);
        spec = tabHost
                .newTabSpec("Target Details")
                .setIndicator("Details",
                        res.getDrawable(R.drawable.details))
                .setContent(intent);
        tabHost.addTab(spec);
    }

    /*********************************************************************/

    // Do the same for the Map Tab
    Intent mapIntent = new Intent(this, ActivityMapView.class);

    double targetLatitude = 0.0;
    double targetLongitude = 0.0;
    double distanceDifference = 0.0;
    double timeSpent = 0.0;
    double feedbackLatitude = 0.0;
    double feedbackLongitude = 0.0;

    try {
        if (other_target) {
            targetLatitude = Double
                    .parseDouble(targetObject
                            .getString(API_Handler.OTHER_TARGET_TABLE_LATITUDE));
        } else {
            targetLatitude = Double
                    .parseDouble(locationObject
                            .getString(API_Handler.LOCATION_TABLE_LOCATION_LAT));
        }
    } catch (Exception ex) {
        targetLatitude = 0.0;
    }

    try {
        if (other_target) {
            targetLongitude = Double
                    .parseDouble(targetObject
                            .getString(API_Handler.OTHER_TARGET_TABLE_LONGITUDE));
        } else {
            targetLongitude = Double
                    .parseDouble(locationObject
                            .getString(API_Handler.LOCATION_TABLE_LOCATION_LONG));
        }

    } catch (Exception ex) {
        targetLongitude = 0.0;
    }

    try {
        distanceDifference = Double
                .parseDouble(targetObject
                        .getString(API_Handler.TARGET_TABLE_TARGET_DISTANCE_DIFFERENCE));
    } catch (Exception ex) {
        distanceDifference = 0.0;
    }

    try {
        timeSpent = Double.parseDouble(targetObject
                .getString(API_Handler.TARGET_TABLE_TARGET_TIME_SPENT));
    } catch (Exception ex) {
        timeSpent = 0.0;
    }

    try {
        if (other_target) {
            feedbackLatitude = targetLatitude;
        } else {
            feedbackLatitude = Double.parseDouble(targetObject
                    .getString(API_Handler.TARGET_TABLE_TARGET_LAT));
        }
    } catch (Exception ex) {
        feedbackLatitude = 0.0;
    }

    try {
        if (other_target) {
            feedbackLongitude = targetLongitude;
        } else {
            feedbackLongitude = Double.parseDouble(targetObject
                    .getString(API_Handler.TARGET_TABLE_TARGET_LONG));
        }

    } catch (Exception ex) {
        feedbackLongitude = 0.0;
    }

    mapIntent.putExtra(API_Handler.PARAMETER_TARGET_LATITUDE,
            targetLatitude);
    mapIntent.putExtra(API_Handler.PARAMETER_TARGET_LONGITUDE,
            targetLongitude);
    mapIntent.putExtra(API_Handler.PARAMETER_DISTANCE_DIFFERENCE,
            distanceDifference);
    mapIntent.putExtra(API_Handler.PARAMETER_TIME_SPENT, timeSpent);
    mapIntent.putExtra(API_Handler.PARAMETER_FEEDBACK_LATITUDE,
            feedbackLatitude);
    mapIntent.putExtra(API_Handler.PARAMETER_FEEDBACK_LONGITUDE,
            feedbackLongitude);

    spec = tabHost.newTabSpec("Map")
            .setIndicator("Map", res.getDrawable(R.drawable.map))
            .setContent(mapIntent);
    tabHost.addTab(spec);

    /**************************************************************************/

    // Do the same for the photo tab
    intent = new Intent().setClass(this, ActivityPhoto.class);
    intent.putExtra(API_Handler.PARAMETER_TARGET_IMAGE_PATH, imagePath);
    spec = tabHost.newTabSpec("Photo")
            .setIndicator("Photo", res.getDrawable(R.drawable.photo))
            .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

} catch (Exception ex) {
    Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}

}

4

0 回答 0