0

In my android app, I try to load this xml into a textview background. But it crashes

Does anyone know whats wrong and how to fix it?

Thanks

protected TextView createCountView(Context context, int text, int bg_id) {
    TextView nametv = new TextView(context);
    nametv.setText(String.valueOf(text));
    nametv.setTextAppearance(context, R.style.count);
    nametv.setBackgroundResource(bg_id);
    LinearLayout.LayoutParams textparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    textparams.gravity = Gravity.CENTER;
    textparams.setMargins(20, 0, 0, 0);
    nametv.setLayoutParams(textparams);
    return nametv;
}

protected TextView createUnAppImageCountView(Context context) {
    return createCountView(context, numberOfUnapprovedImages(), R.drawable.imagecount_bg);
}

imagecount_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<solid xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#076300"/> 

</solid>

error

09-01 12:55:24.295: E/AndroidRuntime(9193): FATAL EXCEPTION: main
09-01 12:55:24.295: E/AndroidRuntime(9193): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.arin/android.arin.NavigationScreen}: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/imagecount_bg.xml from drawable resource ID #0x7f020039
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.ActivityThread.access$700(ActivityThread.java:143)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.os.Looper.loop(Looper.java:137)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.ActivityThread.main(ActivityThread.java:4950)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at java.lang.reflect.Method.invokeNative(Native Method)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at java.lang.reflect.Method.invoke(Method.java:511)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at dalvik.system.NativeStart.main(Native Method)
09-01 12:55:24.295: E/AndroidRuntime(9193): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/imagecount_bg.xml from drawable resource ID #0x7f020039
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.content.res.Resources.loadDrawable(Resources.java:1951)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.content.res.Resources.getDrawable(Resources.java:672)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.view.View.setBackgroundResource(View.java:14453)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.Fish.createCountView(Fish.java:204)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.Fish.createUnAppImageCountView(Fish.java:193)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.Category.addCountViews(Category.java:386)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.Fish.createNodeWrapper(Fish.java:161)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.Category.<init>(Category.java:52)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.TreeMaker.getCategory(TreeMaker.java:53)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.TreeMaker.getRoot(TreeMaker.java:43)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at fish.TreeMaker.getCategoryRoot(TreeMaker.java:33)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.arin.NavigationScreen.setUpCarousel(NavigationScreen.java:156)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.arin.NavigationScreen.onCreate(NavigationScreen.java:54)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.Activity.performCreate(Activity.java:5177)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
09-01 12:55:24.295: E/AndroidRuntime(9193):     ... 11 more
09-01 12:55:24.295: E/AndroidRuntime(9193): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: invalid drawable tag solid
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
09-01 12:55:24.295: E/AndroidRuntime(9193):     at android.content.res.Resources.loadDrawable(Resources.java:1948)
09-01 12:55:24.295: E/AndroidRuntime(9193):     ... 26 more
omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

0

Check the answer here

According to the answer in the link, change your imagecount_bg.xml as follows

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#076300"/> 
</shape>

You should enclose your <solid> inside <shape> and not inside another <solid>

Community
  • 1
  • 1
Lal
  • 14,726
  • 4
  • 45
  • 70