2015-08-15 86 views
1

我一直在嘗試解決這個錯誤一個星期了,但仍然無法找到問題。 LogIn正在工作,但由於某些原因,Messenger Messenger崩潰。我無法真正瞭解問題所在。基本上我把文字保存到我的設備上,然後我嘗試分享它。該文件保存到設備(我選中),但Messenger不共享。Android:分享到Facebook Messenger錯誤

這裏是我的代碼共享:

public void shareFile(View view) { 
    String sayWhat = "This is what you sound like when you write to me, thanks to the app Messenger Say it! Available now at Google Play"; 
    HashMap hashmap = new HashMap(); 
    hashmap.put("utteranceId", sayWhat); 
    String location = new StringBuilder(Environment.getExternalStorageDirectory().toString()).append("/").append(name).append(".mp3").toString(); 


    speed = ((float)speedS.getProgress()/100F)*2.0F; 
    pitch=((float)pitchS.getProgress()/100F)*2.0F; 
    ttsread.setPitch(pitch); 
    ttsread.setSpeechRate(speed); 
    ttsread.synthesizeToFile(sayWhat, hashmap, location); 

    String mimeType = "audio/mpeg"; 


    Uri contentUri = Uri.parse(location); 
    text.setText(contentUri.toString()); 
    long futuretime = System.currentTimeMillis() + 1000; 
    while (System.currentTimeMillis() < futuretime) { 
     synchronized (this) { 
      try { 
       wait(futuretime - System.currentTimeMillis()); 
      } catch (Exception e) { 
      } 
     } 
    } 
    ShareToMessengerParams params = ShareToMessengerParams.newBuilder(contentUri, "audio/mpeg") 
      .setMetaData("com.facebook.sdk.ApplicationId") 
      .build(); 
    MessengerUtils.shareToMessenger(this, 1, params); 

    //MessengerUtils.finishShareToMessenger(activity,params); 

} 

和我的logcat:

java.lang.IllegalStateException: Could not execute method of the activity 
      at android.view.View$1.onClick(View.java:3969) 
      at android.view.View.performClick(View.java:4637) 
      at android.view.View$PerformClick.run(View.java:19422) 
      at android.os.Handler.handleCallback(Handler.java:733) 
      at android.os.Handler.dispatchMessage(Handler.java:95) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5586) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.reflect.InvocationTargetException 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at android.view.View$1.onClick(View.java:3964) 
            at android.view.View.performClick(View.java:4637) 
            at android.view.View$PerformClick.run(View.java:19422) 
            at android.os.Handler.handleCallback(Handler.java:733) 
            at android.os.Handler.dispatchMessage(Handler.java:95) 
            at android.os.Looper.loop(Looper.java:136) 
            at android.app.ActivityThread.main(ActivityThread.java:5586) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
            at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.IllegalArgumentException: Unsupported URI scheme: null 
      at com.facebook.messenger.ShareToMessengerParams.<init>(ShareToMessengerParams.java:106) 
      at com.facebook.messenger.ShareToMessengerParamsBuilder.build(ShareToMessengerParamsBuilder.java:120) 
      at com.inc.nicky.messengersayit.PersonalSettings.shareFile(PersonalSettings.java:205) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:515) 
            at android.view.View$1.onClick(View.java:3964) 
            at android.view.View.performClick(View.java:4637) 
            at android.view.View$PerformClick.run(View.java:19422) 
            at android.os.Handler.handleCallback(Handler.java:733) 
            at android.os.Handler.dispatchMessage(Handler.java:95) 
            at android.os.Looper.loop(Looper.java:136) 
            at android.app.ActivityThread.main(ActivityThread.java:5586) 
+0

我也嘗試共享的圖像,這已經是我的手機上 - 再次崩潰 – EnderNicky

回答

2

您需要閱讀你的logcat和嘗試,並瞭解了它的告訴你。

java.lang.IllegalStateException: Could not execute method of the activity 

好的......爲什麼?

Caused by: java.lang.reflect.InvocationTargetException 

這只是意味着它無法調用目標方法 - 與第一條消息非常相似。 Still..why?

Caused by: java.lang.IllegalArgumentException: Unsupported URI scheme: null 

IllegalArgumentException表示傳遞給方法的參數有問題。哪裏?在代碼中找到的第一個位置:

at com.facebook.messenger.ShareToMessengerParams.<init>(ShareToMessengerParams.java:106) 
      at com.facebook.messenger.ShareToMessengerParamsBuilder.build(ShareToMessengerParamsBuilder.java:120) 
      at com.inc.nicky.messengersayit.PersonalSettings.shareFile(PersonalSettings.java:205) 
... 

所以這告訴你,在PersonalSettings.java線205,還有與變量的問題。而當調用build()時,問題在於使用空URI方案。

在猜測,我會說contentUri參數可能是問題。該值由Uri contentUri = Uri.parse(location);提前設置。 Uri.parse()according to the docs

創建一個解析給定編碼的URI字符串的Uri。

參數:uriString中:符合RFC 2396-,編碼URI

的一點點研究到的URI(比如從this question幫助)使我們看到,uriString需要有計劃像http://file://在字符串的開頭。

在你的情況下,你打電話Uri.parse與一個普通的文件名沒有一個計劃,導致在logcat中呈現給你的錯誤。

添加合適的方案,或者使用一個輔助函數從Uri類應該有助於解決這個問題:

Uri contentUri = Uri.fromFile(new File(location)); 
+0

感謝的人!你太棒了! – EnderNicky