rest - Attempt to invoke virtual method 'void com.newflame.pro.app.AppController.addToRequestQueue(com.android.volley.Request)' on a null object reference -
i trying use volley multipart requester, , i'm getting following error.
java.lang.nullpointerexception: attempt invoke virtual method 'void com.newflame.pro.app.appcontroller.addtorequestqueue(com.android.volley.request)' on null object reference @ com.newflame.pro.networking.multipartrequester.multipart_volley_requester(multipartrequester.java:64) @ com.newflame.pro.networking.multipartrequester.<init>(multipartrequester.java:35) @ com.newflame.pro.flame.loginnew.senddatatoserver(loginnew.java:313) @ com.newflame.pro.flame.loginnew.access$100(loginnew.java:75) @ com.newflame.pro.flame.loginnew$2$1$1.callback(loginnew.java:197) @ com.androidquery.callback.bitmapajaxcallback.checkcb(bitmapajaxcallback.java:502) @ com.androidquery.callback.bitmapajaxcallback.callback(bitmapajaxcallback.java:472) @ com.androidquery.callback.bitmapajaxcallback.callback(bitmapajaxcallback.java:65) @ com.androidquery.callback.abstractajaxcallback.callback(abstractajaxcallback.java:499) @ com.androidquery.callback.abstractajaxcallback.afterwork(abstractajaxcallback.java:1261) @ com.androidquery.callback.abstractajaxcallback.run(abstractajaxcallback.java:986) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
here appcontroler.java
public class appcontroller extends application { public static final string tag = appcontroller.class.getsimplename(); private static double total=0; public static arraylist<menu> menulistglobal = new arraylist<menu>(); private requestqueue mrequestqueue; private imageloader mimageloader; lrubitmapcache mlrubitmapcache; private static appcontroller minstance; public static double gettotal() { return total; } public static void settotal(double total) { appcontroller.total = total; } @override public void oncreate() { super.oncreate(); } public static synchronized appcontroller getinstance() { return minstance; } public requestqueue getrequestqueue() { if (mrequestqueue == null) { mrequestqueue = volley.newrequestqueue(getapplicationcontext()); } return mrequestqueue; } public imageloader getimageloader() { getrequestqueue(); if (mimageloader == null) { getlrubitmapcache(); mimageloader = new imageloader(this.mrequestqueue, mlrubitmapcache); } return this.mimageloader; } public lrubitmapcache getlrubitmapcache() { if (mlrubitmapcache == null) mlrubitmapcache = new lrubitmapcache(); return this.mlrubitmapcache; } public <t> void addtorequestqueue(request<t> req, string tag) { req.settag(textutils.isempty(tag) ? tag : tag); getrequestqueue().add(req); } public <t> void addtorequestqueue(request<t> req) { req.settag(tag); req.setshouldcache(false); getrequestqueue().add(req); } public void cancelpendingrequests(object tag) { if (mrequestqueue != null) { mrequestqueue.cancelall(tag); } } @override protected void attachbasecontext(context base) { super.attachbasecontext(base); } }
here multipartrequester.java
public class multipartrequester { context activity; private asynctaskcompletelistener asynctaskcompletelistener; int service_code; public multipartrequester(context activity, map<string, string> map, int service_code, asynctaskcompletelistener asynctaskcompletelistener) { this.activity = activity; this.service_code = service_code; this.asynctaskcompletelistener = asynctaskcompletelistener; string url = map.get(const.url); map.remove(const.url); multipart_volley_requester(url, map); } void multipart_volley_requester(string url, map<string, string> map) { multipartrequest mr = new multipartrequest(url, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.d("ashutosh", error.tostring()); string msg = "no network connection.please check internet"; //andyutils.showlongtoast(msg,activity); //andyutils.removeprogressdialog(); } }, new response.listener<string>() { @override public void onresponse(string response) { log.d("multipartresponse",response); asynctaskcompletelistener.ontaskcompleted(response.tostring(), service_code); } }, map); mr.setretrypolicy(new defaultretrypolicy(const.timeout, const.max_retry, const.default_backoff_mult)); appcontroller.getinstance().addtorequestqueue(mr); } }
and code, im pinging multipartrequester class
private void senddatatoserver() { log.d("shan","thread1executing"); log.d("shanpic",name); log.d("shanpic",ssocial_unique_id); hashmap<string, string> map = new hashmap<>(); map.put(const.url, constant.loginurl); map.put(const.params.social_unique_id, ssocial_unique_id); map.put(const.params.login_by, constant.facebook); map.put(const.params.username, name); // map.put(const.params.dob, dob); if(semailid!=""){ map.put(const.params.email, semailid); } map.put(const.params.picture, filepath); map.put(const.params.device_type, const.android); if(preferences.getstring(property_reg_id, "")!="") { map.put(const.params.device_token, preferences.getstring(property_reg_id, "")); } new multipartrequester(loginnew.this, map, const.servicecode.register, this); }
you not initializing minstance
variable. initialize minstance
in getinstance
method.
change
public static synchronized appcontroller getinstance() { return minstance; }
to,
public static synchronized appcontroller getinstance() { if(minstance == null){ minstance = new appcontroller(); } return minstance; }
Comments
Post a Comment