Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将阿拉伯语翻译返回到资源id?_Java_Android_Sqlite_Localization_Adapter - Fatal编程技术网

Java 如何将阿拉伯语翻译返回到资源id?

Java 如何将阿拉伯语翻译返回到资源id?,java,android,sqlite,localization,adapter,Java,Android,Sqlite,Localization,Adapter,我正在开发一个包含sqlite数据库的应用程序,该应用程序的概念是输入和保存数据 翻译部分是问题所在,有两种语言阿拉伯语和英语,当用户插入新产品时,他必须从spinner中选择项目类型,当用户更改设备语言时,该项目类型被翻译为阿拉伯语保存的数据项目类型未被翻译。我尝试了两种方法来解决此问题,但无法使用阿拉伯语语言 第一种方法是返回错误的翻译值,返回另一个阿拉伯语单词,而不是预期的单词: public int getStringResourceByName(Context context, St

我正在开发一个包含sqlite数据库的应用程序,该应用程序的概念是输入和保存数据 翻译部分是问题所在,有两种语言阿拉伯语和英语,当用户插入新产品时,他必须从spinner中选择项目类型,当用户更改设备语言时,该项目类型被翻译为阿拉伯语保存的数据项目类型未被翻译。我尝试了两种方法来解决此问题,但无法使用阿拉伯语语言

第一种方法是返回错误的翻译值,返回另一个阿拉伯语单词,而不是预期的单词:

 public int getStringResourceByName(Context context, String name) {
    int id = 0;
    Field[] fields = R.string.class.getFields();
    for (Field field : fields) {

        try { //field.getName();
            id = field.getInt(name);

            return id;
        } catch (Exception ex) {
            break;
        }
    }

    return id;

}
适配器代码

 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. getIds(repo.getItemsType())));
textViewquantity.setTextcontext.getStringR.string.last_添加_Quantity++repo.getQuantity++context.getResources.getStringmdatabase.getStringResourceByName上下文,repo.getItemsType

第二种方法可以很好地处理英语数据,但当我用阿拉伯语插入数据时,应用程序崩溃

第二种方法代码

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;
    }
}
它用阿拉伯语给出了这个结果 android.content.res.Resources$NotFoundException:字符串资源ID 0xffffffff

我在这些方法上哪里出了问题,请帮助我,我已经尝试了所有方法,有什么建议吗

<resources
xmlns:tools="http://schemas.android.com/tools">
<string name="app_name">Repo</string>
<string name="table_name">repository</string>

<string name="db_name">Repository</string>
<string name="newInput">New Input</string>
<string name="newOutput">New Output</string>
<string name="repository">Repository</string>
<string name="aboutRepo">About Repo</string>
<string-array name="prices">
    <item>@string/USD</item>
    <item>@string/EUR</item>
    <item>@string/SYP</item>
    <item>@string/LL</item>
    <item>@string/egp</item>
    <item>@string/QAR</item>
    <item>@string/AED</item>
    <item>@string/SAR</item>
    <item>@string/IQD</item>
    <item>@string/JOD</item>
    <item>@string/YER</item>
    <item>@string/LYD</item>
    <item>@string/SDG</item>
    <item>@string/MAD</item>
    <item>@string/TND</item>
    <item>@string/KWD</item>
    <item>@string/dzd</item>
    <item>@string/MRO</item>
    <item>@string/BHD</item>
    <item>@string/OMR</item>
    <item>@string/SOS</item>
    <item>@string/FDJ</item>
    <item>@string/GBP</item>
    <item>@string/TRY</item>
    <item>@string/RUB</item>
    <item>@string/JPY</item>
    <item>@string/AUD</item>

</string-array>
<string name="USD">USD</string>
<string name="EUR">EUR</string>
<string name="SYP">SYP</string>
<string name="LL">  LBP</string>
<string name="egp">EGP</string>
<string name="QAR">QAR</string>
<string name="AED">AED</string>
<string name="SAR">SAR</string>
<string name="IQD">IQD</string>
<string name="JOD"> JOD</string>
<string name="YER">YER</string>
<string name="LYD">LYD</string>
<string name="SDG">SDG</string>
<string name="MAD"> MAD</string>
<string name="TND"> TND</string>
<string name="KWD">KWD</string>
<string name="dzd">DZD</string>
<string name="MRO">MRO</string>
<string name="BHD"> BHD</string>
<string name="OMR"> OMR</string>
<string name="SOS">SOS</string>
<string name="FDJ">FDJ</string>

