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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:59:16+00:00 2026-05-27T16:59:16+00:00

I am trying to write an app that will connect to a database, extract

  • 0

I am trying to write an app that will connect to a database, extract data, and display that data on the phone. I am running into a problem though.

I connect to the database using:

try {           
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://74.208.131.62/Androidtest/testscript.php");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    Log.d("Connection Success","Connected To Database");
} catch(Exception e) {

}

test.php is an sql which will return values: Item_ID(auto_inc_int), OtherTerms(String).

Then, I convert it to a string:

BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";

while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
    is.close();
    result = sb.toString();
}

Then I use this part, which I don’t understand, I just copied it from the internet:

int Item_id;
String Item_name;
String populate = new String();

try {       
    jArray = new JSONArray(result);
    JSONObject json_data = null;
    for(int i = 0; i < jArray.length(); i++) {
        json_data = jArray.getJSONObject(i);
        Item_id = json_data.getInt("id");
        Item_name = json_data.getString("item");
    }
...

However, I get the message “No Item found”. I tried changing the name of the database, but I didn’t get “Error in Connection” in LogCat, rather “No Item found”.

I don’t know if my app is successfully connecting to the database or not. I need to insert the result into a ListView object. What am I doing wrong?

(Also, happy holidays to you all!)

  • 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-05-27T16:59:17+00:00Added an answer on May 27, 2026 at 4:59 pm

    I am working on an app that does exactly what you are trying to do.

    Heres my code:

    this is the main activity. Here your connect to the php file and create an array from the JSON result.

    public class mainActivity extends Activity {
    
    
    
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.menu);
    
        ArrayList<List> menuitems = getItems("android", 1); //Call to function to get results from web, you can put variables to pass here
    
        ListView listView = (ListView) findViewById(R.id.Menu);
        listView.setAdapter(new ListAdapter(this, R.layout.categorymenu, menuitems));
    
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
              ON CLICK ACTIVITY GOES HERE
    
    
    
    
            }
        });
    }
    
    public ArrayList<List> getItems(String searchTerm, int page) {
        String searchUrl = "URL TO YOUR PHP FILE GOES HERE";
    
        ArrayList<List> lists = new ArrayList<List>();
    
        HttpClient client = new  DefaultHttpClient();
        HttpGet get = new HttpGet(searchUrl);
    
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
    
        String responseBody = null;
        try{
            responseBody = client.execute(get, responseHandler);
        }catch(Exception ex) {
            ex.printStackTrace();
        }
    
        JSONObject jsonObject = null;
        JSONParser parser=new JSONParser();
    
        try {
            Object obj = parser.parse(responseBody);
            jsonObject=(JSONObject)obj;
    
        }catch(Exception ex){
            Log.v("TEST","Exception: " + ex.getMessage());
        }
    
        JSONArray arr = null;
    
        try {
            Object j = jsonObject.get("results");
            arr = (JSONArray)j;
        }catch(Exception ex){
            Log.v("TEST","Exception: " + ex.getMessage());
        }
    
        for(Object t : arr) {
            List list = new List(
                    ((JSONObject)t).get("categories_name").toString(),
                    ((JSONObject)t).get("categories_id").toString()
                    );
            lists.add(list);
        }
    
        return lists;
    
    
    }   
    
    /** Classes **/
    
    public class List {
        public String name;
        public String message;
        public Boolean usernameSet = false;
        public Boolean messageSet = false;
    
        public List(String username, String message) {
            this.name = username;
            this.message = message;
        }
    }
    
    }
    

    Then I use the menuListAdapater class to create the list view:

    public class menuListAdapter extends ArrayAdapter<List> {
    private ArrayList<List> lists;
        private Activity activity;
    
    
    public menuListAdapter(Activity a, int textViewResourceId, ArrayList<List> lists) {
        super(a, textViewResourceId, lists);
        this.lists = lists;
        activity = a;
    
    }
    
    public static class ViewHolder{
        public TextView name;
        public TextView message;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;
        if (v == null) {        
            LayoutInflater vi = 
                (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.categorymenu, null);
            holder = new ViewHolder();
            holder.name = (TextView) v.findViewById(R.id.categoryname);
            holder.message = (TextView) v.findViewById(R.id.message);
            v.setTag(holder);
        }
        else
            holder=(ViewHolder)v.getTag();
    
        final List list = lists.get(position);
        if (list != null) {
            holder.name.setText(list.name);
            holder.message.setText(list.message);
        }
    
        return v;
    }
    
    }
    

    I highly recommend that you test the output of your php file in a browsers to make sure your queries and connection to the database work correctly.

    Good Luck!

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

Sidebar

Related Questions

im trying to write an app that will display a list off lines from
I am trying to write a basic app that will read data off a
I'm trying to write a Sinatra app that will run on a shared Passenger
I'm trying to write an Android 2.2 app that will find installed apps that
I'm trying to write a very simple terminal app that will scan for Bluetooth
I need to write an app that that will iterate over our database, and
I'm trying to write a simple app that will do a screen capture of
I'm trying to write a very simple app that will do just one very
I'm trying to write an app that will open an excel spreadsheet find the
I'm trying to write a sql statement that will insert data given a few

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.