[英]CAN not sort out :android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
It's my first android application and I've an issue with an error that i couldn't sort it out.这是我的第一个 android 应用程序,我遇到了一个无法解决的错误问题。 I've done some researches in order to see similar cases such as android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff but unfortuently it doesn't help me .我做了一些研究以查看类似的情况,例如android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff但不幸的是它对我没有帮助。 Here is the debugger output :这是调试器输出:
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'
Thanks Here is my Adapter Class :谢谢这是我的适配器类:
@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;
}
Finally i found the issue to sort out the problem : I've just to delete the first occuration of this line :最后我找到了解决问题的问题:我刚刚删除了这一行的第一次出现:
icone.setImageResource(currentWord.getmImageResourceId());
Why does it works ??为什么有效?? Well , it's an adapter Class that is set in 4 other activities , one of those activities has words (elements of the ArrayList) that have not an image , by the the mImageRessourceId is -1 which is an invalid Id ressource so icone.setImageResource(currentWord.getmImageResourceId())
will cause a crash .好吧,它是一个在其他 4 个活动中设置的适配器类,其中一个活动的单词(ArrayList 的元素)没有图像,因为 mImageRessourceId 为 -1,这是一个无效的 Id icone.setImageResource(currentWord.getmImageResourceId())
所以icone.setImageResource(currentWord.getmImageResourceId())
会导致崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.