I was working on a project which used exclusively strings literals in the code and layout, so I extracted them to strings.xml to later localize. Unfortunately after extracting all the strings and when trying to run I get a runtime error:
2020-06-16 13:54:20.482 22717-22717/com.Applikation.OReels.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.Applikation.OReels.android, PID: 22717
java.lang.RuntimeException: Unable to create application com.Applikation.progressplay.Android.ProgressPlayApplication: android.content.res.Resources$NotFoundException: String resource ID #0x7f0f0062
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5743)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0f0062
at android.content.res.Resources.getText(Resources.java:339)
at android.content.res.Resources.getString(Resources.java:433)
at com.Applikation.progressplay.Android.Shared.DataManager.DataManager.createServerMessage(DataManager.kt:183)
at com.Applikation.progressplay.Android.Shared.DataManager.DataManager.<init>(DataManager.kt:33)
at com.Applikation.progressplay.Android.Shared.DataManager.DataManager$Companion.shared(DataManager.kt:45)
at com.Applikation.progressplay.Android.ProgressPlayApplication.onCreate(ProgressPlayApplication.kt:22)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
DataManager.kt Line 183:
serverErrors.put("em_DailyDepositLimitIsBelowZero" , Resources.getSystem().getString(R.string.daily_deposit_limit))
Any help or advice would be welcome.
Simply use getString() instead of Resources.getSystem().getString()
Related
enter image description here
I am creating a chat in android studio, when I run the program everything comes up with green chekes, but in the log I get the following error and send me to correct the problem in the Main Activity, in the emoludar opens the application and closes it.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: mensajeria.chatappsistema, PID: 11008
java.lang.RuntimeException: Unable to start activity ComponentInfo{mensajeria.chatappsistema/mensajeria.chatappsistema.MainActivity}: java.lang.ClassCastException: android.support.v7.app.AlertController$RecycleListView cannot be cast to android.support.v7.widget.RecyclerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassCastException: android.support.v7.app.AlertController$RecycleListView cannot be cast to android.support.v7.widget.RecyclerView
at mensajeria.chatappsistema.MainActivity.onCreate(MainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
Application terminated.
In XML file you are using different recyclerview and java you are casting different recyclerview that's why the error is coming. Use the same type of recyclerview in both XML and java file.
2019-03-19 17:48:03.848 9496-9496/com.example.test_firebase E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.test_firebase, PID: 9496
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test_firebase/com.example.test_firebase.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.test_firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.test_firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.0.2:240)
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database##16.0.2:67)
at com.example.test_firebase.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
"Default FirebaseApp is not initialized in this process"
In this link is described how to setup your project with Firebase (Automatically from Android Studio and Manually). My recommendation is to do it Manually.
https://firebase.google.com/docs/android/setup
If this is not your case, you only need to start method:
Firebase.init();
and
FirebaseApp.initializeApp(this);
I'm trying to create an application that uses Wifi Aware but my WifiAwareManager returns null. How can I properly initialize the class so that it does not return null? What is the cause of this behavior? I'm quite sure that Pixel 2 XL does support Wifi Aware, am I wrong?
final WifiAwareManager wifiAwareManager = (WifiAwareManager) getSystemService(Context.WIFI_AWARE_SERVICE);
if (wifiAwareManager.isAvailable()) {
System.out.println("aware avaiable");
} else {
System.out.println("aware not avaiable");
}
The logcat is:
2018-10-11 12:45:53.926 4003-4003/com.example.lucapalmieri.awarecheckE/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lucapalmieri.awarecheck, PID: 4003
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.net.wifi.aware.WifiAwareManager.isAvailable()' on a null object reference
at com.example.lucapalmieri.awarecheck.MainActivity.check(MainActivity.java:71)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Cause isAvailiable is added only from api level 26 as WifiAwareManager. I assume you are using android with version lower than Android 8.0
https://developer.android.com/reference/android/net/wifi/aware/WifiAwareManager.html#isAvailable()
In my application I have the following line:
String ci = getResources().getString(R.string.cidades);
This is throwing an exception while running the application. This only occurs in version 7.1 and 8 of Android, in the previous normal wheel, does anyone know why?
Logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{insidetechnology.studio.ostdor.anestesiaanimal/insidetechnology.studio.ostdor.anestesiaanimal.autenticacao.state}: java.lang.IndexOutOfBoundsException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IndexOutOfBoundsException
at android.content.res.StringBlock.nativeGetString(Native Method)
at android.content.res.StringBlock.get(StringBlock.java:82)
at android.content.res.AssetManager.getResourceValue(AssetManager.java:236)
at android.content.res.AssetManager.getResourceText(AssetManager.java:164)
at android.content.res.Resources.getText(Resources.java:334)
at android.content.res.Resources.getString(Resources.java:432)
at insidetechnology.studio.ostdor.anestesiaanimal.autenticacao.state.onCreate(state.java:38)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
A workaround can be using string-array instead of string
<string-array name="items">
<item>item0</item>
<item>item1</item>
...
</string-array>
then
String[] items = getResources().getStringArray(R.array.items);
I dont know why but maybe your string exceeds the limitation of string resource in new Android versions
I'm having what I believe to be dex issues, which is something pretty foreign to me. My app crashes when it tries to instantiate an OkHttpClient. I see that a lot of people have this issue, but all the common solutions (which I mention below) haven't helped. Here's my error log:
05-06 22:43:27.912 8714-8714/com.clockwise.epochsoftware.clockwise E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.clockwise.epochsoftware.clockwise, PID: 8714
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/OkHttpClient;
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.getLatestRelease(ApplicationLoader.java:123)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.init(ApplicationLoader.java:94)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.onCreate(ApplicationLoader.java:250)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: okhttp3.OkHttpClient
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.getLatestRelease(ApplicationLoader.java:123)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.init(ApplicationLoader.java:94)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.onCreate(ApplicationLoader.java:250)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/Call$Factory;
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.getLatestRelease(ApplicationLoader.java:123)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.init(ApplicationLoader.java:94)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.onCreate(ApplicationLoader.java:250)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.Call$Factory" on path: DexPathList[[zip file "/data/app/com.clockwise.epochsoftware.clockwise-e7jhExlmJXSclbvr60izkA==/base.apk"],nativeLibraryDirectories=[/data/app/com.clockwise.epochsoftware.clockwise-e7jhExlmJXSclbvr60izkA==/lib/arm64, /data/app/com.clockwise.epochsoftware.clockwise-e7jhExlmJXSclbvr60izkA==/base.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.getLatestRelease(ApplicationLoader.java:123)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.init(ApplicationLoader.java:94)
at com.clockwise.epochsoftware.clockwise.ApplicationLoader.onCreate(ApplicationLoader.java:250)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I see multiple solutions about enabling multidexing, but my app already has multidexing enabled and my manifest also has largeHeap set to true. I've also tried this gradle solution, but it hasn't helped:
dexOptions{
preDexLibraries false
javaMaxHeapSize "4g"
}
Other solutions say to disable instant run, but it's already disabled. Anyone have any suggestions? Please let me know if I need to add anything else to this post.