错误消息(android.content.res.Resources $ NotFoundException)

笛里谁知壮士心,沙头空照征人骨。这篇文章主要讲述错误消息:android.content.res.Resources $ NotFoundException相关的知识,希望能为你提供帮助。
我有一个非常讨厌的问题。我看到有些人有同样的问题,但我找不到合适的答案。
我正在android Studio 3.0.1中开发一个非常简单的应用程序,它可以在ListView中显示图像和文本。
我有我想要在res / values / strings中显示的所有字符串,因为它应该是:

< string name="ka"> ka< /string>

我也有我的主要活动和一些其他活动。
【错误消息(android.content.res.Resources $ NotFoundException)】我在AlphabetActivity中出现的问题,我尝试获取字符串的id:
int asd = R.string.ka;

这只是一种简化,但这是不起作用的。我无法以某种方式达到身份证,或者出现了问题,但我不知道该怎么做以及如何欺骗它。
我收到以下错误消息:
android.content.res.Resources$NotFoundException: Drawable japanese.japanese:string/ka with resource ID #0x7f0b004a Caused by: android.content.res.Resources$NotFoundException: File ka from drawable resource ID #0x7f0b004a

这个列表一直在继续“as android.something ......”
如果有人知道导致这个问题的原因,我会很感激,这很烦人。
我还检查了R文件,一切似乎都存在,所以我只是不明白为什么它找不到ID-s。
谢谢你的回答!
public class AlphabetActivity extends AppCompatActivity {@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.alphabet_list); final ArrayList< AlphabetContainer> sets = new ArrayList< AlphabetContainer> (); sets.add(new AlphabetContainer(R.string.a, R.string.i, R.string.u, R.string.e, R.string.o, R.drawable.a, R.drawable.i, R.drawable.u, R.drawable.e, R.drawable.o)); AlphabetContainerAdapter adapter = new AlphabetContainerAdapter(this, sets); ListView listView = (ListView) findViewById(R.id.alphabetList); listView.setAdapter(adapter); }

}
public class AlphabetContainerAdapter extends ArrayAdapter< AlphabetContainer> {public AlphabetContainerAdapter(Context context, ArrayList< AlphabetContainer> alphabet){ super(context, 0, alphabet); }@Override public View getView(int position, View convertView, ViewGroup parent){ View listItemView = convertView; if(listItemView == null){ listItemView = LayoutInflater.from(getContext()).inflate(R.layout.alphabet_list_item, parent, false); }AlphabetContainer currentAlphabetContainer = getItem(position); TextView alphabetTextView = (TextView) listItemView.findViewById(R.id.text1); alphabetTextView.setText(String.valueOf(currentAlphabetContainer.getAlphabetId1())); ImageView alphabetImageView = (ImageView) listItemView.findViewById((R.id.image1)); if(currentAlphabetContainer.hasImage1()){ alphabetImageView.setImageResource(currentAlphabetContainer.***getAlphabetId1***()); alphabetImageView.setVisibility(View.VISIBLE); } else{ alphabetImageView.setVisibility(View.GONE); }return listItemView; }

}
public class AlphabetContainer { //string source ID for the letter private int mAlphabetId1; private int mAlphabetId2; private int mAlphabetId3; private int mAlphabetId4; private int mAlphabetId5; //image source ID for the letter private int mImageId1 = NO_IMAGE_PROVIDED; private int mImageId2 = NO_IMAGE_PROVIDED; private int mImageId3 = NO_IMAGE_PROVIDED; private int mImageId4 = NO_IMAGE_PROVIDED; private int mImageId5 = NO_IMAGE_PROVIDED; private static final int NO_IMAGE_PROVIDED = -1; //constructor public AlphabetContainer(int alphabetId1, int alphabetId2, int alphabetId3, int alphabetId4, int alphabetId5, int imageId1, int imageId2, int imageId3, int imageId4, int imageId5){ mAlphabetId1 = alphabetId1; mAlphabetId2 = alphabetId2; mAlphabetId3 = alphabetId3; mAlphabetId4 = alphabetId4; mAlphabetId5 = alphabetId5; mImageId1 = imageId1; mImageId2 = imageId2; mImageId3 = imageId3; mImageId4 = imageId4; mImageId5 = imageId5; }public int getAlphabetId1(){return mAlphabetId1; } public int getAlphabetId2(){return mAlphabetId2; } public int getAlphabetId3(){return mAlphabetId3; } public int getAlphabetId4(){return mAlphabetId4; } public int getAlphabetId5(){return mAlphabetId5; }public int getImageId1(){return mImageId1; } public int getImageId2(){return mImageId2; } public int getImageId3(){return mImageId3; } public int getImageId4(){return mImageId4; } public int getImageId5(){return mImageId5; }public boolean hasImage1(){return mImageId1 != NO_IMAGE_PROVIDED; } public boolean hasImage2(){return mImageId2 != NO_IMAGE_PROVIDED; } public boolean hasImage3(){return mImageId3 != NO_IMAGE_PROVIDED; } public boolean hasImage4(){return mImageId4 != NO_IMAGE_PROVIDED; } public boolean hasImage5(){return mImageId5 != NO_IMAGE_PROVIDED; }

}
public class MainActivity extends AppCompatActivity {@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ////test int asd = R.string.bo; ////testTextView alphabetTextView = (TextView) findViewById(R.id.alphabetView); alphabetTextView.setOnClickListener(new View.OnClickListener() { public void onClick(View v){ setContentView(R.layout.activity_alphabet); } }); TextView alphabetTextView2 = (TextView) findViewById(R.id.alphabetGameView); alphabetTextView2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent alphabetIntent = new Intent(MainActivity.this, AlphabetActivity.class); startActivity((alphabetIntent)); } }); }

}
我在学习过程的开始,所以我的代码可能不那么漂亮,抱歉:)
答案这不是你的名字'R.string.ka'的字符串资源的问题。在你的应用程序的某个地方,你试图使用导致问题的R.drawablw.ka访问。
要么
尝试使缓存无效并重试。

    推荐阅读