java.lang.NullPointerException: parentLoader == null && !nullAllowed - android

I am trying to use ehcache in my android app. It fails on the first line. So this isn't anything to do with a bad cache configuration. I am planning to configure cache programatically so I do not have any config files. All I did was add ehcache as a dependency and try calling the method below. Using ehcache 2.10.2
CacheManager singletonManager = CacheManager.create();
Stacktrace:
W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
W/System.err: SLF4J: Defaulting to no-operation (NOP) logger implementation
W/System.err: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
E/AndroidRuntime: FATAL EXCEPTION: Thread-158
Process: test.app, PID: 7275
java.lang.ExceptionInInitializerError
at net.sf.ehcache.config.Configuration.<init>(Configuration.java:208)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
at test.app.MyCache.setup(MyCache.java:20)
Caused by: java.lang.NullPointerException: parentLoader == null && !nullAllowed
at java.lang.ClassLoader.<init>(ClassLoader.java:210)
at java.lang.ClassLoader.<init>(ClassLoader.java:202)
at net.sf.ehcache.EhcacheDefaultClassLoader.<init>(EhcacheDefaultClassLoader.java:35)
at net.sf.ehcache.EhcacheDefaultClassLoader.<clinit>(EhcacheDefaultClassLoader.java:26)
at net.sf.ehcache.config.Configuration.<init>(Configuration.java:208) 
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152) 
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103) 
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140) 
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892) 
at net.sf.ehcache.CacheManager.create(CacheManager.java:873) 
at test.app.MyCache.setup(MyCache.java:20) 

Try this:
CacheManager singletonManager = CacheManager.getInstance();
Not: create()
EDIT:
You're right. Still the same problem. I tried it
Failed to load class "org.slf4j.impl.StaticLoggerBinder".
This means there was no SLF4J binding.
Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem
Here's the link.
make sure you only add ONE jar
EDIT 2:
if you want to remove the config warning, add ehcache.xml file. Here's an exmaple:
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
Try it out.

Related

Kotlin Multiplatform + Sentry

I want to use Sentry for my Multiplatform Kotlin project.
Sentry for Kotlin Multiplatform
So I was trying to prepare the setup of Sentry with Kotlin Multiplatform.
I was following the guide, made a mavenLocal() build etc.
Now I wanted to add it to the project.
However, when starting my (Android) project, even before starting the onCreate() of the Application I get a crash stating:
Unable to get provider io.sentry.android.core.SentryInitProvider:
java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
So to be clear this happens already when adding api("io.sentry:sentry-kotlin-multiplatform:0.0.1") to the dependencies. Long before the init call.
All I did was:
Configure shared build.gradle.kts and add
val commonMain by getting {
dependencies {
api("io.sentry:sentry-kotlin-multiplatform:0.0.1")
Adding the sample configuration
fun initializeSentry(context: Context) {
Sentry.init(context) { sentryOptions -> setDsnHere... }
}
and in the Android Application:
initializeSentry(this)
Then tried to run it. But I don't even get to the init call.
The configuration should be reached and the initializeSentry(this) block executed. (I can accept if it fails there but I don't even get that far.)
Instead the app fails stating
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xyz, PID: 23056
java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
...
even before anything else.
So the mere adding to the gradle file causes the crash already (even if the other code is commented out).
-------- Full Stack trace-------
java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
at io.sentry.Sentry.initConfigurations(Sentry.java:201)
at io.sentry.Sentry.init(Sentry.java:170)
at io.sentry.Sentry.init(Sentry.java:118)
at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:87)
at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:56)
at io.sentry.android.core.SentryInitProvider.onCreate(SentryInitProvider.java:27)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
at io.sentry.android.core.SentryInitProvider.attachInfo(SentryInitProvider.java:44)
at android.app.ActivityThread.installProvider(ActivityThread.java:7462)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744) 
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7872) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
Turns out the manual had forgotten to mention the auto configuration.
Add this line to your Manifest:
<meta-data android:name="io.sentry.auto-init" android:value="false" />
and proceed with the tutorial.
For Reference:
https://github.com/getsentry/sentry-kotlin-multiplatform/issues/45

