0

App crashes due to event listener used in the program.

Please tell me what is the correct way to use eventListener.

This is the error I am getting in the logcat:

The errors I can track are the following:

java.lang.NoSuchMethodException: android.os.MessageQueue#enableMonitor()#bestmatch

Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference

-21 19:51:47.919 19135-19135/? I/art: Late-enabling -Xcheck:jni
02-21 19:51:47.975 19135-19135/? D/TidaProvider: TidaProvider()
02-21 19:51:47.984 19135-19135/? W/ReflectionUtils: java.lang.NoSuchMethodException: android.os.MessageQueue#enableMonitor()#bestmatch
        at miui.util.ReflectionUtils.findMethodBestMatch(ReflectionUtils.java:338)
        at miui.util.ReflectionUtils.findMethodBestMatch(ReflectionUtils.java:375)
        at miui.util.ReflectionUtils.callMethod(ReflectionUtils.java:800)
        at miui.util.ReflectionUtils.tryCallMethod(ReflectionUtils.java:818)
        at android.os.BaseLooper.enableMonitor(BaseLooper.java:47)
        at android.os.Looper.prepareMainLooper(Looper.java:111)
        at android.app.ActivityThread.main(ActivityThread.java:5584)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
02-21 19:51:48.076 19135-19135/? W/ResourceType: No package identifier when getting name for resource number 0x00000000
02-21 19:51:48.098 19135-19135/com.example.android.miwok W/System: ClassLoader referenced unknown path: /data/app/com.example.android.miwok-1/lib/arm64
02-21 19:51:48.176 19135-19135/com.example.android.miwok D/AndroidRuntime: Shutting down VM
02-21 19:51:48.179 19135-19135/com.example.android.miwok E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.android.miwok, PID: 19135
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.miwok/com.example.android.miwok.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2396)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2545)
        at android.app.ActivityThread.access$1100(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1396)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5601)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
        at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:68)
        at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:145)
        at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
        at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
        at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29)
        at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:186)
        at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:170)
        at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:502)
        at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:174)
        at com.example.android.miwok.MainActivity.<init>(MainActivity.java:25)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2386)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2545) 
        at android.app.ActivityThread.access$1100(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1396) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:157) 
        at android.app.ActivityThread.main(ActivityThread.java:5601) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)` 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) 
02-21 19:51:49.940 19135-19135/com.example.android.miwok I/Process: Sending signal. PID: 19135 SIG: 9

My class is the following:

   package com.example.android.miwok;
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.TextView;

    public class MainActivity extends AppCompatActivity {
    
        TextView family=(TextView) findViewById(R.id.family);
        TextView colors=(TextView) findViewById(R.id.colors);
        TextView Phrases=(TextView) findViewById(R.id.phrases);
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // Set the content of the activity to use the activity_main.xml layout file
            setContentView(R.layout.activity_main);
    
            TextView numbers=(TextView)findViewById(R.id.numbers);
            if(numbers!=null){
            numbers.setOnClickListener(view -> {
                Intent i=new Intent(MainActivity.this,NumbersActivity.class);
                startActivity(i);
            });
            }
    
        }
        public void openNumbersActivity(View view){
            Intent i=new Intent(this,NumbersActivity.class);
            startActivity(i);
        }
    
    }
Aris
  • 984
  • 8
  • 22
  • https://stackoverflow.com/questions/4688277/java-lang-runtimeexception-unable-to-instantiate-activity-componentinfo https://stackoverflow.com/questions/36666091/attempt-to-invoke-virtual-method-android-view-windowcallback-android-view-wind – Android_id Feb 21 '21 at 15:50

1 Answers1

0

Please post your log with quote next time. And for a good reading, post before code

Anyway, it's preferred the view be initialized inside onCreate() or a method called by it.

You've never called openNumberActivity(), sure your should call it inside setOnClickListener() ?!

You also get the current instance of MainActivity via MainActivity#this, you could type "this" directly

DynoZ
  • 169
  • 1
  • 8