android - nullpointer exception at onServiceConnected() -


edit 2 : realized didn't initialize info new accessibilityserviceinfo , i'm stupid.

i'm trying use accessibilityservice listen , retrieve information of notifications other apps phone (youtube , facebook, sms)

it crashes , logcat report null pointer exception on onserviceconnected

after googling think might due activity has not yet bind service , not launch ?

do need bind accessibility service?

if how do ?

i have these codes in accessibilitylistener class

@override     public void oncreate() {         super.oncreate();         intent intent = new intent(broadcast_action);         log.d("tag","oncreate");     }      @override     public void onserviceconnected() {         info.packagenames = new string[] {"com.whatsapp","com.facebook"};          info.notificationtimeout = 100;          this.setserviceinfo(info);         log.d("tag","onserviceconnected");     }      @override     public void onaccessibilityevent(accessibilityevent event) {         final int eventtype = event.geteventtype();         notificationinfo info = new notificationinfo();          toast.maketext(getapplicationcontext(), "received event", 1000);         log.d("tag","onaccessibility event running");         switch (eventtype) {              case accessibilityevent.type_notification_state_changed:                 info.packagename = (string) event.getpackagename();                 info.eventtime = event.geteventtime();                 info.eventtext = event.gettext().tostring();                 sendevent(info);           }     } 

and these codes in activity

@override      protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      //sets main layout of activity      setcontentview(r.layout.calendar_display);       //initializes calendarview      initializecalendar();      intent = new intent(this,accessibilitylistener.class);  }  @override protected void onstart() {     super.onstart();     // bind service    // intent intent = new intent(this, accessibilitylistener.class);      localbroadcastmanager.getinstance(this).registerreceiver(notificationreceiver,              new intentfilter("add-event"));     startservice(intent); }  @override protected void onresume() {     super.onresume();      if(ismyservicerunning(accessibilitylistener.class))         toast.maketext(this,"service online", 1000).show();     else         toast.maketext(this,"service offline", 1000).show();      registerreceiver(notificationreceiver,new intentfilter(accessibilitylistener.broadcast_action)); } 

edit : requested , added in logcat