TFlite object detector app crashes just before making predictions

I tried several methods to deploy the tflite model on android, flutter, kotlin, etc, but andriod app keeps crashing when I want to make predictions. This was an error I got trying out the object detection codelab:
2022-01-01 15:52:55.965 2971-3034/org.tensorflow.codelabs.objectdetection E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: org.tensorflow.codelabs.objectdetection, PID: 2971
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:938)
at org.tensorflow.lite.task.core.TaskJniUtils.createHandleFromFdAndOptions(TaskJniUtils.java:65)
at org.tensorflow.lite.task.vision.detector.ObjectDetector.createFromFileAndOptions(ObjectDetector.java:147)
at org.tensorflow.codelabs.objectdetection.MainActivity.runObjectDetection(MainActivity.kt:127)
at org.tensorflow.codelabs.objectdetection.MainActivity.access$runObjectDetection(MainActivity.kt:48)
at org.tensorflow.codelabs.objectdetection.MainActivity$setViewAndDetect$1.invokeSuspend(MainActivity.kt:150)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
2022-01-01 15:52:56.014 2971-3034/org.tensorflow.codelabs.objectdetection I/Process: Sending signal. PID: 2971 SIG: 9
This issue was caused by android compressing the tflite model during the build. To solve this issue i had to instruct aapt not to compress the file.
go to build.gradle, at the app level, inside the andriod{} block, add
aaptOptions {
noCompress "model.tflite"
}
please rename model.tflite to your custom name if your tflite model is not named "model.tflite"

Problems getting started with Chirp SDKs for Android

I have downloaded SDK for Android from
https://developers.chirp.io/downloads
After that I added *.aar library as was explain here:
https://developer.android.com/studio/projects/android-library.html#AddDependency
Hurrah. I can build the project.
Now I want to install the test App on the phone. But the application crashes like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 12979
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:2)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
As I understand it, a problem arose with dependencies when packaging * aar
So I added in build.gradle (marked as Module) dependency for kotlin like:
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.2.61'
After that my ERROR has changed.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 13395
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/MediaType;
at io.chirp.b.a.<init>(Unknown Source:24)
at io.chirp.chirpsdk.a.<init>(Unknown Source:36)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:20)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
I have wrong paths to io.chirp internal libraries.
What should I do to resolve dependency related errors?
You have to import the okhttp 3.12.x dependency required by the ChirpSDK.
However, you don't need to explicitly import the dependency if you are using the SDK from the maven repository as this will be already included:
implementation 'io.chirp:chirpsdk:3.10.0'
and add the repository in your parent maven file:
repositories {
maven {
url "https://maven.chirp.io/release"
}
}
Thanks Dinu for your answer!
Maven repository doesn't work in my case (proxy issues or something else but this is the topic of another discussion).
The problem with using offline ChirpSDK was solved by adding two dependencies:
implementation 'com.squareup.okhttp3:okhttp:3.12.6'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'

No implementation found for com.djinnius.HelloWorld$CppProxy

I'm working on a React Native project that uses djinni to use cross platform native C++.
I already looked at this question, but it seems a different problem.
The project build successfully but fails almost immediately on run.
adb logcat shows the following exception:
No implementation found for com.djinnius.HelloWorld$CppProxy com.djinnius.HelloWorld.create(com.rushingvise.reactcpp.ReactBridge) (tried Java_com_djinnius_HelloWorld_create and Java_com_djinnius_HelloWorld_create__Lcom_rushingvise_reactcpp_ReactBridge_2)
I'm trying to understand what tried means in the message above. Is this because the corresponding native code is missing from the apk ? Or maybe another cause ?
Full logcat is following:
04-19 19:44:51.042 2354-2700/com.djinnius E/art: No implementation found for com.djinnius.HelloWorld$CppProxy com.djinnius.HelloWorld.create(com.rushingvise.reactcpp.ReactBridge) (tried Java_com_djinnius_HelloWorld_create and Java_com_djinnius_HelloWorld_create__Lcom_rushingvise_reactcpp_ReactBridge_2)
04-19 19:44:51.045 2354-2354/com.djinnius W/unknown:React: Caught exception after cancelling react context init
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.facebook.react.ReactInstanceManager$Result.get()' on a null object reference
at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.onCancelled(ReactInstanceManager.java:247)
at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.onCancelled(ReactInstanceManager.java:197)
at android.os.AsyncTask.finish(AsyncTask.java:665)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6339)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
04-19 19:44:51.053 2354-2700/com.djinnius E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: com.djinnius, PID: 2354
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:325)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.UnsatisfiedLinkError: No implementation found for com.djinnius.HelloWorld$CppProxy com.djinnius.HelloWorld.create(com.rushingvise.reactcpp.ReactBridge) (tried Java_com_djinnius_HelloWorld_create and Java_com_djinnius_HelloWorld_create__Lcom_rushingvise_reactcpp_ReactBridge_2)
at com.djinnius.HelloWorld.create(Native Method)
at com.djinnius.HelloWorld.<init>(HelloWorld.java:27)
at com.djinnius.HelloWorldPackage.createNativeModules(HelloWorldPackage.java:18)
at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:88)
at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:950)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:891)
at com.facebook.react.ReactInstanceManager.access$600(ReactInstanceManager.java:104)
at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.doInBackground(ReactInstanceManager.java:218)
at com.facebook.react.ReactInstanceManager$ReactContextInitAsyncTask.doInBackground(ReactInstanceManager.java:197)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
at java.lang.Thread.run(Thread.java:761) 
Any help appreciated.
Found the problem.
It was indeed a missing System.LoadLibrary() Call in the Java Class extending ReactPackage.
This is working now with this class initializer
public class HelloWorldPackage implements ReactPackage {
static {
System.loadLibrary("native-lib");
}

FATAL EXCEPTION: GoogleApiHandler

In my project i'm using the monetization service(Vungle/AppLovin).
When I'm trying to load an ad, i get this exception
E/AndroidRuntime: FATAL EXCEPTION: GoogleApiHandler
Process: kz.ikar, PID: 3673
java.lang.NoSuchMethodError: No virtual method setChannelId(Ljava/lang/String;)Landroid/support/v4/app/NotificationCompat$Builder; in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/kz.ikar-2oCl4DY4J8w7wP-jirbYvA==/split_lib_dependencies_apk.apk)
at com.google.android.gms.common.GoogleApiAvailability.zza(Unknown Source:225)
at com.google.android.gms.common.GoogleApiAvailability.zza(Unknown Source:15)
at com.google.android.gms.common.api.internal.zzbm.zzc(Unknown Source:4)
at com.google.android.gms.common.api.internal.zzbo.onConnectionFailed(Unknown Source:104)
at com.google.android.gms.common.api.internal.zzbo.connect(Unknown Source:83)
at com.google.android.gms.common.api.internal.zzbo.zza(Unknown Source:47)
at com.google.android.gms.common.api.internal.zzbm.handleMessage(Unknown Source:283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
In my project I have two fragments in one activity. The user gets an ad in the second one. If I load an ad from the activity, it works well. What can be the cause of this issue?
By the way both ad networks(Vungle and AppLovin) return this exception
I had the same problem and I fixed it downgrading to firebase Google Play services 11.6.0
One reason you could be getting this error is if your buildToolsVersion in your app-level Gradle is less than 26. Either that or your v4 support is less than 26.0.0 seeing as NotificationCompat.Builder was added in API 26.

Categories

Resources