Cannot use Databinding in nested view [duplicate] - android

I was just reading about data binding feature in android. I was trying to bind a view from a nested layout. My activity is android's default template of DrawerMenuActivity and it has content_my_activity layout nested inside activity_my_activity layout.
I have 3 auto generated binding classes. MyActivityBinding, AppBarMyActivityBinding and ContentMyActivityBinding.
I tried initialising all 3 class as below:
MyActivity.java
MyActivityBinding activityBinding;
AppBarMyActivityBinding appBarBinding;
ContentMyActivityBinding contentBinding;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
activityBinding = DataBindingUtils.setContentView(this,
R.layout.activity_my_activity);
appBarBinding = DataBindingUtils.setContentView(this,
R.layout.app_bar_my_activity);
contentBinding = DataBindingUtils.setContentView(this,
R.layout.content_my_activity);
setName();
}
private void setName(){
contentBinding.setFirstName("Omkar");
}
But it throws RuntimeException as below:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 18305
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.userInterface.activity.MyActivity}: android.view.InflateException: Binary XML file line #35: Binary XML file line #27: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.view.InflateException: Binary XML file line #35: Binary XML file line #27: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276)
at com.example.userInterface.activity.MyActivity.onCreate(MyActivity.java:88)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276) 
at com.example.userInterface.activity.MyActivity.onCreate(MyActivity.java:88) 
at android.app.Activity.performCreate(Activity.java:6259) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Caused by: java.lang.IllegalArgumentException: Binary XML file line #27: Duplicate id 0x7f0e0081, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2416)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276) 
at com.example.userInterface.activity.MyActivity.onCreate(MyActivity.java:88) 
at android.app.Activity.performCreate(Activity.java:6259) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
How do I bind view from content_my_activity in MyActivity.java class, any help is appreciated.
Thanks.

DataBindingUtils.setContentView() does exactly how it is named: It sets the current view to the given parameter. I don't think you want your AppBar as the whole view, or do you?
Nevertheless, I assume that you include your layouts in your layout_activity_main.xml. George Mount has written a whole blog post about this feature. The code examples are from this post.
The first example would be your layout_activity_main.xml (Or however you have named it), where you include your AppBar, your Content and so on.
hello_world.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<include
android:id="#+id/world1"
layout="#layout/included_layout"/>
<include
android:id="#+id/world2"
layout="#layout/included_layout"/>
</LinearLayout>
</layout>
included_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/world"/>
</layout>
Now that the used layouts are clear, you'll need to jump into your ActivityMain, initialize the DataBinding and access your fields:
//This works if you have used a variable in your <data> tag and you have built your project afterwards, if you don't have an activity
HelloWorldBinding binding = HelloWorldBinding.inflate(getLayoutInflater());
//if you have an activity, you can use setContentView from the DataBindingUtils. Don't forget to delete the generic setContentView
HelloWorldBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_my_activity);
//Once you have accomplished the above, you can access your data-bound fields like this:
binding.hello.setText(“Hello”);
binding.world1.world.setText(“First World”);
binding.world2.world.setText(“Second World”);
It is important to set Ids to your <include> tags to access them correctly i your Activity.

One can pass the objects in XML ... the xmlns:bind namespace is required (similar to xmlns:app).
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/name"
bind:user="#{user}"/>
<include
layout="#layout/contact"
bind:user="#{user}"/>
</LinearLayout>
</layout>
source of the example: Layouts and binding expressions.

Related

Binary XML Line#0 inflate exception?

