Android: Share to Facebook Messenger Error

雨燕双飞 提交于 2019-12-02 03:12:30
adelphus

You need to read your logcat and try and understand what it is telling you.

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

OK...why?

Caused by: java.lang.reflect.InvocationTargetException

This just means it failed to invoke the target method - so pretty much the same as the first message. Still..why?

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

IllegalArgumentException means something is wrong with an argument passed to a method. Where? Find the first location in your code:

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)
 ...

So this tells you that on line 205 in PersonalSettings.java, there is a problem with an argument. And the problem is to do with a null URI scheme when build() is called.

At a guess, I'd say the contentUri parameter could be the problem. This value is being set earlier by Uri contentUri = Uri.parse(location);. Uri.parse(), according to the docs:

Creates a Uri which parses the given encoded URI string.

Parameters: uriString: an RFC 2396-compliant, encoded URI

A little bit of research into URIs (like help from this question) leads us to see that uriString needs to have a scheme like http:// or file:// at the start of the string.

In your case, you are calling Uri.parse with a plain filename without a scheme, resulting in the error presented to you in logcat.

Adding an appropriate scheme or using a helper function from the Uri class should help to fix the problem:

 Uri contentUri = Uri.fromFile(new File(location));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!