简体   繁体   中英

Android App NOT Running on Emulator, but on real device

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.

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

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

What I've done;

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.

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 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. os.ZygoteInit.main(ZygoteInit.java:616)

You trying to get an NFC which emulator does not support. This may cause problems because there are still real devices in the world that dont have an NFC hardware. 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. 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:

NfcAdapter.getDefaultAdapter(context) !=null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM