问题
This is my xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/filebinder" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="14"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="30 July"
android:textColor="#03a9f4"
android:textSize="32sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
and i am getting this in my android monitor
07-01 18:32:04.693 10005-10005/com.mindefy.kidster E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
07-01 18:32:12.293 10005-10005/com.mindefy.kidster E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mindefy.kidster/com.mindefy.kidster.DiaryEntry.diaryEntryTeacherActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
I am a beginner in android and i had read answers of various related questions but still i am not getting it where i am wrong.
Edit 1 - Removed unusual code.
回答1:
I think the Problem is in your Drawable
Image. The error InflateException is common issue is an out of memory exception when trying to inflate an imageview loading a drawable resource. If one of this resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.
So basically verify that the pixel resolution in your drawables images are just the minimum necessary for your layout.
回答2:
I had this error message, When I was using a library called com.mikhaellopez:circularimageview
and i had the image scale type set to Center_Inside
which was not supported by the library. After removing that line in the xml layout it worked fine.
回答3:
@drawable/filebinder
or @drawable/diarybookmark
not a valid drawable.
Official doc: https://developer.android.com/guide/topics/resources/drawable-resource.html
Drawable could be png, jpg, gif files or drawable defined by a XML file as state drawable, shape drawable, ...
回答4:
In my case the reason of this error was that I added the dimen
resource to values-land/dimens.xml
, but not in values/dimens.xml
. Then IDE didn't show any warning/error but at runtime obviously the layout couldn't be drawn.
In general the best way is commenting/deletion views in the layout file one by one to realise which view causes an error.
来源:https://stackoverflow.com/questions/38146238/android-view-inflateexception-binary-xml-file-line-error-inflating-class