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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:39:27+00:00 2026-06-09T21:39:27+00:00

Hey i was using the list of friends which gets from the mysql db

  • 0

Hey i was using the list of friends which gets from the mysql db via php. it sometimes takes a while depends on the connection strenght. so i wanted to use a loader till it gets the data. but im getting errors.

please help me.

thk you,

Code

public class Activity_YourFriendsWith_Class extends Activity {

public String PREFS_NAME = "MyPrefsFile";
public String PREFS_USERID = "prefsUserId";

private static final String TAG_Name = "fname";
private static final String TAG_LName = "lname";

String result = "";
public String userId;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_yourfriendswith);

    SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);

    userId = pref.getString(PREFS_USERID, "");

    Button back = (Button) findViewById(R.id.addback);
    back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent();
            intent.setClass(getApplication(), Activity_MyProfile_Class.class);
            startActivity(intent);
            finish();
        }
    });

    Button addfrnds = (Button) findViewById(R.id.addfrnds);
    addfrnds.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent inti = new Intent();
            inti.setClass(Activity_YourFriendsWith_Class.this,
                    Activity_AddFreinds_Class.class);
            startActivity(inti);
        }
    });

    ProgressTask task = new ProgressTask();
    task.execute();

}
private class ProgressTask extends AsyncTask<String, Void, Boolean> {

           private ProgressDialog pd;
        private Activity activity;



    @Override
    protected Boolean doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        InputStream is = null;

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("user_id", userId));
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(
                    "http://hopscriber.com/friendshopscriber.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection " + e.toString());
        }
        // convert response to string
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result = sb.toString();
        } catch (Exception e) {
            Log.e("log_tag", "Error converting result " + e.toString());
        }
        // parse json data
        try {

            ArrayList<HashMap<String, String>> placelist = new ArrayList<HashMap<String, String>>();
            JSONArray jArray = new JSONArray(result);
            if (jArray != null) {
                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject json_data = jArray.getJSONObject(i);
                    HashMap<String, String> map = new HashMap<String, String>();

                    map.put(TAG_Name, json_data.getString("fname"));
                    map.put(TAG_LName, json_data.getString("lname"));

                    placelist.add(map);
                }
            }
            ListView list = (ListView) findViewById(R.id.frndslist);

            ListAdapter adapter = new SimpleAdapter(activity, placelist,
                    R.layout.listrow_yourfriendswith, new String[] { TAG_Name,
                            TAG_LName }, new int[] {
                            R.id.fname, R.id.lname });
            list.setAdapter(adapter);

        } catch (JSONException e1) {
            ListView list = (ListView) findViewById(R.id.frndslist);
            list.setEmptyView(findViewById(R.id.fempty));
        }
        return null;
    }

    }



}

Logcat

08-16 18:38:17.910: E/AndroidRuntime(452): FATAL EXCEPTION: AsyncTask #1
08-16 18:38:17.910: E/AndroidRuntime(452): java.lang.RuntimeException: An error occured while executing doInBackground()
08-16 18:38:17.910: E/AndroidRuntime(452):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.lang.Thread.run(Thread.java:1019)
08-16 18:38:17.910: E/AndroidRuntime(452): Caused by: java.lang.NullPointerException
08-16 18:38:17.910: E/AndroidRuntime(452):  at android.widget.SimpleAdapter.<init>(SimpleAdapter.java:85)
08-16 18:38:17.910: E/AndroidRuntime(452):  at hopscriber.com.Activity_YourFriendsWith_Class$ProgressTask.doInBackground(Activity_YourFriendsWith_Class.java:142)
08-16 18:38:17.910: E/AndroidRuntime(452):  at hopscriber.com.Activity_YourFriendsWith_Class$ProgressTask.doInBackground(Activity_YourFriendsWith_Class.java:1)
08-16 18:38:17.910: E/AndroidRuntime(452):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-16 18:38:17.910: E/AndroidRuntime(452):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-16 18:38:17.910: E/AndroidRuntime(452):  ... 4 more
  • 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-09T21:39:28+00:00Added an answer on June 9, 2026 at 9:39 pm
        private class ProgressTask extends AsyncTask<String, Void, Boolean> {
    
               private Activity activity;
               ......
    
               ListAdapter adapter = new SimpleAdapter(activity, ......);
    
        } 
    

    Variable activity not defined – so you are get NPE

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

Sidebar

Related Questions

Hey guys, I'm having trouble in inserting my values into MySQL using PHP and
Hey I am having some issues while using Nggalley plugin for wordpress the plugin
Hey guys, I'm using Twitter's PHP API, called twitterlibphp , and it works well,
Hey, I have a list of using ul and li: <span class=important>Show/Hide</span> <div id=important
hey guys, I have a standard nav bar with an unordered list and using
Hey, I was trying to delete an item form a list (without using set
Hey I am using a NSURL Connection to receive data. [NSURLConnection sendSynchronousRequest: //create request
Hey all, I have been away from rails for a while and have been
Hey. I am assigned to do Stack using double-linked list and I faced a
Hey all, I am using the Pinboard API for adding a post from my

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.