codenameone - Can we code cn1 inside native interface? -
there location manager in cn1 works fine project. need update location value using jobscheduler every few minutes. have done jobscheduler using native interface , need gps code in 1 of method (onstartjob() method here). don't want code location manager(gps) again in native native android. hence used cn1 location provider directly in native interface , giving error. can mix cn1 in native interface smhow?
public class myjobservice extends jobservice { @override public boolean onstartjob(jobparameters jobparameters) { checkgps(); toast.maketext(this, "live track running jobscheduler", toast.length_short).show(); return false; } @override public boolean onstopjob(jobparameters jobparameters) { toast.maketext(this, "live track running jobscheduler stops", toast.length_short).show(); return false; } //using cn1 location manager... public void checkgps() { locationmanager.getlocationmanager().setlocationlistener(new locationlistener() { @override public void locationupdated(location location) { loc = location; latitude = location.getlatitude(); longitude = location.getlongitude(); system.out.println("locationupdated latitudeeee " + latitude); system.out.println("locationupdated longitudeeee " + longitude); } @override public void providerstatechanged(int newstate) { system.out.println("newstate " + newstate); } }); } }
error log:
09-11 10:48:14.980 15455-15455/? e/jobservice: error while executing job: 1 09-11 10:48:14.990 15455-15455/? e/androidruntime: fatal exception: main process: com.capitaleyenepal.nokia, pid: 15455 java.lang.runtimeexception: java.lang.nullpointerexception: attempt invoke virtual method 'com.codename1.location.locationmanager com.codename1.impl.codenameoneimplementation.getlocationmanager()' on null object reference @ android.app.job.jobservice$jobhandler.handlemessage(jobservice.java:130) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:7409) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120) caused by: java.lang.nullpointerexception: attempt invoke virtual method 'com.codename1.location.locationmanager com.codename1.impl.codenameoneimplementation.getlocationmanager()' on null object reference @ com.codename1.ui.display.getlocationmanager(display.java:3091) @ com.codename1.location.locationmanager.getlocationmanager(locationmanager.java:70) @ com.capitaleyenepal.nokia.myjobservice.checkgps(myjobservice.java:56) @ com.capitaleyenepal.nokia.myjobservice.onstartjob(myjobservice.java:30) @ android.app.job.jobservice$jobhandler.handlemessage(jobservice.java:126) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:7409) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1230) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1120)
this happening because codename 1 isn't running. need make sure display
class initialized using code such as:
if(display.isinitialized()) { ... }
if it's not can try calling init
, pass context object, advise against if possible there nuances. suggest looking @ androidimplementation.java
file if choose follow path.
Comments
Post a Comment