Android 应用不是 运行 在模拟器上,而是在真实设备上
Android App NOT Running on Emulator, but on real device
Android Studio 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 硬件的真实设备。如果它对您的应用程序至关重要,您应该包含清单标签
<uses-feature android:name="android.hardware.nfc" android:required="true" />
这样不支持NFC的设备将无法安装您的应用程序。如果它不是关键的,例如你同时启用了 NFC 和 QR 扫描,你可以将其设置为 false
但你应该非常仔细地检查每个询问 NFCAdapter 的方法,例如:
NfcAdapter.getDefaultAdapter(context) !=null
Android Studio 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 硬件的真实设备。如果它对您的应用程序至关重要,您应该包含清单标签
<uses-feature android:name="android.hardware.nfc" android:required="true" />
这样不支持NFC的设备将无法安装您的应用程序。如果它不是关键的,例如你同时启用了 NFC 和 QR 扫描,你可以将其设置为 false
但你应该非常仔细地检查每个询问 NFCAdapter 的方法,例如:
NfcAdapter.getDefaultAdapter(context) !=null