android.view.InflateException when extending AppCompatSpinner - android

I have successfully created custom views in the past extending LinearLayout or android.support.v7.widget.CardView, however I can't seem to get it working when extending from android.support.v7.widget.AppCompatSpinner. I don't see why it is a problem for this specific class so I must be overlooking something.
I have the following class CustomSpinner
public class CustomSpinner extends android.support.v7.widget.AppCompatSpinner {
public CustomSpinner(Context context)
{
this(context, null);
}
public CustomSpinner(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context, attrs, 0);
}
public CustomSpinner(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle)
{
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.view_custom_spinner, this);
}
}
And the R.layout.view_custom_spinner
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.AppCompatSpinner
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/view_custom_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/minimum_clickable_area"
android:gravity="center_vertical"/>
And I use the custom component in another layout for 'MyFragment' like this (line #11 mentioned in the stacktrace):
<my.custom.namespace.CustomSpinner
android:id="#+id/view_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The strange thing is that when I extend the CustomSpinner class from LinearLayout everything is working fine and I don't get an InflateException.
I get the following stacktrace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.custom.namespace.MyActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #11: Error inflating class my.custom.namespace.CustomSpinner
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3320)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
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:7407)
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 #8: Binary XML file line #11: my.custom.namespace.CustomSpinner
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
at android.app.Activity.performStart(Activity.java:6943)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
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:7407) 
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 #11: Error inflating class my.custom.namespace.CustomSpinner
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) 
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819) 
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797) 
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590) 
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377) 
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239) 
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231) 
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181) 
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192) 
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572) 
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177) 
at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258) 
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266) 
at android.app.Activity.performStart(Activity.java:6943) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
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:7407) 
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 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:843) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:429) 
at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) 
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819) 
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797) 
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590) 
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377) 
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239) 
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231) 
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181) 
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192) 
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572) 
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177) 
at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258) 
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266) 
at android.app.Activity.performStart(Activity.java:6943) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416) 
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:7407) 
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 l

I don't get why you are inflating the layout of the spinner. The spinner has its own layout by itself, you don't need to create the xml with a spinner inside. For linear layout it makes sense to inflate your own layout beacause it's a ViewGroup and inside your custom view class you can bind the linear layout's children, but for the spinner simply work on the spinner layout elements, using your custom view attributes to edit the layout.
In summary, you can't add children to a spinner layout, so it doesn't make sense to inflate a custom xml for it. Simply remove
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.view_custom_spinner, this);
from your code and you'll have a perfectly working class extending the spinner.

Related

setText Textview from custum imageview

I have an activity which has custom imageView. in imageView, I want to call a method from the activity, and that method wants setText Textview.
is it possible?
I have done these code but I've encountered an error.
MainActivity:
package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
pubic void myFunction(int score){
((TextView)findViewById(R.id.txtScore)).setText(score+"");
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="#+id/txtScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a TextView" />
<com.example.MyImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
MyImageViewClass:
public class MyImageViewClass extends ImageView {
public MyImageViewClass(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onDraw(Canvas canvas) {
((MainActivity)context).myFunction(12);
}
}
when call myFunction() from imageView و Such an error will appear:
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.example.adisun.gamesss.ImageViews.GmaeMemClassicImageView
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.adisun.gamesss.activity.GameActivity.onCreate(GameActivity.java:19)
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 #9: Error inflating class com.example.adisun.gamesss.ImageViews.GmaeMemClassicImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
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.adisun.gamesss.activity.GameActivity.onCreate(GameActivity.java:19) 
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 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
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.adisun.gamesss.activity.GameActivity.onCreate(GameActivity.java:19) 
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.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.adisun.gamesss.activity.GameActivity.setScore(GameActivity.java:38)
at com.example.adisun.gamesss.ImageViews.GmaeMemClassicImageView.initialize(GmaeMemClassicImageView.java:75)
The problem Here ((MainActivity)context).myFunction(12) is getting called inside onDraw. this is why you are getting a NPE->
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
You can not access a View from onDraw of a another view because layout for the Activity is not inflated Yet .
Even if you can this is never a way cause onDraw get called several times whenever invalidate get called.
Look for some elegant way to solve your problem . Your problem is pretty much unclear right not so i can not suggest anything.

Custom View not inflating when using WindowManager in service

I am trying to add a custom KnockView using WindowManager in service. Here is KnockView class.
public class KnowView extends LinearLayout {
public KnowView(Context context) {
super(context);
initView();
}
public KnowView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.KnowView);
try {
isFromChangeKnock = typedArray.getBoolean(R.styleable.KnowView_changeKnock, false);
} catch (Exception e) {
e.printStackTrace();
} finally {
typedArray.recycle();
}
initView();
}
public KnowView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView();
}
private void initView() {
mainLayout = inflate(getContext(), R.layout.knock_code, this);
}
}
So basically in KnowView class we are inflating another layout (knock_code) and adding that into KnowView. And after that, I am using this custom Knockview in another layout called. main_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:orientation="vertical"
tools:context=".MainActivity">
<production.kado.lock.views.KnowView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="20dp"
app:changeKnock="true" />
</RelativeLayout>
and inflating main_view.xmlin service with WindowManager like this.
WindowManager windowManager = ((WindowManager)
this.getSystemService(WINDOW_SERVICE));
View view1 = LayoutInflater.from(this).inflate(R.layout.main_view, null);
windowManager.addView(mainView, getViewParam(true));
But I am getting these exceptions when I run this service.
07-12 09:16:34.087 12020-12020/production.kado.lock E/AndroidRuntime: FATAL EXCEPTION: main
Process: production.kado.lock, PID: 12020
java.lang.RuntimeException: Unable to create service production.kado.lock.services.LockService: android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class <unknown>
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3252)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1594)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.view.View.inflate(View.java:21008)
at production.kado.lock.views.KnowView.findAllViews(KnowView.java:115)
at production.kado.lock.views.KnowView.initView(KnowView.java:99)
at production.kado.lock.views.KnowView.<init>(KnowView.java:46)
at production.kado.lock.services.LockService.addLockView(LockService.java:87)
at production.kado.lock.services.LockService.onCreate(LockService.java:69)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3242)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1594)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 35: TypedValue{t=0x2/d=0x7f02012d a=-1}
I also used KnockView in activity but in activity, it works fine. The only problem is when used in service with WindowManager.
I figured out the problem I was using this
android:background="?selectableItemBackground"
property in my layout button after removing this it's working fine

