我正在尝试为我的大学项目开发一个应用程序,该应用程序跟踪 ADS-B 接收器接收到的飞机,该接收器连接到将数据流式传输到我的应用程序的服务器。
为此,我创建了一个“Aircraft”类来跟踪飞机的位置,可以通过每架飞机的唯一 Mode-S 十六进制代码和发现的每架飞机的 ArrayList 来识别。
这是应该创建飞机对象的代码:
Aircraft aircraftToAdd = new Aircraft(sbsMessageArray[4], //Mode-S hex code
sbsMessageArray[10], //callsign
Integer.parseInt(sbsMessageArray[11]), //altitude
Integer.parseInt(sbsMessageArray[12]), //ground speed
Integer.parseInt(sbsMessageArray[13]), //track
Double.parseDouble(sbsMessageArray[14]), //latitude
Double.parseDouble(sbsMessageArray[15])); //longitude
然后将其添加到 ArrayList 中,如下所示:
aircraftArrayList.add(aircraftToAdd);
但是,这会发生:
02-26 16:09:26.869 14873-14873/com.example.se415017.maynoothskyradar E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.se415017.maynoothskyradar, PID: 14873
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.se415017.maynoothskyradar/com.example.se415017.maynoothskyradar.activities.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:334)
at com.example.se415017.maynoothskyradar.activities.MainActivity.addAircraftToList(MainActivity.java:525)
at com.example.se415017.maynoothskyradar.activities.MainActivity.parseSBSMessage(MainActivity.java:516)
at com.example.se415017.maynoothskyradar.activities.MainActivity.readFromTextFile(MainActivity.java:419)
at com.example.se415017.maynoothskyradar.activities.MainActivity.onCreate(MainActivity.java:147)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
我只是受够了这些错误。我什至尝试通过从中创建一个字符串并将其插入其位置来替换 sbsMessageArray[4],但这并没有帮助。