单击列表项时强制关闭。 (机器人)

时间:2013-01-18 07:25:15

标签: android

  

可能重复:
  Android 2.1 NullPointerException with TabWidgets

我开发了一个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

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

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

    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();
}

}

0 个答案:

没有答案