<string name="GBP">GBP</string>
<string name="TRY">TRY</string>
<string name="RUB">RUB</string>
<string name="JPY">JPY</string>

<string name="AUD">AUD</string>


<string-array name="items">
    <item>@string/Items</item>
    <item>@string/KG</item>
    <item>@string/Boxes</item>
    <item>@string/Pieces</item>
    <item>@string/Liter</item>
    <item>@string/Meter</item>
    <item>@string/Inches</item>
    <item>@string/Tons</item>
</string-array>
<string name="Items">Items</string>
<string name="KG">KG</string>
<string name="Pieces">Pieces</string>
<string name="Liter">Liter</string>
<string name="Meter">Meter</string>
<string name="Boxes">Boxes</string>
<string name="Inches">Inches</string>
<string name="Tons">Tons</string>

<string name="action_settings">Settings</string>

<string name="about_repoReview">Repo is an inventory application that helps the user with keeping track of their repository.
    It functions as a register to easily keep track of the products present in the repo, as well as their purchasing price,
    wholesale price and quantity. It helps the user calculate the total profit and profit per piece in a seamless way.
    It also shows the number of items remaining in the inventory. What makes Repo stand out is the simplicity in use.
    It saves time and efforts, and ensures precision in calculations.</string>


<string name="view_repository"> View Inventory Checklist </string>
<string name="edit_product_name"> Edit product name</string>
<string name="delete_product">Delete product card</string>
<string name="are_u_sure">Do you want to delete this product card permanently?</string>
<string name="options">Options</string>
<string name="yes">Yes</string>
<string name="No">No</string>
<string name="cancel">Cancel</string>
<string name="product_card_deleted">Product card is deleted </string>
<string name="product_name_hasbeenUpdated">Product name is updated </string>
<string name="product_name_isAlreadyExisted">Product name is already existed</string>
<string name="product_nameisalreadyExistedqst">You already have the same Product name in your list do you want to add another product with the same name?</string>
<string name="name_cannotBeEmpty">Column Name cannot be empty!</string>
<string name="qty_cannotBeEmpty">Column Quantity cannot be empty!</string>

<string name="product_Name">Product Name</string>
<string name="id">ID</string>
<string name="last_added_qty">Last In Quantity </string>
<string name="entry_date">Input Date</string>
<string name="last_out_qty">Last Out Quantity</string>
<string name="total_qty">Total Quantity</string>
<string name="last_updated_date">Last Updated Date</string>
<string name="retail_price">Retail Price</string>
<string name="wholesale_price">Wholesale Price</string>
<string name="retail_profit">Retail Profit</string>
<string name="wholesale_profit">Wholesale Profit</string>
<string name="total_retail_profit">Total Retail Profit</string>
<string name="total_wholesale_profit">Total Wholesale Profit</string>
<string name="purchasing_price">Purchasing Price</string>
<string name="total_purchase_price">Total Purchasing Price</string>
<string name="num_unitsInBox">Number of Units in a Box</string>
<string name="retail_price_perUnit">Retail Price per Unit</string>
<string name="wholesale_price_perUnit">WholeSale Price per Unit</string>
<string name="total_units">Total Units</string>
<string name="date_pattern">yyyy/MM/dd hh:mm:ss a</string>
<string name="In">In</string>
<string name="Out">Out</string>
<string name="isUpdated">Updated as an Output from the List</string>
<string name="addedSuccessfully">Added Successfully</string>
<string name="iUpdatedIn"> Updated</string>



<string name="enter_product_name">Enter product name</string>
<string name="enter_product_qty">Enter quantity</string>
<string name="number_units_inBox">Enter number of Units in a box</string>
<string name="retail_price_perunit">Retail price per unit</string>
<string name="wholesale_price_per_unit">Wholesale price per unit</string>
<string name="retail_price_perProduct">Retail price for product</string>
<string name="wholesale_price_perproduct">Wholesale price for product</string>
<string name="purchasing_priceofProduct">Purchasing price</string>
<string name="date_entry">date</string>
<string name="submit">Confirm</string>
<string name="isnotExisted">is not existed in your Repository</string>
<string name="the_qty_of">This quantity of </string>
<string name="this_product">This product</string>

