0

I am using this Kfilter library for adding filters in my code written in JAVA.

I am getting this error java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull while adding the image to the Imageview.

This is my code:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1 && resultCode == Activity.RESULT_OK){
            if (data == null) {
                showMessage("Failed to open picture!");
                return;
            }
            else
                {
                resultUri = data.getData();

                kfilter.setContentPath(resultUri.toString()); //Error occurs here
                kfilter.setFilters(filter);


            }

        }

    }

This is the error:

 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/0/1/content://media/external/images/media/120425/ORIGINAL/NONE/916748167 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F120425/ORIGINAL/NONE/916748167} }} to activity {com.unit.helloworld/com.unit.helloworld.CompetitionPackage.AddNewPhotoAcivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter $this$startsWith
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4596)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4638)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1976)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6912)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
     Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter $this$startsWith
        at kotlin.text.StringsKt__StringsJVMKt.startsWith(Unknown Source:2)
        at kotlin.text.StringsKt__StringsJVMKt.startsWith$default(StringsJVM.kt:332)
        at com.isaacudy.kfilter.KfilterMediaFile.<init>(KfilterMediaFile.kt:32)
        at com.isaacudy.kfilter.KfilterView.setContentPath(KfilterView.kt:98)
        at com.unit.helloworld.CompetitionPackage.AddNewPhotoAcivity.onActivityResult(AddNewPhotoAcivity.java:208)
        at android.app.Activity.dispatchActivityResult(Activity.java:7468)

All I can find is to add ? to the code. But I have written in Java and the library is developed in kotlin. How to solve this?

Michiel Leegwater
  • 1,172
  • 4
  • 11
  • 27
raghhav
  • 167
  • 2
  • 13

1 Answers1

0

After closer inspection of the stack trace you'll notice that the error arises in KfilterMediaFile. The following is the relevant section:

val extension = path.split(".").last()
val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)

when {
    mimeType.startsWith("video") -> processAsVideo() // the error arises here
    mimeType.startsWith("image") -> processAsImage()
    else -> error = MediaError.ERROR_INVALID_FILE_TYPE
}

The mimeType is null if the MimeTypeMap could not map the file extension to a mime type. Therefore I'd recommend that you check that the type of your file is correct. If it is you could ask the library maintainer about the problem, such that this case is handled more gracefully.

Jannik
  • 1,583
  • 1
  • 14
  • 22
  • Is there a way to resolve this in the code itself? Because the library has been dead past year – raghhav Oct 15 '19 at 16:47
  • 1
    One workaround would probably be to do the same things the library does and call the lib function only if your checks succeeded. But that's not really the most elegant solution. Alternatively you could fork the library and just fix it yourself. I don't really know of any other good approached to the problem. – Jannik Oct 15 '19 at 16:50
  • I tried using this https://stackoverflow.com/a/10564727/11428585 . Is this the correct way? Because now its not throwing errors – raghhav Oct 15 '19 at 16:54
  • But the image is not visible in the view! :( – raghhav Oct 15 '19 at 18:16
  • The answer by Jitendra ramoliya looks somewhat similar to the getUriPath function in the library example. But i can't help you with that because I've never used the library. You could try to translate the example code to Java, test if it works and then integrate it in your app – Jannik Oct 15 '19 at 19:03
  • Ok i will try it! – raghhav Oct 15 '19 at 19:17