I am getting this error everytime i try to run my app and i dont know why im trying to make a basic welcome screen for my app that will then transition to my homepage but at the moment the welcome screen does not load and the app just says "Unable to run app" when i run the project. I have tried Doing a clean build and Rebuild on the project and other fixes for this error that other people have had but still no luck.
Below i have posted the error the logcat is giving at run time.
Error: FATAL EXCEPTION: main
Process: com.example.ross.moviepickerapp, PID: 21507
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ross.moviepickerapp/com.example.ross.moviepickerapp.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.widget.RelativeLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.ross.moviepickerapp.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7331) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.ross.moviepickerapp.MainActivity.onCreate(MainActivity.java:13) 
at android.app.Activity.performCreate(Activity.java:6904) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7331) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.ross.moviepickerapp.MainActivity.onCreate(MainActivity.java:13) 
at android.app.Activity.performCreate(Activity.java:6904) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7331) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.ross.moviepickerapp:drawable/welcomebackground" (7f060064) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060064 a=-1 r=0x7f060064}
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4245)
at android.content.res.Resources.loadDrawable(Resources.java:4152)
at android.content.res.Resources.loadDrawable(Resources.java:4002)
at android.content.res.TypedArray.getDrawable(TypedArray.java:886)
at android.view.View.<init>(View.java:4249)
at android.view.ViewGroup.<init>(ViewGroup.java:591)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:249)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:245)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:241)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:631) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:706) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:774) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:380) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.ross.moviepickerapp.MainActivity.onCreate(MainActivity.java:13) 
at android.app.Activity.performCreate(Activity.java:6904) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415) 
at android.app.ActivityThread.access$1100(ActivityThread.java:229) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:7331) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Here is my code for MainActivity:
package com.example.ross.moviepickerapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
public class MainActivity extends AppCompatActivity
{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
setContentView(R.layout.welcome_screen);
}
}
And here is my code for my XMl:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/welcome_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ross.moviepickerapp.MainActivity"
android:background="#drawable/welcomebackground">
<LinearLayout
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_marginTop="150dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_to"
android:textSize="40sp"
android:textStyle="italic|bold"
android:textColor="#color/colorPrimary"
/>
<TextView
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/movie_picker"
android:textSize="30sp"
android:textStyle="italic|bold"
android:textColor="#color/colorPrimaryDark"
/>
</LinearLayout>
</RelativeLayout>
Can someone please help me with this ?
You may have problem with the line
android:background="#drawable/welcomebackground"
in the xml file. Try to comment this line and clean the project and run.
Create a new android activity using new > empty activity and see how is work.
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.ross.moviepickerapp:drawable/welcomebackground" (7f060064) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060064 a=-1 r=0x7f060064}
you need to check this file.
you can add resouces via Android Studio , go to app>res>drawable>"Right Click">New>"Image Asset" or "Vector Asset"
I don't know if it is related to the android library version with compiledSdkVersion and targetSdkVersion. Previously I got the error when I used :
compileSdkVersion 26
targetSdkVersion 26
'com.android.support:appcompat-v7:26.1.0'
'com.android.support:design:26.1.0'
then I changed to the newer version and it worked :
compileSdkVersion 27
targetSdkVersion 27
'com.android.support:appcompat-v7:27.0.2'
'com.android.support:design:27.0.2'
I hope this will help

error in inflating layout in android studio

I want to add footer in my listview by inflating a different layout.
here is my code ...
View loadMoreView, loading_img;
loading_img = ((LayoutInflater)this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.loading_img, null, false);
loadMoreView = ((LayoutInflater)this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.load_more_btn, null, false);
Here is xml file loading_img.xml code ....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<pl.droidsonroids.gif.GifImageView
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="#+id/loading_img"
android:src="#mipmap/progress_bar_default"
android:background="#color/pd_color1"
android:layout_marginLeft="20dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="10dp"/>
</LinearLayout>
but it shows error....
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.plexusd.plexusd/com.plexusd.plexusd.Notification}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2572)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.plexusd.plexusd.Notification.onCreate(Notification.java:104)
at android.app.Activity.performCreate(Activity.java:6337)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at com.plexusd.plexusd.Notification.onCreate(Notification.java:104) 
at android.app.Activity.performCreate(Activity.java:6337) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at com.plexusd.plexusd.Notification.onCreate(Notification.java:104) 
at android.app.Activity.performCreate(Activity.java:6337) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 3686412 byte allocation with 2971336 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:831)
at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
at android.graphics.Bitmap.createBitmap(Bitmap.java:775)
at pl.droidsonroids.gif.GifDrawable.<init>(GifDrawable.java:248)
at pl.droidsonroids.gif.GifDrawable.<init>(GifDrawable.java:160)
at pl.droidsonroids.gif.GifDrawable.<init>(GifDrawable.java:95)
at pl.droidsonroids.gif.GifViewUtils.setResource(GifViewUtils.java:53)
at pl.droidsonroids.gif.GifViewUtils.getResourceId(GifViewUtils.java:41)
at pl.droidsonroids.gif.GifViewUtils.initImageView(GifViewUtils.java:29)
at pl.droidsonroids.gif.GifImageView.<init>(GifImageView.java:41)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at com.plexusd.plexusd.Notification.onCreate(Notification.java:104) 
at android.app.Activity.performCreate(Activity.java:6337) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
07-06 00:23:56.956 24424-24424/com.plexusd.plexusd I/Process: Sending signal. PID: 24424 SIG: 9
The cause is shown down at the bottom of stacktrace:
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 3686412 byte allocation with 2971336 free bytes and 2MB until OOM
The suggested ways to deal with OOM are:
If you are working with large-sized GIFs you can subsample them, see: #284 (comment)
You can use tools like MAT, or Memory Monitor in Android Studio to locate potential causes.
You can increase available heap space by using android:largeHeap="true" in AndroidManifest.xml or dividing app to
separate processes (by adding android:process tags) but those
workarounds may cause side-effects.
https://github.com/koral--/android-gif-drawable/issues/326