<string name="out_by_box">Out by Box</string>
<string name="out_by_unit">Out by Unit</string>
<string name="retail_out">Retail out</string>
<string name="wholesale_out">Wholesale out</string>
<string name="date_out">Date</string>
 <string name="clear_all_list">Clear all list</string>
<string name="sortBy">Sort by</string>
<string name="Id">ID</string>
<string name="date">Entry Date</string>
<string name="lastupdaate">Last updated</string>
<string name="name">Name</string>
<string name="exit_repo">Exit Repo</string>
<string name="update">Update</string>
<string name="delete_all">Do you want to clear all of your list?</string>
<string name="your_list_is_cleared">The List has been Deleted</string>

你能提供你的字符串xml吗?@Bracadabra我把英语和阿拉伯语的strings.xml都添加到了post中。你能提供你的适配器代码吗?我不知道你是如何接收资源的name@Bracadabra我添加了适配器代码repo.getItemsType返回什么?您希望如何按名称将此类型映射为字符串资源?
<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">ريبو</string>
<string name="newInput">إدخال جديد</string>
<string name="newOutput">إخراج جديد</string>
<string name="repository">المستودع</string>
<string name="aboutRepo">عن ريبو</string>
<string name="action_settings">الضبط</string>
<string name="view_repository">رؤية المستودع</string>
<string name="edit_product_name">تعديل إسم المنتج</string>
<string name="delete_product">حذف بطاقة المنتج</string>
<string name="are_u_sure">هل تريد حذف بطاقة هذا المنتج نهائيا</string>
<string name="options">خيارات</string>
<string name="yes">أجل</string>
<string name="No">لا</string>
<string name="cancel">إلغاء</string>
<string name="product_card_deleted">تم حذف هذه البطاقة</string>
<string name="product_name_hasbeenUpdated">تم تعديل إسم المنتج</string>
<string name="product_name_isAlreadyExisted">إسم المنتج موجود ضمن قائمة المستودع</string>
<string name="product_nameisalreadyExistedqst">إسم المنتج موجود مسبقا ضمن قائمة المستودع هل ترغب بإضافة منتج آخر بنفس الإسم إلى المستودع</string>
<string name="name_cannotBeEmpty">خانة الإسم لا يمكن أن تكون فارغة</string>
<string name="qty_cannotBeEmpty">"خانة الكمية لا يمكن أن تكون فارغة "</string>
<string name="product_Name">إسم المنتج</string>
<string name="id">رقم التعريف</string>
<string name="last_added_qty">آخر كمية تم إدخالها</string>
<string name="entry_date">تاريخ الإدخال</string>
<string name="last_out_qty">آخر كمية تم إخراجها</string>
<string name="total_qty">الكمية الإجمالية</string>
<string name="last_updated_date">آخر تحديث</string>
<string name="retail_price">سعر التجزئة</string>
<string name="wholesale_price">سعر الجملة</string>
<string name="retail_profit">ربح التجزئة</string>
<string name="wholesale_profit">ربح الجملة</string>
<string name="total_retail_profit">ربح التجزئة الإجمالي</string>
<string name="total_wholesale_profit">ربح الجملة الإجمالي</string>
<string name="purchasing_price">سعر الشراء</string>
<string name="total_purchase_price">سعر الشراء الإجمالي</string>
<string name="num_unitsInBox">"عدد القطع في الصندوق "</string>
<string name="retail_price_perUnit">سعر التجزئة للقطعة</string>
<string name="wholesale_price_perUnit">سعر الجملة للقطعة</string>
<string name="total_units">"العدد الإجمالي للقطع "</string>

<string name="addedSuccessfully">تمت الإضافة بنجاح</string>

