app 在 4.4 系统正常运行在 5.1 上闪退

2016-04-18 10:52:06 +08:00
 happy1993

如题,最近接替学长的一个项目,使用蓝牙将传感器采集的数据发送到手机, APP 在 4.4 系统上正常运行,我的手机是 5.1 系统,一打开就闪退。安卓小白,之前做的都是嵌入式相关的软硬件开发。 APP 的代码我也看了,感觉逻辑上没有问题。 androidmanifest.xml 配置文件中有这样一段代码: <uses-sdk android:minsdkversion="18" android:targetsdkversion="18"/> 请问怎样才能让 APP 在 5.1 系统上正常运行呢?

11162 次点击
所在节点    Android
10 条回复
zhfsxtx
2016-04-18 11:10:46 +08:00
<uses-sdk android:minsdkversion="18" android:targetsdkversion="18"/> 这个配置是可以在 5.1 上运行的, 可能 是你代码没兼容好
nanoxx
2016-04-18 11:18:39 +08:00
logcat 看日志
honeycomb
2016-04-18 11:25:20 +08:00
看 logcat ,一般总能看到崩溃的直接原因
happy1993
2016-04-18 11:34:41 +08:00
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
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

错误信息很明显了吧,,,
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
happy1993
2016-04-18 13:27:39 +08:00
恩,我再看看,谢谢楼上的各位
happy1993
2016-04-18 14:27:14 +08:00
// 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 方法注释掉程序就可以运行了,但是相应的状态栏上的图标就没有了,有没有人知道为什么?
bjzhou1990
2016-04-18 15:04:56 +08:00
5.0 以上系统没有 ActionBar 了,使用 ActionBar 的地方用 ToolBar 代替,具体请 Google 相关资料
happy1993
2016-04-18 19:36:43 +08:00
@bjzhou1990 嗯,好的,谢谢,第一次在 V2EX 上发帖,感谢大家的热情帮助

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/271911

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX