我有一个FragmentActivity
使用SherlockActionBar
和支持库 v4。
主布局中有一个ListFragment
。点击一个列表项会打开一个新ListFragment
的部分滑入视图。如果您长按这些列表项,则会显示一个包含两个选项的上下文菜单。第一个选项显示一个dialog
带有一个EditText
框和一个Button
' 它在尝试打开时崩溃。
如果我删除该EditText
行和这些Button
行(除非您用 声明它们),会弹出findViewById
一个空的。dialog
但出于某种原因,它不喜欢对话框的内容(按钮/框)。任何人都可以查看 LogCat 并了解原因吗?线就是null
线setText
。如果我将其注释掉,按钮将onClickListner
变为null
.
这是该代码和logcat的代码。
public boolean onContextItemSelected(android.view.MenuItem item) {
if (item.getGroupId() == 2) {
switch (item.getItemId()) {
case 1:
case 1:
if (Rateit.isUserLoggedIn == true) {
final Dialog dialog = new Dialog(getActivity());
dialog.setTitle("Edit Review");
dialog.show();
final EditText etEdit = (EditText) dialog
.findViewById(R.id.etEditReview);
etEdit.setText(reviewWords);
Button bInsert = (Button) dialog.findViewById(R.id.bInsert);
bInsert.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
clickedReview = etEdit.getText().toString();
if (clickedReview.equals("")) {
Toast.makeText(getActivity(),
"Please add something first.",
Toast.LENGTH_SHORT).show();
} else {
newReview = etEdit.getText().toString();
new EditCommentTask().execute();
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(
etEdit.getWindowToken(), 0);
dialog.dismiss();
}
}
});
}
return true;
日志猫:
03-06 10:29:08.527: E/AndroidRuntime(10438): FATAL EXCEPTION: main
03-06 10:29:08.527: E/AndroidRuntime(10438): java.lang.NullPointerException
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.---.---.RateReviewFragment.onContextItemSelected(RateReviewFragment.java:901)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.support.v4.app.FragmentManagerImpl.dispatchContextItemSelected(FragmentManager.java:1933)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:360)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(SherlockFragmentActivity.java:211)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3633)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:167)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.widget.AbsListView$1.run(AbsListView.java:3423)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.os.Handler.handleCallback(Handler.java:725)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.os.Handler.dispatchMessage(Handler.java:92)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.os.Looper.loop(Looper.java:137)
03-06 10:29:08.527: E/AndroidRuntime(10438): at android.app.ActivityThread.main(ActivityThread.java:5226)
03-06 10:29:08.527: E/AndroidRuntime(10438): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 10:29:08.527: E/AndroidRuntime(10438): at java.lang.reflect.Method.invoke(Method.java:511)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-06 10:29:08.527: E/AndroidRuntime(10438): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-06 10:29:08.527: E/AndroidRuntime(10438): at dalvik.system.NativeStart.main(Native Method)