DevicePolicyManger().getCurrentFailedPasswordAttempts crashes app - android

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.

Related

IncompatibleClassChangeError when called "realm.copyToRealmOrUpdate({RealmModel})"

when i call "realm.copyToRealmOrUpdate({RealmObject})", app crashes on lower API(21-25). No problem in version API-25 and above. Logcat output :
java.lang.IncompatibleClassChangeError: The method 'java.lang.Class java.lang.Object.getClass()' was expected to be of type interface but instead was found to be of type virtual (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
at io.realm.DefaultRealmModuleMediator.copyOrUpdate(DefaultRealmModuleMediator.java:131)
at io.realm.Realm.copyOrUpdate(Realm.java:1815)
at io.realm.Realm.copyToRealmOrUpdate(Realm.java:1199)
at com.viyatek.ultimatefacts.Activites.MainActivity.DataFetched$lambda-10(MainActivity.kt:826)
at com.viyatek.ultimatefacts.Activites.MainActivity.$r8$lambda$fX_wkxDWKFkFuw4LXNz0m5YzJyo(MainActivity.kt)
at com.viyatek.ultimatefacts.Activites.MainActivity$$ExternalSyntheticLambda4.execute(D8$$SyntheticClass)
at io.realm.Realm.executeTransaction(Realm.java:1604)
at com.viyatek.ultimatefacts.Activites.MainActivity.DataFetched(MainActivity.kt:823)
at com.viyatek.ultimatefacts.NetworkOperations.getData.ExecuteNetWorkCall$lambda-0(getData.kt:111)
at com.viyatek.ultimatefacts.NetworkOperations.getData.$r8$lambda$Va8-rJSbrmVyGMKSedsNwZR74V8(getData.kt)
at com.viyatek.ultimatefacts.NetworkOperations.getData$$ExternalSyntheticLambda1.onResponse(D8$$SyntheticClass)
at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:100)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:102)
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: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 use in top-level gradle;
classpath "io.realm:realm-gradle-plugin:10.10.1"
I have no idea for the solution. I added try-catch block for now. I suspect ProGuard. but, for now i couldn't find the solution

app crashes when changing the font style of the device

I am facing a issue in Samsung mobile, the issue is this, i open the application that i have made and minimized the app now the app is running at the background, now i go to my mobile
settings-->Display--> font style,
Then i changed the font when i come back and open the app that was running at the back ground the app crashes
I do not know where the issue is can you please give some idea on how to move about
This was the error that i was able to see in my logcat
2-12 17:58:54.883 1473-1473/com.mysmcc E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mysmcc, PID: 1473 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mysmcc/com.mysmcc.activities.AppMainActivity}: java.lang.StringIndexOutOfBoundsException: length=0; index=0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769) at android.app.ActivityThread.access$900(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5910) 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:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) Caused by: java.lang.StringIndexOutOfBoundsException: length=0; index=0 at java.lang.String.indexAndLength(String.java:500) at java.lang.String.charAt(String.java:494) at android.graphics.Color.parseColor(Color.java:209) at com.mysmcc.activities.AppMainActivity.onCreate(AppMainActivity.java:213) at android.app.Activity.performCreate(Activity.java:6178) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769) at android.app.ActivityThread.access$900(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5910) 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:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

java.lang.NoClassDefFoundError Android

I was integrating XMPP in my project, it was working fine but it crashed some of the device like Moto G... Below i mentioned crash report
java.lang.NoClassDefFoundError: com.app.xmpp.MyXMPP$MMessageListener
at
com.app.xmpp.MyXMPP.init(MyXMPP.java:88)
at
com.app.xmpp.MyXMPP.<init>(MyXMPP.java:57)
at
com.app.xmpp.MyXMPP.getInstance(MyXMPP.java:63)
at
com.app.xmpp.XmppService.onCreate(XmppService.java:54)
at
android.app.ActivityThread.handleCreateService(ActivityThread.java:2791)
at
android.app.ActivityThread.access$1800(ActivityThread.java:155)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1400)
at
android.os.Handler.dispatchMessage(Handler.java:102)
at
android.os.Looper.loop(Looper.java:135)
at
android.app.ActivityThread.main(ActivityThread.java:5343)
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:905)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Help me out how to solve this issue.

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 :)

Android Studio - Unable to choose declaration

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()

Categories

Resources