0

我在以下代码片段中遇到一个错误。我尝试调试它但没有用。

代码片段 -

    public void createNewList(){
            popupCreateList = new PopupWindow(popupCreateListView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            popupCreateList.setBackgroundDrawable(new BitmapDrawable());
            popupCreateList.setOutsideTouchable(true);
            ((LinearLayout)popUpListView.getParent()).removeView(popUpListView);
            Log.i(TAG,"popupCreateList-->>>" + popupCreateList + R.layout.layout_task_manager);
   EXCEPTION--> popupCreateList.showAtLocation(findViewById(R.layout.layout_task_manager), Gravity.CENTER, 0, 0);


            //popupCreateList.showAsDropDown(listsButton, 50, -30);
            }

日志猫 -

12-29 04:20:44.041: E/AndroidRuntime(885): FATAL EXCEPTION: main
12-29 04:20:44.041: E/AndroidRuntime(885): java.lang.NullPointerException
12-29 04:20:44.041: E/AndroidRuntime(885):  at android.widget.PopupWindow.showAtLocation(PopupWindow.java:809)
12-29 04:20:44.041: E/AndroidRuntime(885):  at ray.kaushik.simple.task.manager.TaskManagerActivity.createNewList(TaskManagerActivity.java:338)
12-29 04:20:44.041: E/AndroidRuntime(885):  at ray.kaushik.simple.task.manager.TaskManagerActivity.onMenuItemSelected(TaskManagerActivity.java:323)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:958)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:468)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:126)
12-29 04:20:44.041: E/AndroidRuntime(885):  at android.view.View$PerformClick.run(View.java:16966)
12-29 04:20:44.041: E/AndroidRuntime(885):  at android.os.Handler.handleCallback(Handler.java:615)
12-29 04:20:44.041: E/AndroidRuntime(885):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-29 04:20:44.041: E/AndroidRuntime(885):  at android.os.Looper.loop(Looper.java:137)
12-29 04:20:44.041: E/AndroidRuntime(885):  at android.app.ActivityThread.main(ActivityThread.java:4745)
12-29 04:20:44.041: E/AndroidRuntime(885):  at java.lang.reflect.Method.invokeNative(Native Method)
12-29 04:20:44.041: E/AndroidRuntime(885):  at java.lang.reflect.Method.invoke(Method.java:511)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-29 04:20:44.041: E/AndroidRuntime(885):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-29 04:20:44.041: E/AndroidRuntime(885):  at dalvik.system.NativeStart.main(Native Method)

编辑 - 1

我正在尝试显示弹出窗口的 findViewById(R.layout.layout_task_manager) 获得 NULL 值。

4

2 回答 2

2

您正在使用

findViewById(R.layout.layout_task_manager)

这不是一个 id,而是一个布局。在 xml 中为其分配一个 id(使用 android:id)并在此处使用它。

于 2012-12-29T11:23:24.667 回答
0

R.layout.XYZ 我们在充气中使用。这不是此布局中任何元素的 id。

于 2012-12-29T11:22:41.227 回答