空白指针将照片发布到Facebook墙壁时出现异常(android) [英] Null Pointer Exception when posting a picture to Facebook wall (android)

查看:140
本文介绍了空白指针将照片发布到Facebook墙壁时出现异常(android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是为了让用户拍照,然后将其上传到他们的Facebook墙。以下代码非常类似于许多其他关于与这个完全相同的问题的其他SO问题的工作代码示例,但仍然给出了空指针异常:

  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(异常e)
{
e.printStackTrace();
}
}

我只想让图片上传工作我可以继续添加消息。任何想法?



编辑:
这是与AsyncRunner(...)行一起使用的SampleUploadListener():

  public class SampleUploadListener extends BaseRequestListener {
public void onComplete(final String response,final Object state){
try {
/ /处理这里的响应:(在后台线程中执行)
Log.d(Facebook-Example,Response:+ response.toString());
JSONObject json = Util.parseJson(response);
final String src = json.getString(src);

//然后将处理后的结果发回UI线程
//如果我们不这样做,将会生成运行时异常
//例如CalledFromWrongThreadException:只有创建视图层次结构的原始
//线程才能触及其视图。

} 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自动生成的方法存根

}
}

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 ):at 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):at 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.dispatchM essage(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):at java.lang.reflect.Method.invokeNative(Native Method)
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):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)


解决方案

当您更正了您在这里遇到的任何错误时,您将不幸地发现,目前无法通过upl将图像发布到您的墙壁将实际图像字节直接覆盖到Facebook。您可以将照片上传到他们的照片库,但不要挂在墙上。要将照片发布到墙上,它必须已经在线存在,您需要提供与其他数据一起存在的位置的链接。如果我是错误的,那么这是一个非常新的发展,因为我刚刚在几个月前遇到这一切,甚至提交了一个Facebook的错误,他们拒绝说,这不是一个错误,这是我们的目标是什么 / p>

如果您可以将照片放在他们的画廊(如果它是画廊中唯一的照片,它将看起来几乎完全像一个常规的墙贴),这就是做到这一点:$ b​​ $ b Android发布图片到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墙壁时出现异常(android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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