android.view.InflateException , Error inflating class fragment

I know this is a repeat, but cant find a solution. This is my Map XML file
activity_map
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.healthapp.MapActivity" />
<fragment
android:id="#+id/fragment_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
This is my MapActivity (on setContentView) snippet where the error occurs:
MapActivity is extending FragmentActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
And my Logcat
FATAL EXCEPTION: main
Process: com.example.ather.healthapp, PID: 10185
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ather.healthapp/com.example.ather.healthapp.MapActivity}: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #14: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2172)
at com.example.ather.healthapp.MapActivity.onCreate(MapActivity.java:97)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
at android.app.Activity.setContentView(Activity.java:2172) 
at com.example.ather.healthapp.MapActivity.onCreate(MapActivity.java:97) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.NullPointerException
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:466)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2379)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:376)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
at android.app.Activity.setContentView(Activity.java:2172) 
at com.example.ather.healthapp.MapActivity.onCreate(MapActivity.java:97) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
Your help will be much appreciated.
I have tried to change layout of activity_map to LinearLayout, RelativeLayout and Framelayout, but nothing works. Tried adding android:name or class to the fragment in line 15 of activity_map.
The problem is your second fragment tag hasn't a fragment class defined, then a NullPointerException is launched because the Android framework expects a class to be loaded there. You should get rid of that tag (if you don't need it), add a fragment class to be loaded or use a dynamic fragment loading approach if you want to add dynamically a fragment there. Check this guide of the official docs.
Did you declare these in your Manifest.xml file?
Declare it within the <application> element and your code should work.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
And also
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

How to set Android DataBinding in nested layouts

I was just reading about data binding feature in android. I was trying to bind a view from a nested layout. My activity is android's default template of DrawerMenuActivity and it has content_my_activity layout nested inside activity_my_activity layout.
I have 3 auto generated binding classes. MyActivityBinding, AppBarMyActivityBinding and ContentMyActivityBinding.
I tried initialising all 3 class as below:
MyActivity.java
MyActivityBinding activityBinding;
AppBarMyActivityBinding appBarBinding;
ContentMyActivityBinding contentBinding;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
activityBinding = DataBindingUtils.setContentView(this,
R.layout.activity_my_activity);
appBarBinding = DataBindingUtils.setContentView(this,
R.layout.app_bar_my_activity);
contentBinding = DataBindingUtils.setContentView(this,
R.layout.content_my_activity);
setName();
}
private void setName(){
contentBinding.setFirstName("Omkar");
}
But it throws RuntimeException as below:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 18305
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.userInterface.activity.MyActivity}: android.view.InflateException: Binary XML file line #35: Binary XML file line #27: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.view.InflateException: Binary XML file line #35: Binary XML file line #27: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276)
at com.example.userInterface.activity.MyActivity.onCreate(MyActivity.java:88)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276) 
at com.example.userInterface.activity.MyActivity.onCreate(MyActivity.java:88) 
at android.app.Activity.performCreate(Activity.java:6259) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Caused by: java.lang.IllegalArgumentException: Binary XML file line #27: Duplicate id 0x7f0e0081, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2416)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276) 
at com.example.userInterface.activity.MyActivity.onCreate(MyActivity.java:88) 
at android.app.Activity.performCreate(Activity.java:6259) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
How do I bind view from content_my_activity in MyActivity.java class, any help is appreciated.
Thanks.
DataBindingUtils.setContentView() does exactly how it is named: It sets the current view to the given parameter. I don't think you want your AppBar as the whole view, or do you?
Nevertheless, I assume that you include your layouts in your layout_activity_main.xml. George Mount has written a whole blog post about this feature. The code examples are from this post.
The first example would be your layout_activity_main.xml (Or however you have named it), where you include your AppBar, your Content and so on.
hello_world.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<include
android:id="#+id/world1"
layout="#layout/included_layout"/>
<include
android:id="#+id/world2"
layout="#layout/included_layout"/>
</LinearLayout>
</layout>
included_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/world"/>
</layout>
Now that the used layouts are clear, you'll need to jump into your ActivityMain, initialize the DataBinding and access your fields:
//This works if you have used a variable in your <data> tag and you have built your project afterwards, if you don't have an activity
HelloWorldBinding binding = HelloWorldBinding.inflate(getLayoutInflater());
//if you have an activity, you can use setContentView from the DataBindingUtils. Don't forget to delete the generic setContentView
HelloWorldBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_my_activity);
//Once you have accomplished the above, you can access your data-bound fields like this:
binding.hello.setText(“Hello”);
binding.world1.world.setText(“First World”);
binding.world2.world.setText(“Second World”);
It is important to set Ids to your <include> tags to access them correctly i your Activity.
One can pass the objects in XML ... the xmlns:bind namespace is required (similar to xmlns:app).
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/name"
bind:user="#{user}"/>
<include
layout="#layout/contact"
bind:user="#{user}"/>
</LinearLayout>
</layout>
source of the example: Layouts and binding expressions.

