弹出窗口中的空指针异常显示在位置

时间:2012-12-29 11:13:01

标签: android popup

我在下面的代码片段中遇到一个错误。我试过调试它但没用。

COde片段 -

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

Logcat -

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)获取空值我正在尝试显示POPUP。

2 个答案:

答案 0 :(得分:2)

您正在使用

findViewById(R.layout.layout_task_manager)

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

答案 1 :(得分:0)

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