Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:34:18+00:00 2026-06-07T00:34:18+00:00

I am trying to display data that I am getting from server through json.

  • 0

I am trying to display data that I am getting from server through json. How can I use lazylist to show that data. My current code does not work and I have no Idea why. Please help me. Modification to current code will be helpful.

Here is my code

public class MainActivity extends Activity {

ListView list;
LazyAdapter adapter;
JSONParser jsons = new JSONParser();
UserFunctions userFunctions = new UserFunctions();
JSONArray data = null;
ArrayList<HashMap<String, String>> inboxList;
String[] tS;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    inboxList = new ArrayList<HashMap<String, String>>();

    List<String> t = new ArrayList<String>(); 
    List<String> im = new ArrayList<String>();

    list=(ListView)findViewById(R.id.list);
    adapter=new LazyAdapter(this, tS, mTitles);
    list.setAdapter(adapter);

    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(listener);

    /********************************/

    JSONObject json = userFunctions.homeData();

    Log.e("Data", json.toString());

    // Check your log cat for JSON reponse
    //Log.d("Inbox JSON: ", json.toString());

    try {
        data = json.getJSONArray("data");
        Log.d("inbox array: ", data.toString());
        // looping through All messages
        for (int i = 0; i < data.length(); i++) {
            JSONObject c = data.getJSONObject(i);

            // Storing each json item in variable
            String uid = c.getString("uid");
            String name = c.getString("name");
            String success = c.getString("success");
            String profile_img = c.getString("profile_image");
            //String date = c.getString(TAG_DATE);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put("uid", uid);
            map.put("name", name);
            map.put("success", success);
            map.put("profile_image", profile_img);

            t.add(profile_img);

            // adding HashList to ArrayList
            inboxList.add(map);
        }

        tS = new String[t.size()];
        t.toArray(tS);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    /*******************************/
}

@Override
public void onDestroy()
{
    list.setAdapter(null);
    super.onDestroy();
}

public OnClickListener listener=new OnClickListener(){
    public void onClick(View arg0) {
        adapter.imageLoader.clearCache();
        adapter.notifyDataSetChanged();
    }
};

private String[] mTitles = {
        "title 1", "title 2", "title 3", "title 4", "title 5", "title 6", "title 7", "title 8", "title 9", "title 10",
        "title 11", "title 12", "title 13", "title 14", "title 15", "title 16", "title 17", "title 18", "title 19", "title 20",
        "title 21", "title 22", "title 23", "title 24", "title 25", "title 26", "title 27", "title 28", "title 29", "title 30",
        "title 31", "title 32", "title 33", "title 34", "title 35", "title 36", "title 37", "title 38", "title 39", "title 40",
        "title 41", "title 42", "title 43", "title 44", "title 45", "title 46", "title 47", "title 48", "title 49", "title 50",
        "title 51", "title 52", "title 53", "title 54", "title 55", "title 56", "title 57", "title 58", "title 59", "title 60",
        "title 61", "title 62", "title 63", "title 64", "title 65", "title 66", "title 67", "title 68", "title 69", "title 70",
        "title 71", "title 72", "title 73", "title 74", "title 75", "title 76", "title 77", "title 78", "title 79", "title 80",
        "title 81", "title 82", "title 83", "title 84", "title 85", "title 86", "title 87", "title 88", "title 89", "title 90",
        "title 91", "title 92", "title 93", "title 94", "title 95", "title 96", "title 97", "title 98", "title 99", "title 100",
        "title 101", "title 102", "title 103", "title 104"
};

}

Here is my logcat output

06-30 08:49:25.210: E/AndroidRuntime(31245): FATAL EXCEPTION: main
06-30 08:49:25.210: E/AndroidRuntime(31245): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fedorvlasov.lazylist/com.fedorvlasov.lazylist.MainActivity}: java.lang.NullPointerException
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.os.Looper.loop(Looper.java:130)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.ActivityThread.main(ActivityThread.java:3691)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at java.lang.reflect.Method.invokeNative(Native Method)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at java.lang.reflect.Method.invoke(Method.java:507)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at dalvik.system.NativeStart.main(Native Method)
06-30 08:49:25.210: E/AndroidRuntime(31245): Caused by: java.lang.NullPointerException
06-30 08:49:25.210: E/AndroidRuntime(31245):    at com.fedorvlasov.lazylist.LazyAdapter.getCount(LazyAdapter.java:29)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.widget.ListView.setAdapter(ListView.java:485)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at com.fedorvlasov.lazylist.MainActivity.onCreate(MainActivity.java:41)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-30 08:49:25.210: E/AndroidRuntime(31245):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-30 08:49:25.210: E/AndroidRuntime(31245):    ... 11 more

here is my lazyadapter

public class LazyAdapter extends BaseAdapter {

private Activity activity;
private String[] data;
private String[] titles;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, String[] d, String[] mTitles) {
    activity = a;
    data=d;
    titles = mTitles;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return data.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.item, null);

    TextView text=(TextView)vi.findViewById(R.id.text);
    TextView title=(TextView)vi.findViewById(R.id.textView_title);
    ImageView image=(ImageView)vi.findViewById(R.id.image);
    text.setText("item "+position);
    title.setText("Title: " + titles[position]);
    imageLoader.DisplayImage(data[position], image);
    return vi;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:34:20+00:00Added an answer on June 7, 2026 at 12:34 am

    the problem is in ur adapter setting without having data u have set adapter that y exception occurs
    add this line

    adapter=new LazyAdapter(this, tS, mTitles);
    list.setAdapter(adapter);
    

    after this line

     t.toArray(tS);
    

    and one more thing is in ur activity first check where u have assing data in mTitles i don’t get any code for that in ur activity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display JSON data that I retrieve from an ajax call
I am trying to have a tree display custom data that looks like this.
I'm trying to display data from a database and I want to know what
I'm trying to display some data from a list sharepoint and then using jquery
Hi i am new to jsp & was trying to display some data from
I am trying to display a table containing data from my db in a
I am trying to get column data from sqlLite DB and put that data
I am trying to retrieve data from mysql then display it on android listview.
Hey all i am trying to find examples of getting data back from a
I want to display data that i receive from a data store. One way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.