AsyncTask.execute()

时间:2017-07-13 21:03:03

标签: java android

我一直在研究接收UDP数据包的单个活动应用程序,解析它们的消息,然后更改ImageView,TextView,并根据消息包含的内容播放警报歌曲。我有三个类:MainActivity,ListeningService和AndroidUDP。 MainActivity包含所有GUI实现,AndroidUDP包含枚举,该枚举包含取决于UDP消息包含的20种可能的警报类型以及设置TextView和ImageViews,而ListeningService包含AsyncTask私有类。

我没有写这个,电气工程师做了,我的任务是让它真正起作用。当我尝试通过ListeningService方法调用AndroidUDP.startIt()时,我收到错误

  

java.lang.RuntimeException:无法启动活动ComponentInfo {com.p3_group.v2vapp / com.p3_group.v2vapp.MainActivity}:java.lang.NullPointerException:尝试调用虚方法'void com.p3_group.v2vapp.ListeningService 。null对象引用上的.continueListening()'                                                                          在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)                                                                          在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)                                                                          在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                          在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                          在android.os.Handler.dispatchMessage(Handler.java:102)                                                                          在android.os.Looper.loop(Looper.java:148)                                                                          在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                          at 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)                                                                       引发者:java.lang.NullPointerException:尝试在空对象引用上调用虚方法'void com.p3_group.v2vapp.ListeningService.continueListening()'                                                                          在com.p3_group.v2vapp.MainActivity.onCreate(MainActivity.java:61)

我确信我正在做一些愚蠢的事情,比如试图从错误的线程调用后台更新。我之前从未做过这样的事情所以任何指针都会很棒!

是的,我知道这段代码非常糟糕。我只需要它对我们正在做的事情起作用,而不是完美的

1 个答案:

答案 0 :(得分:1)

您好,您根本没有启动该服务,并且您尝试在“order by case when 2 then 0 when 3 then 1 when 4 then 2 when 1 then 3 end ”中绑定服务但它不会绑定,因此在AndroidUDP中public void doStuff(MainActivity r, IntentFilter filter)为空,但您正在尝试调用下面的方法,但listenService为null,因此它给出了空指针异常。

ListeningService listeningService