Android.content.res.Resources $ NotFoundException: Resource ID # 0x7f0200d1
I am getting above error on dialog.setContentView(R.layout.alert_ok);
this line even though xml exists in my application "layout" folder "alert_ok". Below is my complete Java code for displaying my custom alert -
public void showAlertOk(Context context, String title, String message,
String OkTitle) {
// custom dialog
final Dialog dialog = new Dialog(context, R.style.MyAlertDlgTheme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.alert_ok);
dialog.setCanceledOnTouchOutside(false);
TextView alertTitle = (TextView) dialog.findViewById(R.id.alertTitle);
alertTitle.setText(title);
TextView tvAlertMsg = (TextView) dialog.findViewById(R.id.tvAlertMsg);
tvAlertMsg.setText(message);
Button btnAlertOK = (Button) dialog.findViewById(R.id.btnAlertOK);
btnAlertOK.setText(OkTitle);
btnAlertOK.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onfieldAlertListener.onOkClicked();
dialog.dismiss();
}
});
dialog.show();
}
Below is my file "alert_ok.xml -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/one_fifty"
android:background="@drawable/rounded_white"
android:padding="5dp" >
<TextView
android:id="@+id/alertTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:gravity="center"
android:padding="5dp"
android:text="@string/safenest"
android:textColor="@color/colorPrimaryDark"
android:textSize="@dimen/twenty"
android:textStyle="bold" />
<TextView
android:id="@+id/tvAlertMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/llAlertBtn"
android:layout_below="@+id/alertTitle"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:text="Message"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal" />
<LinearLayout
android:id="@+id/llAlertBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@color/alert_devider"
android:orientation="horizontal" >
<Button
android:id="@+id/btnAlertOK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/dlg_bg"
android:gravity="center"
android:paddingBottom="7dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="7dp"
android:text="@string/ok"
android:textColor="@color/alert_btn_color"
android:textStyle="bold" />
</LinearLayout>
<View
android:id="@+id/alertDivider_1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@id/llAlertBtn"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@color/alert_devider" />
</RelativeLayout>
Below is how I call showAlertOk () from my "RegisterNSocietyMobNoVerifyActivity"
public class RegisterNSocietyMobNoVerifyActivity extends AppCompatActivity
{
CommonAlertHandler alertHandler;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.register_new_mobno_verify_activity);
alertHandler = new CommonAlertHandler();
alertHandler.setWikiAlertListner(this);
alertHandler.showAlertOk(RegisterNSocietyMobNoVerifyActivity.this, getResources().getString(R.string.safenest), getResources().getString(R.string.failed_msg), getResources().getString(R.string.ok));
}
}
Following is my code "MyAlertDlgTheme" -
<style name="MyAlertDlgTheme" parent="android:Theme.Dialog">
<!-- Fill the screen -->
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<!-- Custom backgrounds, titles or window float -->
<item name="android:windowBackground">@drawable/rounded_white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
</style>
below is my rounded_white code -
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/dlg_bg" />
<stroke
android:width="3dip"
android:color="@color/dlg_bg" />
<corners android:radius="10dip" />
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip" />
</shape>
For more information see my complete error log as shown below -
01-31 16:35:24.242 19275-19275/com.winsnit.societymanagement E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.winsnit.societymanagement, PID: 19275
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.winsnit.societymanagement/com.winsnit.societymanagement.RegisterNSocietyMobNoVerifyActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0200d1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2247)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5111)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0200d1
at android.content.res.Resources.getValue(Resources.java:1133)
at android.content.res.MiuiResources.getValue(MiuiResources.java:135)
at android.content.res.Resources.getDrawable(Resources.java:708)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3042)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3085)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:286)
at android.app.Dialog.setContentView(Dialog.java:477)
at com.winsnit.societymanagement.Common.CommonAlertHandler.showAlertOk(CommonAlertHandler.java:79)
at com.winsnit.societymanagement.RegisterNSocietyMobNoVerifyActivity.onCreate(RegisterNSocietyMobNoVerifyActivity.java:94)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2247)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5111)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
01-31 16:38:55.822 932-3631/? E/GpsXtraDownloader: No XTRA servers were specified in the GPS configuration
[ 01-31 16:38:56.012 26436:26436 W/ ]
[ColorAdjust] gammamode=2, cemode=10
[ 01-31 16:38:56.012 26436:26436 W/ ]
[ColorAdjust] temp_gammavalue=2, temp_cevalue=10
[ 01-31 16:38:56.012 26436:26436 W/ ]
[ColorAdjust] Don't setGamma!
[ 01-31 16:38:56.012 26436:26436 W/ ]
[ColorAdjust] Don't setCe!
[ 01-31 16:38:56.012 26436:26436 W/ ]
[ColorAdjust] Set temp_prefer temp_ce!
01-31 16:40:24.492 932-986/? E/InputDispatcher: channel '424b6a28 com.winsnit.societymanagement/com.winsnit.societymanagement.Token_Activity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-31 16:43:55.862 932-3055/? E/GpsXtraDownloader: No XTRA servers were specified in the GPS configuration
Also let me know if I can provide more information for this same. Thank.
source to share
I got the same problem: check if the drawable XML file version was embedded in the same file version of other files.
Mine was (v.24) and didn't work.
I copied and pasted the drawing file and changed the color in the code, but when I pasted the file into my drawing folder, the file was converted to (v.24).
I deleted the file and created a new blank drawing file and then pasted the XML code into that blank file. (V.24) was not there and my resource was working fine.
Hope this helps.
source to share