E / UncaughtException:android.content.res.Resources $ NotFoundException:资源ID#0x7f0800a8

时间:2018-09-11 11:52:41

标签: java android

当我在诺基亚7 plus安卓版本8.1上启动我的应用程序时,该应用程序运行正常,但是当我在另一部手机安卓6.0版上尝试该应用程序时。我收到此错误:

    E/UncaughtException: android.content.res.Resources$NotFoundException: Resource ID #0x7f0800a8
        at android.content.res.Resources.getValue(Resources.java:1544)
        at android.content.res.Resources.getDrawable(Resources.java:918)
        at android.content.res.Resources.getDrawable(Resources.java:879)
        at com.ephoenixdev.svecanitrenutak.lists.CategoryAdapter.getView(CategoryAdapter.java:102)
        at android.widget.AbsListView.obtainView(AbsListView.java:2474)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1301)
        at android.widget.ListView.onMeasure(ListView.java:1203)
        at android.view.View.measure(View.java:19147)
        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
        at android.view.View.measure(View.java:19147)
        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3343)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2481)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1440)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1694)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6708)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894)
        at android.view.Choreographer.doCallbacks(Choreographer.java:696)
        at android.view.Choreographer.doFrame(Choreographer.java:631)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5765)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
09-11 13:26:20.614 24986-24986/com.ephoenixdev.svecanitrenutak E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ephoenixdev.svecanitrenutak, PID: 24986
    android.content.res.Resources$NotFoundException: Resource ID #0x7f0800a8
        at android.content.res.Resources.getValue(Resources.java:1544)
        at android.content.res.Resources.getDrawable(Resources.java:918)
        at android.content.res.Resources.getDrawable(Resources.java:879)
        at com.ephoenixdev.svecanitrenutak.lists.CategoryAdapter.getView(CategoryAdapter.java:102)
        at android.widget.AbsListView.obtainView(AbsListView.java:2474)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1301)
        at android.widget.ListView.onMeasure(ListView.java:1203)
        at android.view.View.measure(View.java:19147)
        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
        at android.view.View.measure(View.java:19147)
        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3343)
        at android.view.View.measure(View.java:19147)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2481)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1440)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1694)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6708)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894)
        at android.view.Choreographer.doCallbacks(Choreographer.java:696)
        at android.view.Choreographer.doFrame(Choreographer.java:631)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5765)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

这就是我的代码的外观(RecycleView适配器):

public class CategoryAdapter extends BaseAdapter {

    private Activity context;

    public CategoryAdapter(Activity context) {
        this.context = context;
    }

    int[] kategorije = {
            R.string.K_1,
            R.string.K_2,
            R.string.K_3,
            R.string.K_4,
            R.string.K_5,
            R.string.K_6,
            R.string.K_7,
            R.string.K_8,
            R.string.K_9,
            R.string.K_10,
            R.string.K_11,
            R.string.K_12,
            R.string.K_13,
            R.string.K_14,
            R.string.K_15,
            R.string.K_16,
            R.string.K_17,
            R.string.K_18,
            R.string.K_19,
            R.string.K_20,
            R.string.K_21,
            R.string.K_22,
            R.string.K_23,
            R.string.K_24
    };

    int[] ikoniceKategorija = {
            R.drawable.ic_muzika,
            R.drawable.ic_restorani,
            R.drawable.ic_dekoracije,
            R.drawable.ic_foto,
            R.drawable.ic_lepota,
            R.drawable.ic_burme,
            R.drawable.ic_torte,
            R.drawable.ic_ketering,
            R.drawable.ic_pica,
            R.drawable.ic_vencanice,
            R.drawable.ic_svecana_odela,
            R.drawable.ic_aksesoar,
            R.drawable.ic_obuca,
            R.drawable.ic_pozivnice,
            R.drawable.ic_satori,
            R.drawable.ic_limuzine,
            R.drawable.ic_prenociste,
            R.drawable.ic_casoviplesa,
            R.drawable.ic_igraonice,
            R.drawable.ic_animacije,
            R.drawable.ic_osoblje,
            R.drawable.ic_pokloncici,
            R.drawable.ic_organizatori,
            R.drawable.ic_ostalo,
    };

    @Override
    public int getCount() {
        return kategorije.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = context.getLayoutInflater();

        convertView = inflater.inflate(R.layout.list_item_categories,null);

        ImageView imageView = convertView.findViewById(R.id.imageViewListItemCategories);
        TextView textView = convertView.findViewById(R.id.textViewListItemCategories);

        imageView.setImageResource(ikoniceKategorija[position]);
        textView.setText(kategorije[position]);
        return convertView;
    }
}

这很奇怪:

enter image description here

有什么想法吗?而且我还尝试了其他一些电话,但在某些工作上却没有。

我将此称为onCreate()方法:

private void createList() {

        // Kreiranje liste
        ListView listView= findViewById(R.id.listViewMain);
        CategoryAdapter categoryAdapter = new CategoryAdapter(CategoriesActivity.this);
        listView.setAdapter(categoryAdapter);
}

1 个答案:

答案 0 :(得分:1)

确保所有图像都在Drawbles文件夹中。然后

setImageDrawable应该像这样

Resources resources = context.getResources();
image.setImageDrawable(resources.getDrawable(ikoniceKategorija[position]));