0

Ok What I need to be able to do is the following things with the following json file

"result":"success",
"threads":{
"34203_27542076":{
"pulse_updates_id":34203,
"poster_id":27542076,
"date_posted":"2012-03-09 22:00:22",
"last_updated":"2012-03-09 22:00:22",
"source":"",
"content":"anyone want to hang out it me up \n",
"how_long_ago":"<span class='notranslate'>2<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/27542076_6734834444f582fd06ebbb.png",
"avatar_name":"LordDragonNickFire00",
"is_vip":0,
"has_ap":true,
"is_staff":false,
"is_friend":true,
"deleted":"0",
"comments":[
],
"total_comments":0
},
"105955_38856955":{
"pulse_updates_id":105955,
"poster_id":38856955,
"date_posted":"2012-03-09 21:52:44",
"last_updated":"2012-03-09 21:52:44",
"source":"",
"content":"A real IMVU Droid app now has a release date and is coming soon...\n\nMajor update is the Login it now keeps your session o-o",
"how_long_ago":"<span class='notranslate'>10<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/38856955_8130690014f3f36e3492e7.png",
"avatar_name":"Toyz",
"is_vip":1,
"has_ap":true,
"is_staff":false,
"is_friend":false,
"deleted":"0",
"comments":[
],
"total_comments":0
},
"76541_36258084":{
"pulse_updates_id":76541,
"poster_id":36258084,
"date_posted":"2012-03-09 21:39:57",
"last_updated":"2012-03-09 21:57:47",
"source":"web",
"content":"*sighs*\nNot again..\n*looks down as she turns away & walks 2 disappears*",
"how_long_ago":"<span class='notranslate'>22<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/36258084_6723628384f5a1de019b78.png",
"avatar_name":"Tizanidine",
"is_vip":1,
"has_ap":true,
"is_staff":false,
"is_friend":true,
"deleted":"0",
"comments":{
"158451":{
"pulse_comments_id":158451,
"poster_id":36258084,
"pulse_updates_id":76541,
"parent_poster_id":36258084,
"date_posted":"2012-03-09 21:51:57",
"source":"web",
"content":"Jace: *nod quietly* ikr.. v_v",
"how_long_ago":"<span class='notranslate'>10<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/36258084_6723628384f5a1de019b78.png",
"avatar_name":"Tizanidine",
"is_vip":1,
"has_ap":true,
"is_staff":false,
"is_friend":true,
"deleted":"0"
},
"158452":{
"pulse_comments_id":158452,
"poster_id":62578061,
"pulse_updates_id":76541,
"parent_poster_id":36258084,
"date_posted":"2012-03-09 21:54:22",
"source":"",
"content":"-Hugs-",
"how_long_ago":"<span class='notranslate'>8<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/62578061_9109627814f5aab76a8004.jpg",
"avatar_name":"JaceMashiara",
"is_vip":0,
"has_ap":true,
"is_staff":false,
"is_friend":false,
"deleted":"0"
},
"158453":{
"pulse_comments_id":158453,
"poster_id":36258084,
"pulse_updates_id":76541,
"parent_poster_id":36258084,
"date_posted":"2012-03-09 21:57:47",
"source":"web",
"content":"Jace: *is being hugged as she hugs him back too*",
"how_long_ago":"<span class='notranslate'>4<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/36258084_6723628384f5a1de019b78.png",
"avatar_name":"Tizanidine",
"is_vip":1,
"has_ap":true,
"is_staff":false,
"is_friend":true,
"deleted":"0"
}
},
"total_comments":6
},
"165095_56558482":{
"pulse_updates_id":165095,
"poster_id":56558482,
"date_posted":"2012-03-09 21:19:56",
"last_updated":"2012-03-09 21:54:56",
"source":"",
"content":"Goodnight\u2665",
"how_long_ago":"<span class='notranslate'>42<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/56558482_9974587834f5ac7431f9d5.jpg",
"avatar_name":"KaylaMioran",
"is_vip":0,
"has_ap":true,
"is_staff":false,
"is_friend":true,
"deleted":"0",
"comments":{
"295959":{
"pulse_comments_id":295959,
"poster_id":85811900,
"pulse_updates_id":165095,
"parent_poster_id":56558482,
"date_posted":"2012-03-09 21:54:56",
"source":"",
"content":"nini baby",
"how_long_ago":"<span class='notranslate'>7<\/span> minutes ago",
"avatar_pic_url":"http:\/\/userimages-akm.imvu.com\/catalog\/includes\/modules\/phpbb2\/images\/avatars\/85811900_13049606984f58e4ec4be4a.jpg",
"avatar_name":"RedVelvetLillie",
"is_vip":0,
"has_ap":false,
"is_staff":false,
"is_friend":false,
"deleted":"0"
}
},
"total_comments":1
},

^Sorry for not being able to do the code view

And what i wanna do is able to load the Avatar Name, Content, and Image (Only these 3) into a listview

This cannot use anything but the android SDK

This also is not homework it's a personal project...

This is what my list adpater looks like currently it just crashes on load of the activity

package IMVU.For.Droid;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

public class PulseADP extends BaseAdapter implements ListAdapter {

    private final Activity activity;
    private final JSONArray jsonArray;
    private static LayoutInflater inflater=null;
    public PulseADP(Activity activity, JSONArray jsonArray) {
        assert activity != null;
        assert jsonArray != null;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.jsonArray = jsonArray;
        this.activity = activity;
    }


    public int getCount() {

        return jsonArray.length();
    }

    public JSONObject getItem(int position) {

        return jsonArray.optJSONObject(position);
    }

    public long getItemId(int position) {
        JSONObject jsonObject = getItem(position);

        return jsonObject.optLong("id");
    }
    JSONObject jsonObject = null;
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.pulse_list, null);

        /*try {
            jsonObject = jsonObject.getJSONObject("threads");
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        JSONArray js = jsonObject.names();

        JSONArray js2;
        try {
            js2 = js.getJSONArray(position);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }*/

        JSONArray js = null;

        JSONArray js2 = null;
        try {
            js = jsonArray.getJSONArray(1);
            js2 = js.getJSONArray(position);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        TextView text=(TextView)convertView.findViewById(R.id.textView1);
        TextView s_text=(TextView)convertView.findViewById(R.id.textView2);
        ImageView image=(ImageView)convertView.findViewById(R.id.imageView1);

        try {
            text.setText(js2.getString(8));
            text.setText(js2.getString(5));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return convertView;
    }
}

Logcat

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{IMVU.For.Droid/IMVU.For.Droid.Home}: java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1852)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1873)
    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:4352)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at IMVU.For.Droid.PulseADP.getCount(PulseADP.java:42)
    at android.widget.ListView.setAdapter(ListView.java:455)
    at IMVU.For.Droid.Home.onCreate(Home.java:33)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
    ... 11 more
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
Toyz
  • 1
  • 1
  • Could you provide trace log please.. – Dmytro Danylyk Mar 10 '12 at 08:17
  • Please provide a logcat. And a second tip, use an efficient adapter, that isn't going to be that efficient. Take a look at list14. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html and make use of a viewholder. – David Olsson Mar 10 '12 at 08:51
  • I have added the Logcat like you asked Also i looked over the link that is no were near the answer I need I need help like how to write a new adapter to do what I need it to do, or at least a good tarting place (That actually works correctly) – Toyz Mar 10 '12 at 09:00

2 Answers2

1

It seems like your jsonArray that comes in as parameter to the constructor is null. The assert will not help you, because it will be ignored as mentioned here. I am posting this as an answer, because it will point you to the cause of the problem you are particularly asking for, if you need further help on your problem elaborate on the question (i.e. add the code that calls the constructor).

Community
  • 1
  • 1
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
0

Have you provided the complete JSON file? there seems to be some validating errors. May be the exception is caused by this.