-2

im developing plugin for cordova android. it open up a custom activity and return sets of data back to the plugin.

all things are running well on the activity. but when the activity finished, it crashed and give me this error:

Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success(java.lang.String)' on a null object reference
E/AndroidRuntime( 2697):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3539)
E/AndroidRuntime( 2697):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3582)
E/AndroidRuntime( 2697):    at android.app.ActivityThread.access$1300(ActivityThread.java:144)
E/AndroidRuntime( 2697):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
E/AndroidRuntime( 2697):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 2697):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 2697):    at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 2697):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 2697):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 2697):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 2697):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime( 2697): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success(java.lang.String)' on a null object reference
E/AndroidRuntime( 2697):    at com.faiz.faizOk.onActivityResult(faizOk.java:147)
E/AndroidRuntime( 2697):    at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:151)
E/AndroidRuntime( 2697):    at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:348)
E/AndroidRuntime( 2697):    at android.app.Activity.dispatchActivityResult(Activity.java:6139)
E/AndroidRuntime( 2697):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3535)
E/AndroidRuntime( 2697):    
... 10 more

this is my android onActivityResult method

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.out.println("finished native activity proceess...");

    String message = " :finished activity from native: ";
    callbackContext.success(message);
}
faiz
  • 123
  • 5
  • 16
  • May be _callbackContext_ null –  Mar 22 '16 at 05:15
  • i tried using `this.callbackContext.success(message)` wasnt work too. same error – faiz Mar 22 '16 at 05:15
  • Whats _callbackContext_ stands for ? –  Mar 22 '16 at 05:16
  • it is form the `execute` of the cordova plugin. `public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException` – faiz Mar 22 '16 at 05:18
  • print the requestCode and data , you will come to know anyvalue is there or not – Amit Ranjan Mar 22 '16 at 05:18
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – OneCricketeer Mar 22 '16 at 05:20
  • i had gone there. wasnt understand it with my issues. – faiz Mar 22 '16 at 05:22
  • You have a NullPointerException. The logs point you straight to the file and that line number and the method being referenced. You have an uninitialized variable. You couldn't understand that? – OneCricketeer Mar 22 '16 at 05:24
  • no i could not understand it. at least tell me how to initialize it. `public void onActivityResult(int requestCode, int resultCode, Intent data, callbackContext callbackContext)` gives error too – faiz Mar 22 '16 at 05:29

2 Answers2

1

You have to initialise callback context .may be you have declared it but haven't initialised as in : 1. Callbackcontext myvar; Myvar.mymethod

This will throw a null pointer because callbackcontext is declared but not initialized. 2. To fix the above you have to initialize.

Callbackcontext myvar =new callbackcontext;; Myvar.mymethod

VarunJoshi129
  • 4,802
  • 1
  • 12
  • 10
0

You haven't initialized the variable callbackContext. On your onCreate() method, you should initialize it, e.g. callbackContext = new CallbackContext() being CallbackContextthe class that corresponds to the type of callbackContext.

rafaelc
  • 57,686
  • 15
  • 58
  • 82
  • so meaning i had to to this: `@override public void onCreate(){ callbackContext = new CallbackContext(); }` im not sure if i understand well on this. can someone point me the basic and fundamental concept to it? im new in this. sorry for the noob question – faiz Mar 22 '16 at 05:25