简体   繁体   中英

Facebook sharing from my app crashes on Motorola Droid?

I have developed an app that allows to post data on the facebook wall using facebook sdk.I have tested on a few other phones like LG optimus but when the app runs on the motorola droid it crashes at times.

When i click on the share facebook button in my context menu the app crashes.

I have googled and found out this much

http://groups.google.com/group/android-developers/browse_thread/thread/92d6f063682d2ca4/735acce1300115d7?show_docid=735acce1300115d7&pli=1 .

There is a problem with Droid phones when using web kit.

The same issue was reported on facebook sdk https://github.com/facebook/facebook-android-sdk/issues/82?authenticity_token=a321076df454835ad9c481d6fa73a3ea8cad1ceb

Again it is mostly said that the exception has occurred during the use of motorola droid.

Here is the stack Trace:

java.lang.NullPointerException
    at android.webkit.WebView.onWindowFocusChanged(WebView.java:4177)
    at android.view.View.dispatchWindowFocusChanged(View.java:3788)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:658)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:662)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1921)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4627)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    at dalvik.system.NativeStart.main(Native Method)

Does someone have a solution or workaround to this?

Edit:This seems to be happening on HTC Incredible also.

There is a work around for this which explicitly mentions the Motorola Droid you can find the original posting at:

Workaround for Null Pointer Excpetion in WebView.onWindowFocusChanged

Create a custom webclass:

CustomWebView.java

public class CustomWebView extends WebView {

    public CustomWebView(Context context) {
        super(context);
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        try{
            super.onWindowFocusChanged(hasWindowFocus);
        }catch(NullPointerException e){
        // Catch null pointer exception
        }
    }
}

Now open up the FbDialog.java provided by facebook and modify the line that creates the webview to use the the CustomWebView subclass as follows

WebView view = new CustomWebView(getContext());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM