简体   繁体   English

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

[英]Android App NOT Running on Emulator, but on real device

Android Studio 2.1, Gradle 2.1.0 Android Studio 2.1、Gradle 2.1.0

I've search similar problem here, but nothing found.我在这里搜索了类似的问题,但没有找到。 Mostly related to, the emulator is good but not on real device.主要与模拟器有关,但不是在真实设备上。

The problem is, once the emulator is ready and the app is launched, the app suddenly crashed as I click on first activity.问题是,一旦模拟器准备好并启动应用程序,当我单击第一个活动时,应用程序突然崩溃。 Then, I tried to run on real device and everything works as it should be.然后,我尝试在真实设备上运行,一切正常。

1st.第一。 This issue is not the same as App running on emulator but not on real device , it's backward with this one.此问题与running on emulator but not on real device App 不同running on emulator but not on real device App 不同,这与此running on emulator but not on real device

2nd.第二。 No errors in editor, just a little warning.编辑器中没有错误,只有一点警告。

3rd.第三。 The logcats says; logcats 说; FATAL EXCEPTION: main.致命例外:主要。

What I've done;我所做的;

1) Delete the current emulator only, without the system images. 1) 只删除当前模拟器,不删除系统镜像。

2) Recreated the emulator, trying to launch the app, again, the app crashed. 2)重新创建模拟器,尝试启动应用程序,应用程序再次崩溃。

3) Delete, re-download all 3 system images; 3) 删除,重新下载所有3个系统镜像;

ARM EABI v7a System Image. ARM EABI v7a 系统映像。

Intel x86 Atom_64 System Image.英特尔 x86 Atom_64 系统映像。

Intel x86 Atom System Image. Intel x86 Atom 系统映像。

Crash Report;崩溃报告;

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.m致命异常:主进程:com.example.akmalzaki.uniklattendanceapp2,PID:2942 java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.akmalzaki.uniklattendanceapp2/com.example.akmalzaki.uniklattendanceapp2.Science}:java. lang.NullPointerException:尝试在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 处的 android.app.ActivityThread.handleLaunchActivity( ActivityThread.java:2476) 在 android.app.ActivityThread.-wrap11(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 在 android.os.Handler.dispatchMessage(Handler.java: 102) 在 android.os.Looper.loop(Looper.java:148) 在 android.app.ActivityThread.main(ActivityThread.java:5417) 在 java.lang.reflect.Method.invoke(Native Method) 在 com.android .internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 在 com.android.internal.os.ZygoteInit.m ain(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. ain(ZygoteInit.java:616) 由: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) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 在 android.app.ActivityThread.-wrap11(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 在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) os.ZygoteInit.main(ZygoteInit.java:616)

You trying to get an NFC which emulator does not support.您试图获得模拟器不支持的 NFC。 This may cause problems because there are still real devices in the world that dont have an NFC hardware.这可能会导致问题,因为世界上仍然存在没有 NFC 硬件的真实设备。 If it is critical to your application you should include manifest tag如果它对您的应用程序至关重要,则应包含清单标记

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

This way the devices with no NFC support will not be able to install your application.这样,不支持 NFC 的设备将无法安装您的应用程序。 If it is not critical, for example you have both NFC and QR Scan enabled, you can set this to false but you should very carefully check every method that asks NFCAdapter like this for example:如果它不是关键,例如您同时启用了 NFC 和 QR 扫描,您可以将其设置为false但您应该非常仔细地检查每个像这样询问 NFCAdapter 的方法,例如:

NfcAdapter.getDefaultAdapter(context) !=null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android应用未在模拟器上运行,也未在真实设备上运行 - Android app not running on emulator nor real device Android:构建Android应用程序以检查应用程序是否在模拟器或真实设备上运行 - Android: build android application to check app is running at emulator or real device Android App 在模拟器中运行良好,但无法在真实设备中安装 - Android App running fine in Emulator but can't install in real device 在真实设备与模拟器上运行应用程序 - Running app on real device vs emulator 应用程序在模拟器上运行,但无法在真实设备上运行 - App running on emulator but not working on real device 在模拟器中,我的应用可以正常运行,但不能在真实设备中运行 - In emulator my app running fine but not in real device Android Instrumental Test 在模拟器上运行但不在真实设备上 - Android Instrumental Test running on Emulator but not on real device Android Studio 应用程序可以在模拟器中运行,但不能在真实设备上运行 - Android Studio app works in emulator but not on a real device Android App可在模拟器上运行,但不能在真实设备上运行 - Android App works on emulator, but not on real device Android应用程序可在模拟器上运行,但不能在真实设备上运行,SharePreferences - Android app working on emulator but not real device, SharePreferences
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM