本帖最后由 swingboy 于 2011-06-04 21:21:42 编辑

解决方案 »

  1.   

    06-04 12:33:41.003: ERROR/AndroidRuntime(264): Caused by: java.lang.NullPointerException引发错误的主要原因是空指针!debug->Logcat  
      

  2.   

    应该是在选择widget的时候,会跳转到settings的AppWidgetPickActivity ,同时会传递一些参数,你看看是不是参数传少了  
      

  3.   


    我也知道是空指针错误啊,报错是在源码里的,并且你也无法debug到源码
      

  4.   

    好吧这个问题已经解决了,解决办法将原生态的Launcher2里部分源码粘贴过来如下面这样
            /**
             * Handle the action clicked in the "Add to home" dialog.
             */
            public void onClick(DialogInterface dialog, int which) {
                getResources();
                cleanup();            switch (which) {
                    case AddAdapter.ITEM_SHORTCUT: {
                        // Insert extra item to handle picking application
                        pickShortcut();
                        break;
                    }                case AddAdapter.ITEM_APPWIDGET: {
                        int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();                    Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
                        pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                        
                        // add the search widget
                        ArrayList<AppWidgetProviderInfo> customInfo =
                                new ArrayList<AppWidgetProviderInfo>();
                        AppWidgetProviderInfo info = new AppWidgetProviderInfo();
                        info.provider = new ComponentName(getPackageName(), "XXX.YYY");
                        info.label = getString(R.string.application_name);
                        info.icon = R.drawable.ic_home_arrows_1_focus;
                        customInfo.add(info);
                        pickIntent.putParcelableArrayListExtra(
                                AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
                        ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
                        Bundle b = new Bundle();
                        b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET);
                        customExtras.add(b);
                        pickIntent.putParcelableArrayListExtra(
                                AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
                        
                        // start the pick activity
                        startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
                        break;
                    }                case AddAdapter.ITEM_LIVE_FOLDER: {
                        Launcher.this.requestPickLiveFolder(false);
                        break;
                    }
                    case AddAdapter.ITEM_ANYCUT: {
                            Intent anycutIntent=new Intent();
                            anycutIntent.setClass(Launcher.this, CustomShirtcutActivity.class);
                            startActivityForResult(anycutIntent, REQUEST_PICK_ANYCUT);
                        break;
                    }
                    case AddAdapter.ITEM_WALLPAPER: {
                        startWallpaper();
                        break;
                    }
                }
            }
        }