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 8651465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:04:47+00:00 2026-06-12T14:04:47+00:00

I have a list fragment that gets populated by a custom adapter (lazy Loading)

  • 0

I have a list fragment that gets populated by a custom adapter (lazy Loading) that should display some text and an image.SO i Built a List fragment and a custom adapter to achieve this.Code below but its throwing the errors shown (Log cat)

ListFragment.java

@Override
 public void onActivityCreated(Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);

   new loadListView().execute();


 }
 protected DashBoardActivity fragmentActivity;    
 public void onAttach (DashBoardActivity activity){
     fragmentActivity = (DashBoardActivity) activity;
 }
 public class loadListView extends AsyncTask<Integer, String, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(Integer... args) {
              motellist = new ArrayList<HashMap<String, String>>();
              JSONObject json = JSONfunctions.getJSONfromURL(URL);
              try{

                JSONArray  mot = json.getJSONArray("MOTEL");
                    for(int i=0;i<mot.length();i++){                        
                        HashMap<String, String> map = new HashMap<String, String>();        
                        JSONObject e = mot.getJSONObject(i);
                        map.put(KEY_ID, e.getString(KEY_ID));
                        map.put(KEY_NAME, e.getString(KEY_NAME));
                        map.put(KEY_PRICE, e.getString(KEY_PRICE));
                        map.put(KEY_ROOMS, e.getString(KEY_ROOMS));
                        map.put(KEY_REF, e.getString(KEY_REF));
                        map.put(KEY_PHONE, e.getString(KEY_PHONE));
                        map.put(KEY_IMAGE_URL, e.getString(KEY_IMAGE_URL));
                        motellist.add(map);
                    }       
              }catch(JSONException e)      {
                 Log.e("log_tag", "Error kupitisha data "+e.toString());
              }
                return null;
            }   


        @Override
        protected void onPostExecute(String args) {

              //list = getListView();
              adapter=new LazyAdapter (fragmentActivity, motellist);
              list.setAdapter(adapter);
            /**ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_1, values);
            setListAdapter(adapter);*/

         }
    }

LazyAdapter.java

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 


 public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity);
}


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

public Object getItem(int position) {
    return data.get(position);//nilifix hapa ju am using a custom
}

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.list_row, null);

    TextView NAME = (TextView)vi.findViewById(R.id.name); 
    TextView PRICE = (TextView)vi.findViewById(R.id.board); 
    TextView REF= (TextView)vi.findViewById(R.id.ref); 
    TextView ROOMS = (TextView)vi.findViewById(R.id.units); 
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 

    HashMap<String, String> hash = new HashMap<String, String>();
    hash = data.get(position);

    // Setting all values in listview
    NAME.setText(hash.get(ListFragment.KEY_NAME));
    PRICE.setText("PRICE: "+hash.get(ListFragment.KEY_PRICE));
    REF.setText("REF:"+hash.get(ListFragment.KEY_REF));
    ROOMS.setText("ROOMS: "+hash.get(ListFragment.KEY_ROOMS));
    imageLoader.DisplayImage(hash.get(ListFragment.KEY_IMAGE_URL), thumb_image);
    return vi;
}

LogCat:

0-10 17:42:30.765: E/AndroidRuntime(17557): FATAL EXCEPTION: main
10-10 17:42:30.765: E/AndroidRuntime(17557): java.lang.NullPointerException
10-10 17:42:30.765: E/AndroidRuntime(17557):    at com.symetry.myitprovider.fragment.ListFragment$loadListView.onPostExecute(ListFragment.java:92)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at com.symetry.myitprovider.fragment.ListFragment$loadListView.onPostExecute(ListFragment.java:1)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at android.os.AsyncTask.finish(AsyncTask.java:590)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at android.os.AsyncTask.access$600(AsyncTask.java:149)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:603)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at android.os.Looper.loop(Looper.java:132)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at android.app.ActivityThread.main(ActivityThread.java:4123)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at java.lang.reflect.Method.invokeNative(Native Method)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at java.lang.reflect.Method.invoke(Method.java:491)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
10-10 17:42:30.765: E/AndroidRuntime(17557):    at dalvik.system.NativeStart.main(Native Method)
  • 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-12T14:04:48+00:00Added an answer on June 12, 2026 at 2:04 pm

    Use getActivity() instead of fragmentActivity (the Activity could be null in onAttach). Also make sure list gets initialized at some point.

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

Sidebar

Related Questions

I'm using Android-support-v4 I have a PagerAdapter that displays a list fragment in each
I have an XmlReader that is trying to read text into a list of
Ok so I have a fragment that I want to display two TextViews and
I have a reusable HTML fragment that I use to list items. So to
I have a ListView in a ListFragment that is populated via a database query.
I have a list Fragment (importing the v4 support library, build target is 2.3.3
I have a xsl:variable ($features-list) specified in my XSL which contains a tree fragment
I have a ListFragment whose list should diplay the Albums of the device and
I'm having some trouble setting up my custom header in my list. I'm creating
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script

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.