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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:01:47+00:00 2026-06-01T10:01:47+00:00

I am building an app using listview and lazy adapter based on @fedor post

  • 0

I am building an app using listview and lazy adapter based on @fedor post on this link

here’s my first activity :

public class MenuViewAll extends ListActivity {

// url to make request
private static String url = "http://10.0.2.2/culigui/getdataresto.php";
//public static String TAG_NAME,TAG_ADDRESS;
static final String KEY_ID = "id";
static final String KEY_NAME = "name";
static final String KEY_ADDRESS = "address";
static final String KEY_THUMB = "linkthumb";

ListView list;
LazyAdapter adapter;

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

    // Hashmap for ListView
    ArrayList<HashMap<String, String>> userList = new ArrayList<HashMap<String, String>>();

    // Creating JSON Parser instance
    JSONParser jParser = new JSONParser();

    // getting JSON string from URL
    JSONObject json = jParser.getJSONFromUrl(url);

    try {
        // Getting JSONArray of listresto
        JSONArray  listresto = json.getJSONArray("listresto");

        // looping through All listresto
        for(int i = 0; i < listresto.length(); i++){
            HashMap<String, String> map = new HashMap<String, String>();    
            JSONObject list = listresto.getJSONObject(i);


            // insert String to Local Variable
            map.put(KEY_ID, list.getString("id_resto"));
            map.put(KEY_NAME, list.getString("nama_resto"));
            map.put(KEY_ADDRESS, list.getString("alamat_resto"));
            map.put(KEY_THUMB, list.getString("thumb_img"));
            userList.add(map);


        }
    } catch (JSONException e) {
        e.printStackTrace();
    }


    /**
     * Updating parsed JSON data into ListView
     * */



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

   // ListView yourListView = getListView() 

}

and here’s my lazy adapter class :

public class LazyAdapter extends BaseAdapter  {

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.getApplicationContext());
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return data.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.listitemviewall, null);

    TextView namaresto = (TextView)vi.findViewById(R.id.name); // resto name
    TextView alamatresto = (TextView)vi.findViewById(R.id.address); // resto address
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.defaultthumb); // thumb image

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

    // Setting all values in listview
    namaresto.setText(resto.get(MenuViewAll.KEY_NAME));
    alamatresto.setText(resto.get(MenuViewAll.KEY_ADDRESS));
    imageLoader.DisplayImage(resto.get(MenuViewAll.KEY_THUMB), thumb_image);
    return vi;
}}

and after i run my code, here’s the logcat :

04-05 14:51:32.714: D/dalvikvm(311): GC_EXTERNAL_ALLOC freed 869 objects / 60304 bytes in 76ms
04-05 14:51:46.235: D/dalvikvm(311): GC_EXTERNAL_ALLOC freed 757 objects / 43592 bytes in 362ms
04-05 14:51:46.945: D/AndroidRuntime(311): Shutting down VM
04-05 14:51:46.945: W/dalvikvm(311): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-05 14:51:46.975: E/AndroidRuntime(311): FATAL EXCEPTION: main
04-05 14:51:46.975: E/AndroidRuntime(311): java.lang.RuntimeException: Unable to start activity ComponentInfo{last.project.CuliGUI/last.project.CuliGUI.MenuViewAll}: java.lang.NullPointerException
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.os.Looper.loop(Looper.java:123)
04-05 14:51:46.975: E/AndroidRuntime(311):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-05 14:51:46.975: E/AndroidRuntime(311):  at java.lang.reflect.Method.invokeNative(Native Method)
04-05 14:51:46.975: E/AndroidRuntime(311):  at java.lang.reflect.Method.invoke(Method.java:521)
04-05 14:51:46.975: E/AndroidRuntime(311):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-05 14:51:46.975: E/AndroidRuntime(311):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-05 14:51:46.975: E/AndroidRuntime(311):  at dalvik.system.NativeStart.main(Native Method)
04-05 14:51:46.975: E/AndroidRuntime(311): Caused by: java.lang.NullPointerException
04-05 14:51:46.975: E/AndroidRuntime(311):  at     last.project.CuliGUI.MenuViewAll.onCreate(MenuViewAll.java:102)

my program always force close…
maybe someone can help me…

  • 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-01T10:01:49+00:00Added an answer on June 1, 2026 at 10:01 am

    You should pay attention to this part of the error:

     04-05 14:51:46.975: E/AndroidRuntime(311): Caused by: java.lang.NullPointerException
    04-05 14:51:46.975: E/AndroidRuntime(311):  at     last.project.CuliGUI.MenuViewAll.onCreate(MenuViewAll.java:102)
    

    And especially:

    MenuViewAll.java:102
    

    That means that something in that line (i’m not going to count out the lines 🙂 ) is NULL, but you try to use it. Look for the using of an object that might be NULL

    Example (JUST AN EXAMPLE, becasue i don’t know what line it is).
    Lets say this line:

    JSONObject list = listresto.getJSONObject(i);
    

    goes wrong for some reason. (there is no JSONobject i, listresto is false, I dunno). Then later on this:

            map.put(KEY_ID, list.getString("id_resto"));
    

    will give a nullpointer, as you can’t do getString on a NULL object.

    so:

    • find the line
    • find the object
    • fix the reason why it is NULL, or make sure you handle it beforehand
    • …
    • profit
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an wpf app using MVVM. I have viewModels the employ lazy
I'm building a web app using EF Code First and ASP.NET MVC. I have
So I'm building an App using the Entity Framework on top of SQL Compact
Just getting started building an app using the v6 of the facebook c# sdk
I am building an app using storyboard. I have added a table view to
I'm building a WPF app using pages and the navigation service. One of the
I am building a mobile app using Jquery mobile. It´s a multi-page app all
I'm building a web App using JSF 2.0 and had a jaf-facelets.1.1.10 jar in
I am building a web app using Codeigniter 2.0.3. I need to create base
I'm building an app that allows users to snap pictures using the iPhone camera,

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.