[英]Android application works fine in emulator but not in real device?
I'm making a simple Music Player application. 我正在制作一个简单的Music Player应用程序。 It already works perfectly on my emulator but after I install it on my device, it gives "The application
MusicShare
(process com.example.musicshare) has stopped unexpectedly. Please try again" . 它已经可以在我的模拟器上完美运行,但是在将其安装到设备上后,它显示“应用程序
MusicShare
(进程com.example.musicshare)意外停止。请重试” 。
My device is a Galaxy S2 and I got the apk by taking it from the bin folder. 我的设备是Galaxy S2,我从bin文件夹中获取了apk。 I have tried using "Export w/o unsigned key and it cannot be installed instead. Here's the manifest :
我尝试使用“不带未签名密钥的导出文件,而无法安装它。这是清单 :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.musicshare"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AndroidBuildingMusicPlayerActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayListActivity" />
</application>
</manifest>
Any help will be appreciated. 任何帮助将不胜感激。 Thanks!
谢谢!
EDIT: 编辑:
Here's the error log from logcat after I debugged it on the device: 这是我在设备上调试之后从logcat发出的错误日志:
11-05 17:31:17.705: D/dalvikvm(6222): GC_EXTERNAL_ALLOC freed 44K, 53% free 2551K/5379K, external 0K/0K, paused 23ms
11-05 17:31:17.760: D/dalvikvm(6222): GC_EXTERNAL_ALLOC freed 11K, 53% free 2575K/5379K, external 466K/518K, paused 28ms
11-05 17:31:17.790: D/AndroidRuntime(6222): Shutting down VM
11-05 17:31:17.790: W/dalvikvm(6222): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
11-05 17:31:17.795: E/AndroidRuntime(6222): FATAL EXCEPTION: main
11-05 17:31:17.795: E/AndroidRuntime(6222): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.musicshare/com.example.musicshare.AndroidBuildingMusicPlayerActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.os.Looper.loop(Looper.java:123)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.ActivityThread.main(ActivityThread.java:3691)
11-05 17:31:17.795: E/AndroidRuntime(6222): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 17:31:17.795: E/AndroidRuntime(6222): at java.lang.reflect.Method.invoke(Method.java:507)
11-05 17:31:17.795: E/AndroidRuntime(6222): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
11-05 17:31:17.795: E/AndroidRuntime(6222): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
11-05 17:31:17.795: E/AndroidRuntime(6222): at dalvik.system.NativeStart.main(Native Method)
11-05 17:31:17.795: E/AndroidRuntime(6222): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
11-05 17:31:17.795: E/AndroidRuntime(6222): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
11-05 17:31:17.795: E/AndroidRuntime(6222): at java.util.ArrayList.get(ArrayList.java:311)
11-05 17:31:17.795: E/AndroidRuntime(6222): at com.example.musicshare.AndroidBuildingMusicPlayerActivity.playSong(AndroidBuildingMusicPlayerActivity.java:273)
11-05 17:31:17.795: E/AndroidRuntime(6222): at com.example.musicshare.AndroidBuildingMusicPlayerActivity.onCreate(AndroidBuildingMusicPlayerActivity.java:80)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-05 17:31:17.795: E/AndroidRuntime(6222): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
11-05 17:31:17.795: E/AndroidRuntime(6222): ... 11 more
@Pleerock is correct. @Pleerock是正确的。 Apparently it was the problem with the path.
显然这是路径问题。 It should be "/sdcard/media/audio/Music/".
它应该是“ / sdcard / media / audio / Music /”。 Thanks for the help.
谢谢您的帮助。
有时您需要导出整个项目并获取.apk文件并进行安装
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.