简体   繁体   English

如何消除这个错误 (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff)

[英]how to remove this error (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff)

I'm building an Android app that contain SQLite DB and I was having a problem with translating SQLite saved data then I find a solution which is a method to get resource id of strings, and it worked just fine, the app was working fine then suddenly this error showed I don't know why, please help我正在构建一个包含 SQLite DB 的 Android 应用程序,我在翻译 SQLite 保存的数据时遇到了问题,然后我找到了一个解决方案,它是一种获取字符串资源 ID 的方法,并且运行良好,然后该应用程序运行良好突然这个错误显示我不知道为什么,请帮忙

The method, I used to get resource for string:我用来获取字符串资源的方法:

     public static int getResId(String resName, Class<?> c) {

        try {
            Field idField = c.getDeclaredField(resName);
            return idField.getInt(idField);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

The code in the adapter适配器中的代码


    textViewname.setText(context.getString(R.string.product_Name)+" " + repo.getName());
    textViewquantity.setText(context.getString(R.string.last_added_qty)+" " + repo.getQuantity() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
    textViewdate.setText(context.getString(R.string.entry_date)+" " + repo.getDate()+ " /"+context.getResources().getString(mdatabase.getResId(repo.getInOrOut(),R.string.class)));
    textViewTotal.setText(context.getString(R.string.total_qty)+" " + repo.getTotal() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
    textviewlastUpdated.setText(context.getString(R.string.last_updated_date)+" " + repo.getUpdateDate() +" /"+context.getResources().getString(mdatabase.getResId(repo.getInOrOut(),R.string.class)));
    textViewid.setText(context.getString(R.string.id)+" " + repo.getId());
    textViewOutputqty.setText(context.getString(R.string.last_out_qty)+" " + repo.getOutputqty() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
    textViewpriceofsingleitem.setText(context.getString(R.string.retail_price)+" " + repo.getPrice() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewpriceofMultipleitem.setText(context.getString(R.string.wholesale_price)+" " + repo.getPriceofmultipleInput() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewProfitSIngle.setText(context.getString(R.string.retail_profit)+" " + repo.getProfitSingle() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewProfitMultiple.setText(context.getString(R.string.wholesale_profit)+" " + repo.getProfitMultiple() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewPurchasingPrice.setText(context.getString(R.string.purchasing_price)+" " + repo.getPurchasingPricePeranItem() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewTotalPurchasingPrice.setText(context.getString(R.string.total_purchase_price)+" " + repo.getTotalPurchasingPrice() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewTotalProfitSingle.setText(context.getString(R.string.total_retail_profit)+" " + repo.getTotalProfitperSingle() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewTotalProfitMultiple.setText(context.getString(R.string.total_wholesale_profit)+" "+ repo.getTotalProfitPerMultiple() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewitemsIBox.setText(context.getString(R.string.num_unitsInBox)+" "+ repo.getItemsInBox());
    textViewSinglePriceOfiteminBox.setText(context.getString(R.string.retail_price_perUnit)+ " " + repo.getSinglePriceofItemInBox()+" " +context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewMultipriceOfItemInBox.setText(context.getString(R.string.wholesale_price_perUnit)+" "+repo.getMultiplePriceofitemInBox()+" "+context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
    textViewtotalItemsInBoexs.setText(context.getString(R.string.total_units)+" "+ repo.getTotalitemsInboxes() +" "+ context.getResources().getString(R.string.Pieces));

This error happens because you are trying to get resource that does not exist.发生此错误是因为您试图获取不存在的资源。 It is because you store memory address which allocate to your string resource and possible it will change next time.这是因为您存储了分配给字符串资源的内存地址,并且下次可能会更改。 I do not know what is your scenario but why you store it already in your strings it will never lost.我不知道你的场景是什么,但为什么你已经将它存储在你的字符串中,它永远不会丢失。 I can help you to build another logic only when you tell what are you trying to achieve.只有当您说出您要实现的目标时,我才能帮助您构建另一个逻辑。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.content.res.Resources$NotFoundException · 字符串资源 ID # - android.content.res.Resources$NotFoundException · String resource ID # 错误:android.content.res.Resources$NotFoundException:字符串资源 ID #0x1 - Error: android.content.res.Resources$NotFoundException: String resource ID #0x1 android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 android.content.res.Resources $ NotFoundException:无法找到资源ID - android.content.res.Resources$NotFoundException: Unable to find resource ID 缺少资源 ID android.content.res.Resources$NotFoundException:字符串资源 ID #0xb - missing resource id android.content.res.Resources$NotFoundException: String resource ID #0xb android.content.res.Resources $ NotFoundException:资源ID#0x0 Android错误 - android.content.res.Resources$NotFoundException: Resource ID #0x0 Android error GridView.FATAL例外:main android.content.res.Resources $ NotFoundException:字符串资源ID#0x0 - GridView.FATAL EXCEPTION: main android.content.res.Resources$NotFoundException: String resource ID #0x0 无法访问变量-android.content.res.Resources $ NotFoundException:字符串资源ID - Can't get access to variables - android.content.res.Resources$NotFoundException: String resource ID android.content.res.Resources $ NotFoundException:字符串资源ID#0x2 - android.content.res.Resources$NotFoundException: String resource ID #0x2 android.content.res.Resources$NotFoundException: 字符串资源 ID #0x0 - android.content.res.Resources$NotFoundException: String resource ID #0x0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM