Attempt to invoke virtual method ‘…’ on a null object reference

Check intent is null or not before you get data

Intent intent=this.getIntent();
if(intent !=null){
       // do something you want
    }

example

In ClassA:

Intent intent = new Intent(this, ClassB);
String[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);

In ClassB:

  Intent intent = getIntent();
     if(intent !=null){
          String[] myStrings = intent.getStringArrayExtra("strings");
      }

Leave a Comment