gpt4 book ai didi

Android 应用程序不在模拟器上运行,而是在真实设备上运行

转载 作者:行者123 更新时间:2023-11-30 01:21:07 24 4
gpt4 key购买 nike

安卓工作室 2.1, Gradle 2.1.0

我在这里搜索过类似的问题,但没有找到。主要与模拟器有关,但在真实设备上不是很好。

问题是,一旦模拟器准备就绪并启动应用程序,当我点击第一个 Activity 时应用程序突然崩溃。然后,我尝试在真实设备上运行,一切正常。

1st. This issue is not the same as App running on emulator but not on
real device
, it's backward with this one.

2nd. No errors in editor, just a little warning.

3rd. The logcats says; FATAL EXCEPTION: main.

我做了什么;

1) Delete the current emulator only, without the system images.

2) Recreated the emulator, trying to launch the app, again, the app crashed.

3) Delete, re-download all 3 system images;

ARM EABI v7a System Image.

Intel x86 Atom_64 System Image.

Intel x86 Atom System Image.

崩溃报告;

FATAL EXCEPTION: main Process: com.example.akmalzaki.uniklattendanceapp2, PID: 2942 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.akmalzaki.uniklattendanceapp2/com.example.akmalzaki.uniklattendanceapp2.Science}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.NfcAdapter.isEnabled()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.nfc.NfcAdapter.isEnabled()' on a null object reference at com.example.akmalzaki.uniklattendanceapp2.Science.onCreate(Science.java:49) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

最佳答案

您尝试获取模拟器不支持的 NFC。这可能会导致问题,因为世界上仍然存在没有 NFC 硬件的真实设备。如果它对您的应用程序至关重要,您应该包含 list 标记

<uses-feature android:name="android.hardware.nfc" android:required="true" />

这样,不支持 NFC 的设备将无法安装您的应用程序。如果它不是关键的,例如你同时启用了 NFC 和 QR 扫描,你可以将它设置为 false 但你应该非常仔细地检查每个询问 NFCAdapter 的方法,例如:

NfcAdapter.getDefaultAdapter(context) !=null

关于Android 应用程序不在模拟器上运行,而是在真实设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37087185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com