Android Studio - Unable to choose declaration - android

I am trying to create an app with a navigation drawer and four fragments. So as I select the option from navigation drawer the view of the fragment gets displayed. Now, I have certain buttons created for the view, but whenever i am trying to initialize them in the code, i am getting runtime error which is pasted below.
When I did Command + Click on those ids R.id.bIndexOutOfBounds button, it showed me multiple declaration. I am unable to get how to choose a specific declaration, and why is android studio looking for 4 different fragment_crash.xml file ( layout file for the fragment) when only 1 file is present.
Please help me if anyone knows how to get only 1 layout_crash.xml file.
04-01 14:34:10.256 2067-2067/com.example.android.navigationdrawer E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.android.navigationdrawer, PID: 2067
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.navigationdrawer/com.example.android.navigationdrawer.NavigationDrawerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at com.example.android.navigationdrawer.CrashFragment.onCreateView(CrashFragment.java:56)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:833)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.Activity.performStart(Activity.java:5948)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

You should use "view" instead of "getView()" in bIndexOutOfBounds = (Button) getView().findViewById(R.id.bIndexOutOfBounds);
getView() will return the root view of a fragment which is returned by onCreateView() so you cannot get view by getView() inside of onCreateView()

Related

Unable to start activity ComponentInfo When Activity Is Not Present

So I had created an activity called BagActivity and it's adapter etc. and have since deleted it as it was no longer required. I clean built the project, uninstalled apk from test devices and yet, I get the following error:
FATAL EXCEPTION: main
Process: in.ddas.pretense, PID: 11858
java.lang.RuntimeException: Unable to start activity ComponentInfo{in.ddas.pretense/in.ddas.pretense.BagActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at in.ddas.pretense.BagActivity.onCreate(BagActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
at android.app.ActivityThread.access$800(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5221) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
What seems to be the problem?
Thanks.
EDIT: If I run this app in a different test device this error doesn't show! Why show it for 1 device?
It seems that you haven't deleted all BugActivity staff.
You have an exception:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at in.ddas.pretense.BagActivity.onCreate(BagActivity.java:28)
It caused second exception. So it says that you try to work with null RecyclerView object in onCreate method of BagActivity. You may delete layout of BagActivity without deleting activity class.

android: RecyclerView stopSmoothScrolle() null pointer exception

[Closed] read my last comment below.
I have a PagerView with some fragments, it was working but today unexpectedly crashed. The log it shows only this, i tried to catch the error with breakpoint but i didn't get anything.
Do you have any ideas ?
Here is my log
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.stopSmoothScroller()' on a null object reference
at android.support.v7.widget.RecyclerView.stopScrollersInternal(RecyclerView.java:1229)
at android.support.v7.widget.RecyclerView.stopScroll(RecyclerView.java:1221)
at android.support.v7.widget.RecyclerView.onDetachedFromWindow(RecyclerView.java:1426)
at android.view.View.dispatchDetachedFromWindow(View.java:13560)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2837)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2834)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4220)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4193)
at android.view.ViewGroup.removeView(ViewGroup.java:4124)
at android.support.v4.view.ViewPager.removeView(ViewPager.java:1326)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1055)
at android.support.v4.app.FragmentManagerImpl.detachFragment(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:724)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:488)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

NP on android.app.ActionBar.setCustomView(int) when using Theme.AppCompat.Light.DarkActionBar

I have imported my eclipse project to Android studio everything is working fine. I have custom Actionbar
which is like this: Oncreate of an activity I have the following
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(R.layout.bartitle);
TextView textViewTitle = (TextView) findViewById(R.id.titleEDIT);
textViewTitle.setText(res.getString(R.string.title));
setContentView(R.layout.register);
and now I have added Style for v21 too.
Style.xml for version 21 has the following:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">true</item>
</style>
</resources>
When I run the project: I get a white Screen and force Close with the following error log:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flm.sPar/com.flm.sPar.Register}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setCustomView(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setCustomView(int)' on a null object reference
at com.flm.sPar.Register.onCreate(Register.java:71)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I have been trying to solve this issue. Trying out all solutions given on SO or Google but couldn't get to solve the issue. Hence thought of asking a question on SO.
Thanks!
Use getSupportActionBar() instead of getActionBar() because you are using AppCompat library. If you're using the v7 appcompat library, your activity should instead extend AppCompatActivity and not Activity.
ActionBarActivity is deprecated in revision 22.1.0 of the Support Library and so AppCompatActivity should be used instead of ActionBarActivity as suggested by a user in comments.
Hope this will solve your issue :)

DevicePolicyManger().getCurrentFailedPasswordAttempts crashes app

Seems like some of the DeviceAdmin functionality has been broken in Lollipop, at least on my Nexus 5.
This works perfectly on KitKat, JellyBean and Ice Cream Sandwich
#Override
public void onPasswordFailed(Context context, Intent intent) {
DevicePolicyManager policyManager = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if(policyManager != null){
int attempts = policyManager.getCurrentFailedPasswordAttempts();
Log.v("TAG", "Attempts = " + attempts);
}
}
But on my Nexus 5 with Android 5.0 Lollipop it produces the following error:
11-24 16:11:50.117 27053-27053/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.myapp, PID: 27053
java.lang.RuntimeException: Unable to start receiver com.example.myapp.receivers.AdminReceiver: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586)
at android.app.ActivityThread.access$1700(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.admin.IDevicePolicyManager$Stub$Proxy.getCurrentFailedPasswordAttempts(IDevicePolicyManager.java:2476)
at android.app.admin.DevicePolicyManager.getCurrentFailedPasswordAttempts(DevicePolicyManager.java:1261)
at com.example.myapp.receivers.AdminReceiver.onPasswordFailed(AdminReceiver.java:48)
at android.app.admin.DeviceAdminReceiver.onReceive(DeviceAdminReceiver.java:417)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2579)
            at android.app.ActivityThread.access$1700(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
It's been reported as an issue in the L-preview as well.
My question, what is causing this?
I have got same error then I realised that it may not work for the version 5.0 and above versions.So what I did is I am checking number of wrong attempts programmatically.Like If the someone wants to unlock pattern or pin if he enters wrong then receiver will catch and calls the passwordFailed() method.So I created on SharedPreference object and I am storing the number of passwordFailed() method is called. Based on that I am getting number of wrong patterns.I think this is correct way or not I don't know.

Upgrading to SDK 21 - Error inflating class android.support.v7.internal.widget.ActionBarContainer

I'm trying to upgrade my app from API19 to API21
The main changes I've made to the gradle properties are:
compileSdkVersion 21
buildToolsVersion "21.0.2"
minSdkVersion 8
targetSdkVersion 21
compile 'com.android.support:appcompat-v7:21.0.0'
The app builds ok, but I always get the following error:
10-22 23:10:38.867 7972-8058/com.example.android.demo E/ACRA? com.example.android.demo fatal error : Unable to start activity ComponentInfo{com.example.android.demo/com.example.android.demo.MainActivity2}: android.view.InflateException: Binary XML file line #27: Error inflating class android.support.v7.internal.widget.ActionBarContainer
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.demo/com.example.android.demo.MainActivity2}: android.view.InflateException: Binary XML file line #27: Error inflating class android.support.v7.internal.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class android.support.v7.internal.widget.ActionBarContainer
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:273)
at android.support.v7.app.ActionBarActivityDelegateBase.createSupportActionBar(ActionBarActivityDelegateBase.java:155)
at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:123)
at android.support.v7.app.ActionBarActivity.getSupportActionBar(ActionBarActivity.java:73)
at com.example.android.demo.MainActivity2.onCreate(MainActivity2.java:243)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:273)
at android.support.v7.app.ActionBarActivityDelegateBase.createSupportActionBar(ActionBarActivityDelegateBase.java:155)
at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:123)
at android.support.v7.app.ActionBarActivity.getSupportActionBar(ActionBarActivity.java:73)
at com.example.android.demo.MainActivity2.onCreate(MainActivity2.java:243)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 11
at android.content.res.TypedArray.getDrawable(TypedArray.java:747)
at android.support.v7.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:66)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.ensureSubDecor(ActionBarActivityDelegateBase.java:273)
at android.support.v7.app.ActionBarActivityDelegateBase.createSupportActionBar(ActionBarActivityDelegateBase.java:155)
at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:123)
at android.support.v7.app.ActionBarActivity.getSupportActionBar(ActionBarActivity.java:73)
at com.example.android.demo.MainActivity2.onCreate(MainActivity2.java:243)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
I've tried the version 4 (which I was using previously) and the v7 ActionBarDrawerToggle (with a change to the new format for the constructor) but always get the same error. The apps theme is a parent of Theme.AppCompat.Light.DarkActionBar
I'm not really sure what to look at.
I had the same problem when trying to use ?attr/selectableItemBackground and based on your answer and some digging around on the internet I found out what was wrong for me (and probably you as well).
From this answer I learned that "? mark is used to reference style in current theme." Which means that when you use ?attr/ you refer to something in the current theme.
I noticed that I got this crash only when inflating using the application context and not when using the activity context. This blog post explains what's happening in "Context Capabilities" section.
...[When using the application context] inflation will be done with
the default theme for the system on which you are running, not what’s
defined in your application.
This mean that ?attr/ won't work since they refer to the current theme, not the default system theme you're inflating with.
So ?attr/ works fine if you make sure to inflate using the Activity context instead of the application context.
I had similar issue, i'm using AppCompat.v21 and supporting Android 5.0.
My layout uses the ?attr/[attribute_name] for some values and I use the activity context.
I changed it to ?android:attr/[attribute_name] and now my views inflate just fine on devices running Android 5.0.
For me the issue seemed to be in layout files when using the ?attr/ format for values. I'm not sure if it's theme related. I took all these out to get things going and then added styles back in.
style name="AppTheme" parent="Base.V23.Theme.AppCompat"
in style.xml worked for my app.

Categories

Resources