Cannot inflate custom viewpager

Hi guys so i have this custom view pager i made in a java class. When I put that viewpager in xml and run the program it crashes. From the stack trace it looks like its looking in the wrong place but i have no idea how to fix it.
Here is my view pager class
public class MyViewPager extends ViewPager
{
private boolean swipeable;
public MyViewPager(Context context) {
super(context);
}
public MyViewPager (Context context, AttributeSet attrs) {
super(context, attrs);
this.swipeable = true;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onTouchEvent(event);
}
return false;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setSwipeable(boolean swipeable) {
this.swipeable = swipeable;
}
}
Here's my xml
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/main_TL"
app:tabTextColor="#color/white"
app:tabSelectedTextColor="#color/white"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabIndicatorColor="#color/white"
app:tabBackground="#color/salmon_main"/>
<com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_VP">
</com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager>
Here's my stack trace:
Process: com.daprlabs.aaron.swipedeck2, PID: 17841
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.daprlabs.aaron.swipedeck2/com.daprlabs.aaron.zivitApp.Main.Main}: android.view.InflateException: Binary XML file line #35: Binary XML file line #35: Error inflating class com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
at android.app.ActivityThread.access$900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: android.view.InflateException: Binary XML file line #35: Binary XML file line #35: Error inflating class com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager
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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.daprlabs.aaron.zivitApp.Main.Main.onCreate(Main.java:49)
at android.app.Activity.performCreate(Activity.java:6272)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5525) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
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.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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
at com.daprlabs.aaron.zivitApp.Main.Main.onCreate(Main.java:49) 
at android.app.Activity.performCreate(Activity.java:6272) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5525) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager" on path: DexPathList[[zip file "/data/app/com.daprlabs.aaron.swipedeck2-1/base.apk"],nativeLibraryDirectories=[/data/app/com.daprlabs.aaron.swipedeck2-1/lib/arm64, /data/app/com.daprlabs.aaron.swipedeck2-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:583)
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.rInflate(LayoutInflater.java:838) 
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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
at com.daprlabs.aaron.zivitApp.Main.Main.onCreate(Main.java:49) 
at android.app.Activity.performCreate(Activity.java:6272) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5525) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Suppressed: java.lang.ClassNotFoundException: com.daprlabs.aaron.zivitApp.Main.Main.MyViewPager
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 26 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
EDITED
My project structure:
In my comment I did mentioned that we need to create a separate class for the view e.g. MyViewPager.java because we can't inflate a view in an inner-class since it is dependent in its top-level class (The inflater is not smart for that job, nor it is not easy to develop this kind of inflater), other option is to declare it static.

Binary XML file line #13: Binary XML file line #13: Error inflating class fragment