> 08-25 07:35:29.265: d/activitythread(24456): handlebindapplication:com.example.utarapp 08-25 07:35:29.265: d/activitythread(24456): settargetheaputilization:0.75 08-25 07:35:29.265: d/activitythread(24456): settargetheapminfree:2097152 08-25 07:35:29.630: d/tag(24456): oncreate 08-25 07:35:29.715: d/libegl(24456): loaded /system/lib/egl/libegl_mali.so 08-25 07:35:29.725: d/libegl(24456): loaded /system/lib/egl/libglesv1_cm_mali.so 08-25 07:35:29.730: d/libegl(24456): loaded /system/lib/egl/libglesv2_mali.so 08-25 07:35:29.730: e/(24456): device driver api match 08-25 07:35:29.730: e/(24456): device driver api version: 23 08-25 07:35:29.730: e/(24456): user space api version: 23  08-25 07:35:29.730: e/(24456): mali: revision=linux-r3p2-01rel3 build_date=fri mar 21 13:52:50 kst 2014  08-25 07:35:29.830: d/openglrenderer(24456): enabling debug mode 0 08-25 07:35:30.150: d/androidruntime(24456): shutting down vm 08-25 07:35:30.150: w/dalvikvm(24456): threadid=1: thread exiting uncaught exception (group=0x4185ace0) 08-25 07:35:30.155: e/androidruntime(24456): fatal exception: main 08-25 07:35:30.155: e/androidruntime(24456): process: com.example.utarapp, pid: 24456 08-25 07:35:30.155: e/androidruntime(24456): java.lang.nullpointerexception 08-25 07:35:30.155: e/androidruntime(24456):    @ com.example.utarapp.accessibilitylistener.onserviceconnected(accessibilitylistener.java:36) 08-25 07:35:30.155: e/androidruntime(24456):    @ android.accessibilityservice.accessibilityservice$1.onserviceconnected(accessibilityservice.java:546) 08-25 07:35:30.155: e/androidruntime(24456):    @ android.accessibilityservice.accessibilityservice$iaccessibilityserviceclientwrapper.executemessage(accessibilityservice.java:659) 08-25 07:35:30.155: e/androidruntime(24456):    @ com.android.internal.os.handlercaller$myhandler.handlemessage(handlercaller.java:40) 08-25 07:35:30.155: e/androidruntime(24456):    @ android.os.handler.dispatchmessage(handler.java:102) 08-25 07:35:30.155: e/androidruntime(24456):    @ android.os.looper.loop(looper.java:136) 08-25 07:35:30.155: e/androidruntime(24456):    @ android.app.activitythread.main(activitythread.java:5146) 08-25 07:35:30.155: e/androidruntime(24456):    @ java.lang.reflect.method.invokenative(native method) 08-25 07:35:30.155: e/androidruntime(24456):    @ java.lang.reflect.method.invoke(method.java:515) 08-25 07:35:30.155: e/androidruntime(24456):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:732) 08-25 07:35:30.155: e/androidruntime(24456):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:566) 08-25 07:35:30.155: e/androidruntime(24456):    @ dalvik.system.nativestart.main(native method) 08-25 07:35:32.080: i/process(24456): sending signal. pid: 24456 sig: 9 08-25 07:35:33.165: d/activitythread(24700): handlebindapplication:com.example.utarapp 08-25 07:35:33.165: d/activitythread(24700): settargetheaputilization:0.75 08-25 07:35:33.165: d/activitythread(24700): settargetheapminfree:2097152 08-25 07:35:33.225: d/tag(24700): oncreate 08-25 07:35:33.235: d/androidruntime(24700): shutting down vm 08-25 07:35:33.235: w/dalvikvm(24700): threadid=1: thread exiting uncaught exception (group=0x4185ace0) 08-25 07:35:33.240: e/androidruntime(24700): fatal exception: main 08-25 07:35:33.240: e/androidruntime(24700): process: com.example.utarapp, pid: 24700 08-25 07:35:33.240: e/androidruntime(24700): java.lang.nullpointerexception 08-25 07:35:33.240: e/androidruntime(24700):    @ com.example.utarapp.accessibilitylistener.onserviceconnected(accessibilitylistener.java:36) 08-25 07:35:33.240: e/androidruntime(24700):    @ android.accessibilityservice.accessibilityservice$1.onserviceconnected(accessibilityservice.java:546) 08-25 07:35:33.240: e/androidruntime(24700):    @ android.accessibilityservice.accessibilityservice$iaccessibilityserviceclientwrapper.executemessage(accessibilityservice.java:659) 08-25 07:35:33.240: e/androidruntime(24700):    @ com.android.internal.os.handlercaller$myhandler.handlemessage(handlercaller.java:40) 08-25 07:35:33.240: e/androidruntime(24700):    @ android.os.handler.dispatchmessage(handler.java:102) 08-25 07:35:33.240: e/androidruntime(24700):    @ android.os.looper.loop(looper.java:136) 08-25 07:35:33.240: e/androidruntime(24700):    @ android.app.activitythread.main(activitythread.java:5146) 08-25 07:35:33.240: e/androidruntime(24700):    @ java.lang.reflect.method.invokenative(native method) 08-25 07:35:33.240: e/androidruntime(24700):    @ java.lang.reflect.method.invoke(method.java:515) 08-25 07:35:33.240: e/androidruntime(24700):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:732) 08-25 07:35:33.240: e/androidruntime(24700):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:566) 08-25 07:35:33.240: e/androidruntime(24700):    @       dalvik.system.nativestart.main(native method)     08-25 07:40:33.305: i/process(24700): sending signal. pid: 24700 sig: 9 

thanks mention hitch.united , realised due me not initializing

accessibilityserviceinfo

i works after info= new accessibilityserviceinfo()

sorry mistake.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -