张贴图片的Facebook墙上当空指针异常(机器人) [英] Null Pointer Exception when posting a picture to Facebook wall (android)

查看:121
本文介绍了张贴图片的Facebook墙上当空指针异常(机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的目的是让用户拍照然后上传到他们的Facebook墙上。下面code非常相似,就与此相同的问题等做题给出工作code的许多其他例子,但仍然给我的空指针异常:

 私人无效postOnWall()
    {
        最后弦乐反应=;
    尝试
    {
        捆绑PARAMS =新包();
        params.putString(消息,的getMessage());
        params.putByteArray(图片报,字节);
        mAsyncRunner.request(ME /饲料,则params,POST,新SampleUploadListener()
        空值);
    }
    赶上(例外五)
    {
        e.printStackTrace();
    }
}

我只想得到图片上传工作之前,我可以继续用它添加消息。任何想法?

编辑:
 下面是与AsyncRunner(...)行云的SampleUploadListener():

 公共类SampleUploadListener扩展BaseRequestListener {
    公共无效的onComplete(最后字符串的响应,最终对象的状态){
        尝试{
            //此处流程的响应:(在后台线程执行)
            Log.d(脸谱-示例,回应:+ response.toString());
            JSONObject的JSON = Util.parseJson(响应);
            最终的字符串src = json.getString(SRC);            //然后发布处理结果返回给UI线程
            //如果我们不这样做,将会产生一个运行时异常
            //例如CalledFromWrongThreadException:只有原始
            //线程创建视图层次可以触摸的意见。        }赶上(JSONException E){
            Log.w(脸谱-示例,JSON错误反​​应);
        }赶上(FacebookError E){
            Log.w(脸谱-实施例,实错误:+ e.getMessage());
        }
    }    @覆盖
    公共无效onFacebookError(FacebookError即对象的状态){
        // TODO自动生成方法存根    }
}

LogCat中:

  06-22 13:23:45.136:W / System.err的(20667):显示java.lang.NullPointerException
06-22 13:23:45.136:W / System.err的(20667):在com.uncc.cci.TrashPickup.TrashPickupActivity.postwall(TrashPickupActivity.java:475)
06-22 13:23:45.136:W / System.err的(20667):在com.uncc.cci.TrashPickup.TrashPickupActivity $ 5 $ 1.onClick(TrashPickupActivity.java:230)
06-22 13:23:45.140:W / System.err的(20667):在android.view.View.performClick(View.java:3511)
06-22 13:23:45.140:W / System.err的(20667):在android.view.View $ PerformClick.run(View.java:14105)
06-22 13:23:45.140:W / System.err的(20667):在android.os.Handler.handleCallback(Handler.java:605)
06-22 13:23:45.140:W / System.err的(20667):在android.os.Handler.dispatchMessage(Handler.java:92)
06-22 13:23:45.140:W / System.err的(20667):在android.os.Looper.loop(Looper.java:137)
06-22 13:23:45.140:W / System.err的(20667):在android.app.ActivityThread.main(ActivityThread.java:4424)
06-22 13:23:45.144:W / System.err的(20667):在java.lang.reflect.Method.invokeNative(本机方法)
06-22 13:23:45.144:W / System.err的(20667):在java.lang.reflect.Method.invoke(Method.java:511)
06-22 13:23:45.144:W / System.err的(20667):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
06-22 13:23:45.144:W / System.err的(20667):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-22 13:23:45.148:W / System.err的(20667):在dalvik.system.NativeStart.main(本机方法)


解决方案

当你已经改正了,你这里有什么错误,你会遗憾的是发现它是不可能在这个时候通过上传实际将图像张贴到墙上图像直接字节到Facebook。您可以将照片上传到自己的照片廊,而不是他们的墙上。要发布的照片​​墙则必须已驻留在网上,您需要提供一个链接到它与其他数据一起生活。如果我错了,那么这是因为我正好遇到这一切在几个月前,甚至提交了错误与Facebook,他们被拒绝说,一个很新的发展这不是一个错误,这是我们如何打算的事情是。

如果你确定有把照片在他们自己的相册(如果它是在画廊的唯一照片它看起来几乎完全像一个普通的墙后),这是做它的方式:
的Andr​​oid后图片的Facebook墙上

My app is meant to allow users to take a picture and then upload it to their Facebook wall. The following code is very similar to many other examples of working code given on other SO questions pertaining to this exact same problem, yet still gives me the null pointer exception:

    private void postOnWall()
    {
        final String response = "";
    try
    {
        Bundle params = new Bundle();
        params.putString("message", getMessage());
        params.putByteArray("picture", byteArray);
        mAsyncRunner.request(me/feed, params, "POST", new SampleUploadListener(),
        null);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }       
}

I would simply like to get the image upload working before I can move on to adding the message with it. Any ideas?

EDIT: Here is the SampleUploadListener() that goes with the AsyncRunner(...) line:

public class SampleUploadListener extends BaseRequestListener {
    public void onComplete(final String response, final Object state) {
        try {
            // process the response here: (executed in background thread)
            Log.d("Facebook-Example", "Response: " + response.toString());
            JSONObject json = Util.parseJson(response);
            final String src = json.getString("src");

            // then post the processed result back to the UI thread
            // if we do not do this, an runtime exception will be generated
            // e.g. "CalledFromWrongThreadException: Only the original
            // thread that created a view hierarchy can touch its views."

        } catch (JSONException e) {
            Log.w("Facebook-Example", "JSON Error in response");
        } catch (FacebookError e) {
            Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
        }
    }

    @Override
    public void onFacebookError(FacebookError e, Object state) {
        // TODO Auto-generated method stub

    }
}

LogCat:

06-22 13:23:45.136: W/System.err(20667): java.lang.NullPointerException
06-22 13:23:45.136: W/System.err(20667):    at     com.uncc.cci.TrashPickup.TrashPickupActivity.postwall(TrashPickupActivity.java:475)
06-22 13:23:45.136: W/System.err(20667):    at com.uncc.cci.TrashPickup.TrashPickupActivity$5$1.onClick(TrashPickupActivity.java:230)
06-22 13:23:45.140: W/System.err(20667):    at android.view.View.performClick(View.java:3511)
06-22 13:23:45.140: W/System.err(20667):    at android.view.View$PerformClick.run(View.java:14105)
06-22 13:23:45.140: W/System.err(20667):    at android.os.Handler.handleCallback(Handler.java:605)
06-22 13:23:45.140: W/System.err(20667):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-22 13:23:45.140: W/System.err(20667):    at android.os.Looper.loop(Looper.java:137)
06-22 13:23:45.140: W/System.err(20667):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-22 13:23:45.144: W/System.err(20667):    at java.lang.reflect.Method.invokeNative(Native Method)
06-22 13:23:45.144: W/System.err(20667):    at java.lang.reflect.Method.invoke(Method.java:511)
06-22 13:23:45.144: W/System.err(20667):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-22 13:23:45.144: W/System.err(20667):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-22 13:23:45.148: W/System.err(20667):    at dalvik.system.NativeStart.main(Native Method)

解决方案

When you have corrected whatever bug you have here, you will unfortunately discover that it is not possible at this time to post an image to your wall by uploading the actual image bytes directly to facebook. You can upload a photo to their photos gallery, but not to their wall. To post a photo to the wall it must already reside online and you will need to provide a link to where it lives along with the other data. If I'm mistaken then this is a very new development as I just encountered all this a few months ago and even filed a bug with Facebook which they rejected saying that "it's not a bug, it's how we intended things to be".

If you're ok with putting the photo in their gallery (if it's the only photo IN the gallery it will look almost exactly like a regular wall post) this is the way to do it: Android post picture to Facebook wall

这篇关于张贴图片的Facebook墙上当空指针异常(机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