V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
happy1993
V2EX  ›  Android

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

  •  
  •   happy1993 · 2016-04-18 10:52:06 +08:00 · 10627 次点击
    这是一个创建于 3140 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    错误信息很明显了吧,,,
    weics
        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
    happy1993
        7
    happy1993  
    OP
       2016-04-18 13:27:39 +08:00
    恩,我再看看,谢谢楼上的各位
    happy1993
        8
    happy1993  
    OP
       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
        9
    bjzhou1990  
       2016-04-18 15:04:56 +08:00   ❤️ 1
    5.0 以上系统没有 ActionBar 了,使用 ActionBar 的地方用 ToolBar 代替,具体请 Google 相关资料
    happy1993
        10
    happy1993  
    OP
       2016-04-18 19:36:43 +08:00
    @bjzhou1990 嗯,好的,谢谢,第一次在 V2EX 上发帖,感谢大家的热情帮助
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2779 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:19 · PVG 22:19 · LAX 06:19 · JFK 09:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.