Re: [問題] 請問如何在另一個class中使用alertdialog
錯誤訊息:
05-31 12:06:30.895: E/AndroidRuntime(9790): FATAL EXCEPTION: main
05-31 12:06:30.895: E/AndroidRuntime(9790): java.lang.NullPointerException
05-31 12:06:30.895: E/AndroidRuntime(9790): at
android.content.ContextWrapper.getResources(ContextWrapper.java:80)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.example.izombie.ItemEvent.showItemCategory(ItemEvent.java:14)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.example.izombie.RoamingMap.onMenuItemSelected(RoamingMap.java:38)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:794)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:860)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
android.view.View$PerformClick.run(View.java:9318)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
android.os.Handler.handleCallback(Handler.java:587)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
android.os.Handler.dispatchMessage(Handler.java:92)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
android.os.Looper.loop(Looper.java:130)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
android.app.ActivityThread.main(ActivityThread.java:3691)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
java.lang.reflect.Method.invoke(Method.java:507)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
05-31 12:06:30.895: E/AndroidRuntime(9790): at
dalvik.system.NativeStart.main(Native Method)
ItemEvent就是上篇的C2
RoamingMap就是C1
showItemCategory就是C2.f()
RoamingMap裡的部份程式碼:
ItemEvent item_event = new ItemEvent();
...
...
item_event.showItemCategory(RoamingMap.this);
showItemCategory則是
public void showItemCategory(Context ct) {
String[] stra_item_category =
getResources().getStringArray(R.array.stra_item_category);
AlertDialog.Builder dlg_item_category = new AlertDialog.Builder(ct);
dlg_item_category.setTitle(getString(R.string.str_dlg_item_category_title));
dlg_item_category.setNeutralButton(getString(R.string.str_cancel), null);
dlg_item_category.setItems(stra_item_category,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int index) {
showItemList(index);
}
}
);
dlg_item_category.show();
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.72.155
→
05/31 12:19, , 1F
05/31 12:19, 1F
→
05/31 12:20, , 2F
05/31 12:20, 2F
→
05/31 12:51, , 3F
05/31 12:51, 3F
→
05/31 12:59, , 4F
05/31 12:59, 4F
→
05/31 13:35, , 5F
05/31 13:35, 5F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 3 篇):