这是我的第一个Android应用程序,而且我遇到了一个我无法解决的错误问题。 我已经做了一些研究,以便查看类似android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff之类的案例,但不幸的是它并没有帮助我。 这是调试器输出:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.miwok, PID: 9310
android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:215)
at android.content.res.Resources.getValue(Resources.java:1316)
at android.support.v7.widget.ResourcesWrapper.getValue(ResourcesWrapper.java:204)
at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:225)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:66)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:71)
at com.example.android.miwok.WordAdapter.getView(WordAdapter.java:44)
at android.widget.AbsListView.obtainView(AbsListView.java:2365)
at android.widget.ListView.makeAndAddView(ListView.java:2052)
at android.widget.ListView.fillDown(ListView.java:786)
at android.widget.ListView.fillFromTop(ListView.java:847)
at android.widget.ListView.layoutChildren(ListView.java:1826)
at android.widget.AbsListView.onLayout(AbsListView.java:2164)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2496)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2212)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Disconnected from the target VM, address: 'localhost:8603', transport: 'socket'
由于 这是我的适配器类:
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItemView = convertView;
if(listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
LinearLayout rootitems = (LinearLayout) listItemView.findViewById(R.id.rootitems) ;
Word currentWord = getItem(position);
TextView defaultTranslation = (TextView) listItemView.findViewById(R.id.item1);
defaultTranslation.setText(currentWord.getMiwokTranslation());
TextView miwokTranslation = (TextView) listItemView.findViewById(R.id.item2);
miwokTranslation.setText(currentWord.getDefaultTransaltion());
ImageView icone = (ImageView) listItemView.findViewById(R.id.icone_miwok);
icone.setImageResource(currentWord.getmImageResourceId());
if (currentWord.hasImage()==true) {icone.setImageResource(currentWord.getmImageResourceId());}
else icone.setVisibility(View.GONE);
int color= ContextCompat.getColor(getContext(),mColorRessourceId);
rootitems.setBackgroundColor(color);
return listItemView;
}
答案 0 :(得分:1)
最后我找到了解决问题的问题: 我只是要删除这一行的第一次出现:
icone.setImageResource(currentWord.getmImageResourceId());
为什么会这样? 好吧,它是一个在4个其他活动中设置的适配器类,其中一个活动有单词(ArrayList的元素)没有图像,mImageRessourceId是-1,这是一个无效的Id资源所以{{1}会导致崩溃。