I am noticing an issue with inflating the initial fragment via XML. What I am noticing is that the onPause(), onDestroy() lifecycle methods are not being called properly. If I replace this fragment, everything works fine. The issue is only when the app is first launched and the initial fragment is inflated via XML. To avoid this conflict I tried to launch the initial fragment programmatically but I keep receiving an inflating class error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com..tap/com.example.tap.activity.MainActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
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 #13: Binary XML file line #13: Error inflating class fragment
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:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.example.tap.activity.MainActivity.onCreate(MainActivity.java:69)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7237) 
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 #13: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
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:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
at com.example.tap.activity.MainActivity.onCreate(MainActivity.java:69) 
at android.app.Activity.performCreate(Activity.java:6876) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7237) 
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.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:469)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2384)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:77)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:527) 
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:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
at com.example.tap.activity.MainActivity.onCreate(MainActivity.java:69) 
at android.app.Activity.performCreate(Activity.java:6876) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) 
at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7237) 
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 how I am inflating my initial fragment via XML. In the Activity that is first launched, I added this segment of code to its layout
<fragment
android:id="#+id/frag_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragments.MainFragment" />
When I change fragments, such as clicking on a tab I replace the fragment using the following method
public void addFragmentReplace(int containerId, Fragment fragment) {
// check if the fragment has been added already
Fragment temp = mFragmentManager.findFragmentByTag(fragment.getClass().getSimpleName());
if (!Utils.checkIfNull(temp) && temp.isAdded()) {
return;
}
// replace fragment and transition with animation
try {
if (!Utils.isStringEmpty(getTopFragment().getTag()) && getTopFragment().isAdded()) {
// pop back stack
popBackStack();
}
mFragmentManager.beginTransaction().replace(containerId, fragment,
fragment.getClass().getSimpleName()).addToBackStack(null).commit();
} catch (IllegalStateException e) {
e.printStackTrace();
mFragmentManager.beginTransaction().replace(containerId, fragment,
fragment.getClass().getSimpleName()).addToBackStack(null)
.commitAllowingStateLoss(); // used as last resort
}
}
After changing tabs the fragment lifecycle works perfectly. Even when returning to the original tab. But how do I get the lifecycle to work initially when the fragment is inflated via XML or how can I remove the class property from XML and just add the fragment?
Adding a fragment in the Activity that is initially launched causes the inflate error. This is how I was adding the fragment, using the following method
public void addFragment(int containerId, Fragment fragment) {
// check if the fragment has been added already
Fragment temp = mFragmentManager.findFragmentByTag(fragment.getClass().getSimpleName());
if (!Utils.checkIfNull(temp) && temp.isAdded()) {
return;
}
// add fragment and transition with animation
mFragmentManager.beginTransaction().add(containerId, fragment,
fragment.getClass().getSimpleName()).addToBackStack(null).commit();
}
Thank you in advance!

TabLayout removes all tabs when PagerAdapter invoke notifyDataSetChanged() override TabLayout class and Exception

I used to use text as title in TabLayout, but I decide to change to icon, at onCreateView use tabLayout.getTabAt(0).setIcon(R.drawable.ic). But When I update my data set in PagerArray by notifyDataSetChanged() all tabs become empty. I found: Issue 202402
They writing the solution is create new Class extends TabLayout. So I did it:
public class SuperTabLayout extends TabLayout {
public SuperTabLayout(Context context) {
super(context);
}
#Override
public void addTab(Tab tab, boolean setSelected) {
tab.setIcon(R.drawable.ic_assessment_24dp);
super.addTab(tab, setSelected);
}
}
And they writing so that don't forget about layout
<com.paragraf.workhours.SuperTabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tablay1"
android:layout_below="#+id/ivPersonAvatar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
class="com.paragraf.workhours.SuperTabLayout"
/>
But I got something like this:
10-17 21:07:18.600 28964-28964/com.paragrafxv.workhours E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.paragrafxv.workhours, PID: 28964
android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class com.paragrafxv.workhours.SuperTabLayout
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.paragrafxv.workhours.SitePersonFragment.onCreateView(SitePersonFragment.java:86)
at android.app.Fragment.performCreateView(Fragment.java:2220)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.BackStackRecord.run(BackStackRecord.java:793)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5539)
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 #23: Error inflating class com.paragrafxv.workhours.SuperTabLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:628)
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.paragrafxv.workhours.SitePersonFragment.onCreateView(SitePersonFragment.java:86) 
at android.app.Fragment.performCreateView(Fragment.java:2220) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148) 
at android.app.BackStackRecord.run(BackStackRecord.java:793) 
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535) 
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5539) 
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.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructor(Class.java:528)
at java.lang.Class.getConstructor(Class.java:492)
at android.view.LayoutInflater.createView(LayoutInflater.java:592)
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.paragrafxv.workhours.SitePersonFragment.onCreateView(SitePersonFragment.java:86) 
at android.app.Fragment.performCreateView(Fragment.java:2220) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148) 
at android.app.BackStackRecord.run(BackStackRecord.java:793) 
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535) 
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5539) 
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) 
Somebody?
You need to implement all of the parent class' constructors. Specifically:
TabLayout(Context) (used when manually creating)
TabLayout(Context, AttributeSet) (used when inflating from XML)
TabLayout(Context, AttributeSet, int) (used when inflating from XML with a style attribute)
As you don't declare the second one, your SuperTabLayout cannot be used from XML.
Are you intentionally calling super.addTab(tab, setSelected) after calling tab.setIcon()? That may be the issue.

Categories

Resources