检索facebook新闻源时图形对象的奇怪行为

时间:2014-11-25 05:23:56

标签: android facebook-graph-api

我正在开发一个应用程序,我根据用户检索facebook新闻源。我将Nexus 4连接到eclipse运行,应用运行正常。我能够将我得到的值填充到列表中。但当我将apk放入其他Android手机时,应用程序在请求新闻源时崩溃。因为它在我运行时没有崩溃,所以我无法对错误进行归零。可以用来避免这种错误处理机制吗?

我的代码:

Bundle params = new Bundle();
    params.putString("limit", "100");
    new Request(
            userSession,
            "/me/home",
            params, 
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {


                    JSONArray json = null;
                    JSONObject current = null;

                    try
                    {
                        json = (JSONArray) response.getGraphObject().getProperty("data");
                    } 
                    catch (Exception e)
                    {
                        // TODO: handle exception

                    }

                    for(int i=0; i<100; i++){
                        try
                        {

                            current = json.getJSONObject(i);


                            String story="",name="",timeStamp="",statusMessage="",url="", id="", feedImage="";



                            try
                            {
                                feedImage=current.getString("picture").toString();
                            } catch (Exception e)
                            {
                                // TODO: handle exception
                            }

                            try
                            {
                                statusMessage=current.get("message").toString();
                            } catch (Exception e)
                            {
                                // TODO: handle exception
                            }

我得到了我想要的其他值并填充了List。我对Android开发相对较新,这是我使用facebook api的第一个应用程序。任何类型的链接或帮助将不胜感激。感谢。

一旦我从响应中获取json对象时添加了这些步骤而不是try-catch:

if(response==null)
                    {
                        Toast.makeText(WallPosts.this, "response is null", Toast.LENGTH_SHORT).show();
                        Log.d("TS","response is null");
                        populateNewsFeed("");
                    }
                    else if(response.getGraphObject()==null)
                    {
                        Toast.makeText(WallPosts.this, "graph object is null", Toast.LENGTH_SHORT).show();
                        Log.d("TS","graph object is null");
                        populateNewsFeed("");
                    }
                    else if(response.getGraphObject().getProperty("data")==null)
                    {
                        Toast.makeText(WallPosts.this, "property is null", Toast.LENGTH_SHORT).show();
                        Log.d("TS","Property is null");
                        populateNewsFeed("");
                    }
                    else
                    {
                         json = (JSONArray) response.getGraphObject().getProperty("data");
                    }

错误仅在图形对象中抛出。

logcat的:

11-26 16:51:57.751: E/JavaBinder(8705): !!! FAILED BINDER TRANSACTION !!!
11-26 16:52:47.504: E/AndroidRuntime(8705): FATAL EXCEPTION: main
11-26 16:52:47.504: E/AndroidRuntime(8705): Process: com.example.login, PID: 8705
11-26 16:52:47.504: E/AndroidRuntime(8705): java.lang.NullPointerException
11-26 16:52:47.504: E/AndroidRuntime(8705):     at             com.example.login.WallPosts$1.onCompleted(WallPosts.java:151)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at com.facebook.Request$4.run(Request.java:1658)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at     android.os.Handler.handleCallback(Handler.java:733)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at     android.os.Handler.dispatchMessage(Handler.java:95)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at android.os.Looper.loop(Looper.java:136)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at android.app.ActivityThread.main(ActivityThread.java:5001)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at java.lang.reflect.Method.invokeNative(Native Method)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at java.lang.reflect.Method.invoke(Method.java:515)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-26 16:52:47.504: E/AndroidRuntime(8705):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案