gpt4 book ai didi

android - 获取 "android.content.res.resources$notfoundexception"

转载 作者:行者123 更新时间:2023-11-29 21:47:32 24 4
gpt4 key购买 nike

我有 3 个选项卡,每个选项卡都有一个 ListView 。我已经为上下文菜单注册了这些 ListView 。我有三个不同的数组列表,我在其中存储各自 ListView 的项目。

现在我想要被点击的 ListView 项目的位置。

我的代码是:

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)

最佳答案

Toast.makeText(getBaseContext(), pos, Toast.LENGTH_LONG).show();

应该是

Toast.makeText(getBaseContext(), String.valueOf(pos), Toast.LENGTH_LONG).show();

Toast 还有一个 makeText()接受字符串资源 ID(int)的方法,并通过传递 pos 调用该方法,但该方法无法找到具有该 ID 的字符串资源, 因此

android.content.res.Resources$NotFoundException

关于android - 获取 "android.content.res.resources$notfoundexception",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15414544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com