Binary XML file line #: Error inflating error for Spinner : Only on Android (6.0)-Marshmallow

ArrayAdapter < String > dataAdapter = new ArrayAdapter < String >
(this, R.layout.spinner_list_item, list0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
dataAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
} else {
dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_custom);
}
mSpinner0.setAdapter(dataAdapter);
I also tried above code but no results..
I am using custom xml adpter.setDropDownViewResource() method like dataAdapter.setDropDownViewResource
(R.layout.simple_spinner_dropdown_custom);
There is total 3 spinner in my Layout.
It's working fine with other 2 Spinner But fist spinner click gives me this error in Android 6.0.
It's working fine in Android L (API-22)
Please help.
Thanks in advance.
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:textColor="#color/normal_color"
android:ellipsize="marquee"
android:padding="10dp"
android:background="#color/white"
android:layout_height="wrap_content" />
log
E/GAv4: Successfully bound to service but never got onServiceConnected
callback E/AndroidRuntime: FATAL EXCEPTION: main Process: com.abc.xyz, PID: 22725
android.view.InflateException: Binary XML file line #19: Binary XML file
line #19: Error inflating class <unknown> at
android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
atandroid.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448)
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963)
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959)
at android.widget.Spinner.measureContentWidth(Spinner.java:833)
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220)
at android.widget.Spinner.performClick(Spinner.java:758)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
atcom.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)at
android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963)  at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959)  at android.widget.Spinner.measureContentWidth(Spinner.java:833)  at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194)  at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220)  at android.widget.Spinner.performClick(Spinner.java:758)  at android.view.View$PerformClick.run(View.java:21163)  at android.os.Handler.handleCallback(Handler.java:746)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5443)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)  Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at android.view.LayoutInflater.createView(LayoutInflater.java:619)at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378) 
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963) 
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959) 
at android.widget.Spinner.measureContentWidth(Spinner.java:833) 
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194) 
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220) 
at android.widget.Spinner.performClick(Spinner.java:758) 
at android.view.View$PerformClick.run(View.java:21163) 
at android.os.Handler.handleCallback(Handler.java:746) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:482)
at android.widget.TextView.<init>(TextView.java:750)
at android.widget.TextView.<init>(TextView.java:671)
at android.widget.TextView.<init>(TextView.java:667)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378) 
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963) 
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959) 
at android.widget.Spinner.measureContentWidth(Spinner.java:833) 
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194) 
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220) 
at android.widget.Spinner.performClick(Spinner.java:758) 
at android.view.View$PerformClick.run(View.java:21163) 
at android.os.Handler.handleCallback(Handler.java:746) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5443) 
at java.lang.reflect.Method.invoke(Native Method) 
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
I had the same issue. It happens if you add a theme to your drop down item. You should apply a theme only to your spinner. In your case, you have added a style to the TextView. You have not posted what that style contains, but if it has a theme such as
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
you need to remove it.

Categories

Resources