<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/general_dts_title"
style="#style/TextAppearance.Compat.Notification.Line2"
android:layout_alignParentBottom="false"
android:layout_alignBottom="#+id/imgToggle"
android:textSize="16sp" />
<Switch
android:id="#+id/imgToggle"
android:layout_width="42dp"
android:layout_height="28dp"
android:layout_gravity="right"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" />
</RelativeLayout>
StatusBar: Caused by: android.view.InflateException: Binary XML file line #338 in com.dts.dtsxultra:layout/view_notification_sample: Class not allowed to be inflated android.widget.Switch ...
Could you please help.
I tried removing background attribute, but still it is not working.
I have tried the above piece of code, without giving the style to the textview, it works great. The error that you are facing may not be because of the piece of code.
RemoveView only allows some layout and widget to inflate. android.widget.Switch as in the error you are getting is not supported by RemoteView. You can see the list of supported views here
Related
I set android:contentDescription in xml file. But it can't be read out in Talkback mode. If I call setContentDecsription in java code, it works. I try to getContentDescription in jave code, it returns null. It seems the android:contentDescription in xml file does not work. I don't know why.
Any suggestion is appreciated.
android:id="#+id/view_delete"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:paddingBottom="32dp"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:paddingTop="8dp"
android:contentDescription="Delete"
android:scaleType="fitCenter"
android:visibility="invisible"
android:src="#drawable/delete"
When working with 4.7 WXGA API 23, I am getting the error of "android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class "
but in higher versions, it is all working well, I have added the code and the xml layout for my issue, don't understand why it is happening so
Code where this error is occurring
#NonNull
#Override
public PostsHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_list_layout,
parent, false);
return new PostsHolder(v);
}
XML Layout for recyclerview Item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/shadow_300_50"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:padding="5dp"
android:orientation="horizontal"
>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/profile"
android:id="#+id/post_user_profile_image"
android:scaleType="centerCrop"
android:layout_marginLeft="4dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:id="#+id/post_item_username"
android:layout_marginLeft="5dp"
android:layout_marginTop="8dp"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Time"
android:id="#+id/post_item_time"
android:layout_marginLeft="257dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:id="#+id/post_item_title"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textAlignment="textStart"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="5dp"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="post_item_Category"
android:textColor="#color/colorPrimaryDark"
android:textSize="13sp"
android:textStyle="bold"
android:id="#+id/post_item_Category"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post_item_SpinnerC"
android:textColor="#color/colorPrimaryDark"
android:textSize="13sp"
android:id="#+id/post_item_SpinnerC"
android:layout_marginLeft="7dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/post_item_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="3dp"
android:padding="3dp"
android:text="Post Description"
android:textColor="#android:color/black"
android:textSize="14dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:padding="2dp">
<Button
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mark"
app:srcCompat="#drawable/ic_heart_normal"
android:background="#drawable/button"/>
<Button
android:id="#+id/commenting_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:text="Comment"
android:background="#drawable/button"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
The problem is that a constructor for a class for creating one of the widgets doesn't exist or can't be found. The LayoutInflater class (in the sdk, ie: Android\Sdk\sources\android-17\android\view\LayoutInflater.java) uses reflection(code introspection) on the widget name to build the widget object. In your case I would guess it is 'de.hdodenhof.circleimageview.CircleImageView', in my case it was 'androidx.appcompat.widget.Toolbar'.
Finding the problem is buried in several layers of exceptions, and only the (pretty useless) 'Binary XML file line #7: Error inflating class...' message appears. I set up Android Studio to break on the android.view.InflateException exception:
The 'ie' InflateException at the bottom contains a java.lang.reflect.InvocationTargetException, which was in turn caused by a android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f03008f a=-1} exception (in my case)
In the LayoutInflator code:
Lin 616 is where they embed the exception named 'e' in the InflationException. Using the 'Evaluate Expression' feature of AS, I called 'e.getStackTrace()' which shows where the error really occurred:
StackTrace line 2 shows that it was line LayoutInflater line 587 (seen with red background in code image above) that threw the exception. Looking up to stackTrace line 0, it is the java.lang.reflect.Constructor.constructNative method that threw the original exception.
LayoutInflator line 587 is was trying to instanciate androidx.appcompat.widget.Toolbar (for me) and was looking for a Toolbar constructor with 2 arguments:
1) Context: ref to activity in which the layout was being inflated
2) AttributeSet: the opaque XmlBlock object named 'attrs'
I found this out by using Expression Evaluator on 'this.mConstructorArgs' (seen in line 584 of the code).
So, for me, it could not find a constructor with the Toolbar(Activity, XmlBlock) signature. So I have to look into where Toolbar is defined in by configuration and find out what constructors it has.
The usual 'solution' people give as in this question, is to clear caches, reset support libraries, run with the latest dependencies etc, which don't get you to the root cause, and sometimes don't work.
I'm documenting this here somewhat for my own future problems -- and also as a plea to the Android developers to give clearer error messages. 'Binary XML file line #7: Error inflating' doesn't help much and line 7 of some Binary XML file doesn't give and clues.
#ramneek, 'de.hdodenhof.circleimageview.CircleImageView' is the only unusual widget you are inflating there must be some method or constructor for that class/widget that the inflator can't find.
I’ve created a widget with the wizard. Then I’ve customized the layout.
I tried to run but all I got is the error view of the widget “Problem loading widget”.
Checking the log I found this error:
W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
It says that the system could not find any view, but my layout is defined in res/layout/ and declared in widget info xml file.
What am I missing? Here is the project on GitHub.
You're not doing much that's wrong. The entire app widget is setup correctly. It is purely a layout issue. It doesn't seem to be happy with the complexity of the playback_widget.xml file. I changed the file to the following:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/playback_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/poster_imageview"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_headset_mic_light_black_140dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textAlignment="center"
android:textColor="#color/primaryTextColor"
android:textSize="16sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/default_text_padding">
<ImageView
android:id="#+id/player_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_toLeftOf="#+id/player_play_pause"
android:src="#drawable/ic_skip_previous_white_32dp" />
<ImageView
android:id="#+id/player_play_pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_play_arrow_white_40dp" />
<ImageView
android:id="#+id/player_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:layout_toRightOf="#id/player_play_pause"
android:src="#drawable/ic_skip_next_white_32dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
The widget views appear fine now. I realise this probably isn't the exact layout that you're after, but you'll just have to play around with it until you find something that it is happy with.
Home screen widgets can be a bit tricky because you have a more limited set of views and less flexibility in terms of the layout.
Also I haven't checked but I'm not sure that the following view is allowed in homescreen widgets:
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="?colorAccent" />
Also if you have trouble getting that error to go away. Destroy the home screen widget and restart the phone. They sometimes get into a dorked up state during development.
But in any event your project is working fine for me after the playback_widget.xml change. Android 8.0.
Can anyone tell me whats wrong with this layout? Because I can't seem to find anything unusual that could cause InflateException. Also I am getting this exception mostly on Samsung Devices, others seem to work more or less fine. Full exception
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{class name}: android.view.InflateException: Binary XML file line #0: Error inflating {class name}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/loginContainer"
style="#style/AuthenticationTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0">
<LinearLayout
android:id="#+id/holder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/window_enter_identifier_greeting_label"
android:textAlignment="center"
android:textSize="26sp" />
<TextView
android:id="#+id/info"
style="#style/AuthenticationTheme"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="#dimen/authentication_margin_from_sides"
android:layout_marginRight="#dimen/authentication_margin_from_sides"
android:gravity="center"
android:text="#string/window_enter_identifier_phone_description_label"
android:textAlignment="center"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/phoneInputHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.custom.authentication.views.IdentifierInputView
android:id="#+id/authenticationInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/authentication_margin_from_sides"
android:layout_marginRight="#dimen/authentication_margin_from_sides" />
</LinearLayout>
</LinearLayout>
<com.custom.authentication.views.BottomButtonsView
android:id="#+id/bottomButtons"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:linkText="#string/window_enter_identifier_login_with_email_button"
app:mainText="#string/Continue" />
</android.support.constraint.ConstraintLayout>
I am inflating this layout in my custom view class like this:
class EnterIdentifierView(context: Context) : ConstraintLayout(context) {
init {
inflate(context, R.layout.view_enter_identifier, this)
}
And creating my custom view like this:
override fun onCreateControllerView(layoutInflater: LayoutInflater, viewParent: ViewGroup) = EnterIdentifierView(layoutInflater.context)
I don't think this is an answer, more of a suggestion, but as I don't have enough reputation have to post it as such.
From my experience when I get this type of error it sometimes indicates an OutOfMemory error, check to make sure your custom classes aren't trying to load any large images etc.
Also check the full Stacktrace carefully, if you have access to one, for any OOMs
I just created a new projet, building some layouts, writing some code. Everything was fine except I got this error as shown in the picture below.
I tried to remove and type it again and when typing 'R.id.', there was no 'container' showing up in the list. So that means theres no problem with my R file, just that the 'container' word lost somewhere.
Those code above are actually default code in onCreate() method in your main activity everytime you create a new project in Android Studio. (I actually tried to create a new project to compare and yes it's the same, and without error as it's brand new.).
All I did was comment out the if statement block so the error goes away, and the application has run just fine on the emulator. I just don't know why I got that problem and how I can handle it as I may need to do that in the future. Thank you!
Edit after #Raghunandan has mentioned: Below is my xml.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/provide_information"
android:id="#+id/provideInfoButton"
android:layout_alignParentTop="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/take_picture"
android:id="#+id/takePictureButton"
android:layout_below="#+id/provideInfoButton"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_below="#+id/takePictureButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/classNameTextView"
android:layout_above="#+id/personNametextView2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginBottom="38dp"
android:layout_above="#+id/emailTextView"
android:layout_alignLeft="#+id/emailTextView"
android:id="#+id/personNameTextView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/emailTextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/classNameTextView"
android:layout_marginBottom="82dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/send_button"
android:id="#+id/sendButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The reason is that I changed the root layout to RelativeLayout (the default of Android Studio was FrameLayout which has an id of "container"). My bad :). Thanks for mentioning about posting the xml file. I have not noticed that as I'm not as familiar with Android Studio as with Eclipse yet.