2

Facebookの友達のリストをプロフィール写真、名前、dobとともに取得するアプリを書いています。

しかし、私の友人の何人かは誕生日の日付を与えていないので、誕生日の代わりにデフォルトでnullを取得していますが、nullの代わりに表示したい:BirthdayNotMentioned

以下の既存のアプリのスクリーンショットを参照してください。

Like:Vikas RanaはFacebookでDOBを提供し、AJay11月はFacebookでDOBを提供していません

      > VikY
        January 1

      > AJamber
        Null

ここで、Nullの代わりに表示したい:誕生日は言及されていません

FriendsList.java:

       public View getView(int position, View convertView, ViewGroup parent) {


        JSONObject jsonObject = null;
        try {
            jsonObject = jsonArray.getJSONObject(position);
        } catch (JSONException e) {

        }

        FriendItem friendItem;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.listfb_friends, null);
            friendItem = new FriendItem();

            convertView.setTag(friendItem);
        } else {
            friendItem = (FriendItem) convertView.getTag();
        }

        friendItem.friendPicture = (ImageView) convertView
                .findViewById(R.id.picture);
        friendItem.friendName = (TextView) convertView
                .findViewById(R.id.name);
        friendItem.friendDob = (TextView) convertView
                .findViewById(R.id.dob);
        friendItem.friendLayout = (RelativeLayout) convertView
                .findViewById(R.id.friend_item);

        try {
            String uid = jsonObject.getString("uid");
            String url = jsonObject.getString("pic_square");
            friendItem.friendPicture.setImageBitmap(picturesGatherer
                    .getPicture(uid, url));
        } catch (JSONException e) {

            friendItem.friendName.setText("");
            friendItem.friendDob.setText("");
        }

        try {
            friendItem.friendName.setText(jsonObject.getString("name"));
            if(!friendItem.friendDob.equals(""))
            {
            friendItem.friendDob.setText(jsonObject.getString("birthday"));
            }
            else 
            {
            friendItem.friendDob.setText("Birthday Not Mentioned");
            }
        } catch (JSONException e) {

            friendItem.friendName.setText("");
            friendItem.friendDob.setText("");
        }

        listofshit.put(position, friendItem);
        return convertView;
    }

そして私がこのようなコードを書いているなら:

 try {
            friendItem.friendName.setText(jsonObject.getString("name"));
            friendItem.friendDob.setText(jsonObject.getString("birthday"));
        } catch (JSONException e) {

            friendItem.friendName.setText("");
            friendItem.friendDob.setText("");
        }
        finally
        {
            friendItem.friendDob.setText("Birthday Not Mentioned");
        }

だから私はすべてのFacebookの友達の誕生日に言及されていない誕生日を取得しています。

4

3 に答える 3

2

これを試してください。

    try{
    if(jsonObject.getString("birthday")!= null && !jsonObject.getString("birthday").equals("")){
          friendItem.friendDob.setText(jsonObject.getString("birthday"));
    }else{
         friendItem.friendDob.setText("Birthday Not Mentioned");
    }
}catch(JSONException e){
    e.printStackTrace();
}
于 2013-02-13T08:50:55.173 に答える
1

あなたがそれをNullPointerException使っtry-catchているところ。

あなたはそれをしたかもしれないと思います。でコードを記述して、textview/edittext (dob を表示するために使用しているものは何でも)にテキスト"Birthday Not Mentioned"catch blockを設定するだけです。


使用するだけです:-

try {
       friendItem.friendName.setText(jsonObject.getString("name"));
       friendItem.friendDob.setText(jsonObject.getString("birthday"));
    } 
catch (Exception e) {    
       friendItem.friendName.setText("Name");  // try it for now.
       friendItem.friendDob.setText("Birthday Not Mentioned"); // Have to be here.
    }
于 2013-02-13T05:32:21.647 に答える
1

このコードで試してみてください:

            try 
        {
            friendItem.friendName.setText(jsonObject.getString("name"));
            friendItem.friendDob.setText(jsonObject.getString("birthday"));

            if(!(jsonObject.getString("birthday").equalsIgnoreCase("null")))
            {
            friendItem.friendDob.setText(jsonObject.getString("birthday"));
            }
            else
            {
            friendItem.friendDob.setText("Birthday Not Mentioned");
            }

        } catch (JSONException e) 
        {
            friendItem.friendName.setText("");
            friendItem.friendDob.setText("");
        }
        listofshit.put(position, friendItem);
        return convertView;
    }
于 2013-02-13T09:01:41.897 に答える