我有3个标签,每个标签都有一个列表视图。我已经为上下文菜单注册了这些列表视图。我有三个不同的arraylists,我存储各个列表视图的项目。
现在我想要点击列表视图项目的位置。
我的代码是:
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch(item.getItemId()){
case R.id.mycards_contextmenu_1:
if(mCurrentTab.equals("Tab 1")){
try{
int pos= info.position;
Toast.makeText(getBaseContext(), pos, Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
break;
}
我正在
android.content.res.resources$notfoundexception
我哪里出错了?
编辑:
Stack Trace :
03-14 22:06:12.488: E/AndroidRuntime(3055): FATAL EXCEPTION: main
03-14 22:06:12.488: E/AndroidRuntime(3055): android.content.res.Resources$NotFoundException: String resource ID #0x0
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.content.res.Resources.getText(Resources.java:229)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.widget.Toast.makeText(Toast.java:265)
03-14 22:06:12.488: E/AndroidRuntime(3055): at neeraj.cardXchange.myCardsPackage.myCardsActivity.onContextItemSelected(myCardsActivity.java:211)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.app.Activity.onMenuItemSelected(Activity.java:2552)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:3601)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:167)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.widget.AbsListView$1.run(AbsListView.java:3529)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.os.Handler.handleCallback(Handler.java:615)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.os.Handler.dispatchMessage(Handler.java:92)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.os.Looper.loop(Looper.java:137)
03-14 22:06:12.488: E/AndroidRuntime(3055): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-14 22:06:12.488: E/AndroidRuntime(3055): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 22:06:12.488: E/AndroidRuntime(3055): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-14 22:06:12.488: E/AndroidRuntime(3055): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-14 22:06:12.488: E/AndroidRuntime(3055): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
Toast.makeText(getBaseContext(), pos, Toast.LENGTH_LONG).show();
应该是
Toast.makeText(getBaseContext(), String.valueOf(pos), Toast.LENGTH_LONG).show();
Toast
还有一个makeText()
方法,在String资源ID(int
)中接受,并通过pasing pos
调用该方法,找不到具有该id的String资源,因此
android.content.res.Resources$NotFoundException