<string name="enter_product_name">أدخل إسم المنتج</string>
<string name="enter_product_qty">أدخل الكمية</string>
<string name="number_units_inBox">أدخل عدد القطع في الصندوق</string>
<string name="retail_price_perunit">سعر التجزئة للقطعة</string>
<string name="wholesale_price_per_unit">سعر الجملة للقطعة</string>
<string name="retail_price_perProduct">سعر التجزئة للمنتج</string>
<string name="wholesale_price_perproduct">سعر الجملة للمنتج</string>
<string name="purchasing_priceofProduct">سعر الشراء</string>
<string name="date_entry">التاريخ</string>
<string name="submit">تثبيت</string>
<string name="out_by_box">إخراج بالصندوق</string>
<string name="out_by_unit">"إخراج بالقطعة "</string>
<string name="retail_out">إخراج بالتجزئة</string>
<string name="wholesale_out">إخراج بالجملة</string>
<string name="date_out">التاريخ</string>
<string name="clear_all_list">حذف كل القائمة</string>
<string name="sortBy">تصنيف حسب</string>
<string name="Id">رقم التعريف</string>
<string name="date">تاريخ الإدخال</string>
<string name="lastupdaate">آخر تحديث</string>
<string name="name">الإسم</string>
<string name="exit_repo">"خروج "</string>
<string name="update">تحديث</string>
<string name="isnotExisted">غير موجودة ضمن قائمة المستودع</string>
<string name="the_qty_of">هذه الكمية</string>
<string name="this_product">هذا المنتج</string>

<string name="delete_all">هل ترغب بحذف كل القائمة؟</string>
<string name="your_list_is_cleared">تم حذف القائمة</string>
<string name="SYP">\tل.س</string>
<string name="LL">\tل.ل</string>
<string name="egp">\tج.م</string>
<string name="QAR">\tر.ق</string>
<string name="AED">\tد.إ</string>
<string name="SAR">\tر.س</string>
<string name="IQD">\tد.ع</string>
<string name="JOD">\tد.ا</string>
<string name="YER">\tر.ي</string>
<string name="LYD">\tد.ل</string>
<string name="SDG">ج.س</string>
<string name="MAD">\tد.م</string>
<string name="TND">د.ت</string>
<string name="KWD">د.ك</string>
<string name="dzd">\tد.ج</string>
<string name="MRO">\tأ.م</string>
<string name="BHD">د.ب</string>
<string name="OMR">ر.ع</string>
<string name="SOS">ش.ص</string>
<string name="FDJ">ف.ج</string>

<string name="GBP">جنيه إسترليني £</string>

<string name="TRY">\tليرة تركية ₺</string>
<string name="RUB">روبل روسي \t₽</string>
<string name="JPY">ين ¥</string>
<string name="AUD">دولار أسترالي \t$</string>
<string name="about_repoReview">ريبو هو تطبيق للجرد بحيث يساعد المستخدم على أن يبقى محافظ على تتبع مخزنه و بضاعته، يعمل التطبيق على شكل قائمة لتسهيل تتبع المنتجات المسجلة في تطبيق ريبو وأيضا يسجل سعر الشراء، سعر الجملة، سعر التجزئة و الكمية الإجمالية.  يساعد تطبيق ريبو مستخدميه على حساب ربحه الإجمالي و الربح في الوحدة الواحدة بطريقة سلسة، بالإضافة إلى أنه يظهر عدد العناصر المتبقية في المستودع. سلاسة وبساطة استخدامه هو ما يجعل من تطبيق ريبو مميز فهو يوفر الوقت والجهد و يضمن لك دقة عالية في الحسابات.</string>
<string name="isUpdated">تم الإخراج من القائمة</string>
<string name="iUpdatedIn">تم التحديث</string>
<string name="db_name">Repository_ar</string>

<string name="table_name">repository</string>

<string name="KG">كغ</string>
<string name="Pieces">قطعة</string>
<string name="Liter">لتر</string>
<string name="Meter">متر</string>
<string name="Boxes">صندوق</string>
<string name="Inches">إنش</string>
<string name="Tons">طن</string>
<string name="USD">دولار أمريكي $</string>
<string name="EUR">يورو €</string>
<string name="In">إدخال</string>
<string name="Out">إخراج</string>
<string name="Items">مادة</string>
 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. getIds(repo.getItemsType())));