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

  • Home
  • SEARCH
  • 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 7551419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:29:22+00:00 2026-05-30T10:29:22+00:00

I’m develping an app that makes queries on reomte databases, using Json and PHP

  • 0

I’m develping an app that makes queries on reomte databases, using Json and PHP over MySQL later will be over posgress becouse is more open.

my problem is that my SimpleAdapter is considered undefined by the eclipse without any quickfix, the strange thing is that before adding the button when I was trying with an imput example everything was working fine. thus, I don’t have any Idea of how to fix this bug.

the code is:

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class DataconectActivity extends ListActivity {
    EditText  searcher;
    Button btmsearch; 
    // adding strings that are going to be the tags of the nodes for the list view in the ListAdapter
    private static String TAG_PRODID = "codigo";
    private static final String TAG_NOMBRE = "nombre";
    private static final String TAG_DESCRIPCION = "descripcion";
    private static final String TAG_COLOR = "color";
    private static final String TAG_PESO =  "peso";
    private static final String TAG_PRECIO = "precio";
    private static final String TAG_DISPONIBILIDAD = "disponibilidad";
    private static final String TAG_INFO = "resultados";
    // remember to change the url to try it with the web server http://trialsols.webege.com/mobil.php after this is important to add at least 10.000 items to the db to ensure the query efficiency
    private static final String url ="http://192.168.1.50/mobilv1.php";
    ArrayList<HashMap<String, String>> jsonResultList = new ArrayList<HashMap<String, String>>();
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);



        searcher = (EditText) findViewById(R.id.searchtxt);
        btmsearch = (Button) findViewById(R.id.searchbtm);

        btmsearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub


                // Hashmap for ListView

                String data = searcher.getText().toString()   ;

                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("precio",data));

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

                // getting JSON string from URL
                JSONArray jArray = jParser.getJSONFromUrl(nameValuePairs, url);


                try {

                    // looping through All JsonData 
                    for(int i = 0; i < jArray.length() ; i++){
                        JSONObject json_data = jArray.getJSONObject(i);
                        String nombre = json_data.getString("nombre");
                        String prodid = json_data.getString("prodid");
                        String descripcion = json_data.getString("descripcion");
                        String color = json_data.getString("color");
                        String peso = json_data.getString("peso");
                        String precio = json_data.getString("precio");
                        String disponibilidad = json_data.getString("disponibilidad");  
                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_PRODID, prodid);
                        map.put(TAG_NOMBRE, nombre);
                        map.put(TAG_DESCRIPCION, descripcion);
                        map.put(TAG_COLOR, color);
                        map.put(TAG_PESO, peso);
                        map.put(TAG_PRECIO, precio);
                        map.put(TAG_DISPONIBILIDAD, disponibilidad);
                        // adding HashList to ArrayList
                        jsonResultList.add(map);

                    }
                }

                catch(JSONException e){
                    Log.e("log_tag", "Error parsing data "+e.toString());
                }                

                //adding the results of the parsed JSON data to a listView using a ListAdapter
                ListAdapter adapter = new SimpleAdapter(this, jsonResultList,
                        R.layout.datalistitems,
                        new String[] { TAG_NOMBRE, TAG_PRECIO, TAG_DISPONIBILIDAD }, new int[] {
                        R.id.dbnombretxt, R.id.dbpreciotxt, R.id.dbdisponibilidadtxt });

                // add in a ListActivity We need to make
                setListAdapter(adapter);    
                // initialize a ListView to display the single item information
                ListView lv = getListView();
                lv.setTextFilterEnabled(true);
                //  generate the action when an item is clicked
                lv.setOnItemClickListener(new OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        // When clicked, create a view with the values
                        // getting values from selected ListItem
                        String name = ((TextView) view.findViewById(R.id.dbnombretxt)).getText().toString();
                        String cost = ((TextView) view.findViewById(R.id.dbpreciotxt)).getText().toString();
                        String stock = ((TextView) view.findViewById(R.id.dbdisponibilidadtxt)).getText().toString();

                        // Starting new intent
                        Intent in = new Intent(getApplicationContext(), SearchResults.class);
                        in.putExtra(TAG_NOMBRE, name);
                        in.putExtra(TAG_PRECIO, cost);
                        in.putExtra(TAG_DISPONIBILIDAD, stock);
                        startActivity(in);
                    }
                });

            }

        });

    }

} 

the error exactly is on:

adapter = new SimpleAdapter(this, jsonResultList,
                        R.layout.datalistitems,
                        new String[] { TAG_NOMBRE, TAG_PRECIO, TAG_DISPONIBILIDAD }, new int[] {
                        R.id.dbnombretxt, R.id.dbpreciotxt, R.id.dbdisponibilidadtxt });
  • 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-30T10:29:24+00:00Added an answer on May 30, 2026 at 10:29 am

    You are constructing your SimpleAdapter instance inside of your View.OnClickListener, so your reference to this points to the OnClickListener, which is not a valid Context. You will want to modify your line of code like so:

    adapter = new SimpleAdapter(DataconectActivity.this, jsonResultList,
                        R.layout.datalistitems,
                        new String[] { TAG_NOMBRE, TAG_PRECIO, TAG_DISPONIBILIDAD }, new int[] {
                        R.id.dbnombretxt, R.id.dbpreciotxt, R.id.dbdisponibilidadtxt });
    

    This will provide the proper reference to your constructor.

    HTH

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.