从图库中选择文件后,Phonegap Android应用程序崩溃

时间:2014-02-25 12:06:36

标签: android html5 file-upload cordova

我需要使用基本的 HTML5 输入type =“file”标签来选择和上传文件库,但是当我尝试选择文件(例如小图片)时,应用程序崩溃了显示此消息--->

Unfortunately,the process com.example.app.mobile**(activity package) has stopped

请在下面找到日志

02-25 17:17:21.509: E/AndroidRuntime(1844): FATAL EXCEPTION: main
02-25 17:17:21.509: E/AndroidRuntime(1844): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=5173, result=-1, data=Intent { dat=content://media/external/audio/media/1166 }} to activity {com.example.app.mobile/com.example.app.mobile.HomeActivity}: java.lang.NullPointerException
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3141)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.ActivityThread.access$1100(ActivityThread.java:130)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.os.Looper.loop(Looper.java:137)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.ActivityThread.main(ActivityThread.java:4745)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at java.lang.reflect.Method.invoke(Method.java:511)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at dalvik.system.NativeStart.main(Native Method)
02-25 17:17:21.509: E/AndroidRuntime(1844): Caused by: java.lang.NullPointerException
02-25 17:17:21.509: E/AndroidRuntime(1844):     at org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:829)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.Activity.dispatchActivityResult(Activity.java:5192)
02-25 17:17:21.509: E/AndroidRuntime(1844):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
02-25 17:17:21.509: E/AndroidRuntime(1844):     ... 11 more

1 个答案:

答案 0 :(得分:1)

由于允许在设备上读取用户文件,可能会发生这种情况。 在您的platform / android / AndroidManifest.xml上添加以下行

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />