如题,最近接替学长的一个项目,使用蓝牙将传感器采集的数据发送到手机, APP 在 4.4 系统上正常运行,我的手机是 5.1 系统,一打开就闪退。安卓小白,之前做的都是嵌入式相关的软硬件开发。 APP 的代码我也看了,感觉逻辑上没有问题。 androidmanifest.xml 配置文件中有这样一段代码: <uses-sdk android:minsdkversion="18" android:targetsdkversion="18"/> 请问怎样才能让 APP 在 5.1 系统上正常运行呢?
1
zhfsxtx 2016-04-18 11:10:46 +08:00
<uses-sdk android:minsdkversion="18" android:targetsdkversion="18"/> 这个配置是可以在 5.1 上运行的, 可能 是你代码没兼容好
|
2
nanoxx 2016-04-18 11:18:39 +08:00 via iPhone
logcat 看日志
|
3
honeycomb 2016-04-18 11:25:20 +08:00 via Android
看 logcat ,一般总能看到崩溃的直接原因
|
4
happy1993 OP 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: FATAL EXCEPTION: main
04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: Process: ti.android.ble.devicemonitor, PID: 15281 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{ti.android.ble.devicemonitor/ti.android.ble.devicemonitor.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setPadding(int, int, int, int)' on a null object reference 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2372) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2434) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:162) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5424) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setPadding(int, int, int, int)' on a null object reference 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at ti.android.ble.devicemonitor.ViewPagerActivity.onCreate(ViewPagerActivity.java:81) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at ti.android.ble.devicemonitor.MainActivity.onCreate(MainActivity.java:118) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6093) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at com.qihoo360.mobilesafe.loader.c.callActivityOnCreate(SourceFile:104) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2434) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:162) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5424) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706) 04-18 11:32:51.664 15281-15281/ti.android.ble.devicemonitor E/AndroidRuntime: at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115) 04-18 11:32:51.664 1209-3751/? W/ActivityManager: Force finishing activity 1 ti.android.ble.devicemonitor/.MainActivity |
5
qqmishi 2016-04-18 12:18:25 +08:00
java.lang.RuntimeException: Unable to start activity ComponentInfo{ti.android.ble.devicemonitor/ti.android.ble.devicemonitor.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setPadding(int, int, int, int)' on a null object reference
错误信息很明显了吧,,, |
6
weics 2016-04-18 12:26:47 +08:00
目测是这个: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setPadding(int, int, int, int)' on a null object reference
|
7
happy1993 OP 恩,我再看看,谢谢楼上的各位
|
8
happy1993 OP // Set up the action bar
final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ImageView view = (ImageView) findViewById(android.R.id.home); //view.setPadding(10, 0, 20, 10); 我把最后一行 setPadding 方法注释掉程序就可以运行了,但是相应的状态栏上的图标就没有了,有没有人知道为什么? |
9
bjzhou1990 2016-04-18 15:04:56 +08:00 1
5.0 以上系统没有 ActionBar 了,使用 ActionBar 的地方用 ToolBar 代替,具体请 Google 相关资料
|
10
happy1993 OP @bjzhou1990 嗯,好的,谢谢,第一次在 V2EX 上发帖,感谢大家的热情帮助
|