如何尝试发送mi文件?

时间:2019-07-01 22:57:17

标签: java

我尝试发送文件时关闭了应用程序

代码

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 101 && resultCode == RESULT_OK && data != null) {
            Uri uri = data.getData();
            File archivo = new File(getPath(this, uri));
            ContentResolver cr = this.getContentResolver();
            String mime = cr.getType(uri);
            if(archivo.exists()){
                Message newMessage = new Message();
                newMessage.text = mime.equals("application/pdf") ? "0" : (mime.equals("application/msword") ? "1" : "2") + convertFileToByteArray(archivo);
                newMessage.idSender = StaticConfig.UID;
                newMessage.idReceiver = roomId;
                newMessage.timestamp = System.currentTimeMillis();
                FirebaseDatabase.getInstance().getReference().child("message/" + roomId).push().setValue(newMessage);
            }else
                Toast.makeText(this, "Ocurrió un error adjuntando el archivo seleccionado. Por favor intentelo nuevamente.", Toast.LENGTH_LONG).show();
        }
    }

此错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: app.empresa.bechasa, PID: 28634
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=101, result=-1, data=Intent { dat=content://com.google.android.apps.docs.storage/document/acc=1;doc=encoded=Mcm4ov2p7WTW37n6JMfmRgYL3q7ywa/ESDAATySOQDH1paQaD21jLncK flg=0x1 }} to activity {app.empresa.bechasa/app.empresa.bechasa.ui.ChatActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NullPointerException
        at java.io.File.<init>(File.java:282)
        at app.empresa.bechasa.ui.ChatActivity.onActivityResult(ChatActivity.java:311)
        at android.app.Activity.dispatchActivityResult(Activity.java:7276)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312) 
        at android.app.ActivityThread.-wrap19(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
Application terminated.

0 个答案:

没有答案