Amarjit Singh
Amarjit Singh

Reputation: 2154

Android App in kotlin keeps crashing

Android App built with Kotlin keeps crashing. I have a search bar with a Menu Item(Search Icon) in my App. when the user clicks on the Search Icon in the Action bar. A new Activity is opened which has an EditText that gets focused automatically. But when the user clicks the back button in Action bar just after opening the activity. the app gets crashed after finishing Search Activity. this is the function that is executed when the user clicks the back button.

Note The back button here is not from the navigation buttons instead it is from the toolbar (Action bar). Also This crash occurs only in API Level 22 Lollipop, API LEVEL 23 Marshmallow. The App works perfectly in Jellybean, KitKat, Oreo.

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item!!.itemId == android.R.id.home) {
            finish()
        }
        return super.onOptionsItemSelected(item)
    }

Here is the exception that is being displayed in Android Studio.

07-21 16:35:01.299 11145-11145/? E/SamsungIME: getMethod(): java.lang.NoSuchMethodException: changeFullInputMethod []
    invoke(): method is null
07-21 16:35:01.354 14763-14763/com.dealsshutter.www.dealsshutter E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dealsshutter.www.dealsshutter, PID: 14763
    java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference
        at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
        at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:362)
        at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:7402)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
07-21 16:35:01.354 14835-14913/? E/Finsky: [15052] com.google.android.finsky.an.c.a(34): Unable to build selector: /storage/emulated/0/Download/marketenvs.csv: open failed: ENOENT (No such file or directory)

Upvotes: 2

Views: 3788

Answers (2)

Harat
Harat

Reputation: 1356

try deleting .gradle folder in your project directory and then rebuild your project after clearing build cache.

Upvotes: 2

Shubham Naik
Shubham Naik

Reputation: 418

You have a NullPointerException. You are using Kotlin so you are not supposed to get this. Unless you are not using Kotlin null safety properly. Read thiis Kotlin Null Safety

Upvotes: -1

Related Questions