我在执行意图,失败交付结果时遇到错误?

时间:2016-07-29 04:34:53

标签: android

我的代码在这里:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1){
        if (resultCode == Activity.RESULT_OK){
            Uri selectdFileUri = data.getData();
            File file = new File(selectdFileUri.getPath().toString());
            Log.e(TAG, "File: "+file.getName() );
            uploadedFileName = file.getName().toString();
            Log.e(TAG, "FILE NAME: "+uploadedFileName );
            tokens = new StringTokenizer(uploadedFileName,":");
            first = tokens.nextToken();
            file_1 = tokens.nextToken().trim();
            Log.e(TAG, "FILE 1: "+file_1 );
        }
    }
}

我收到的错误:

FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.estrongs.files/storage/sdcard0/WhatsApp/Media/WhatsApp Documents/8763890_133791_1103157248.pdf }} to activity {com.cogent.harikrishna.uploadpdf/com.cogent.harikrishna.uploadpdf.MainActivity}: java.util.NoSuchElementException
 at android.app.ActivityThread.deliverResults(ActivityThread.java:3533)
 at android.app.ActivityThread.handleSendResult(ActivityThread.java:3576)
 at android.app.ActivityThread.access$1100(ActivityThread.java:165)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
 at android.os.Handler.dispatchMessage(Handler.java:107)
 at android.os.Looper.loop(Looper.java:194)
 at android.app.ActivityThread.main(ActivityThread.java:5391)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:525)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
 at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
 at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

我引用我发现的here

  

java.util.StringTokenizer也可以抛出NoSuchElementException   没有更多的标记或元素,你调用nextToken()或   nextElement()方法。

     

使用Stringtokenizer调用时摆脱此异常   在进行调用之前,hasMoreTokens()或hashMoreElements()   nextToken()或nextElement()。

相关问题