Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,

I am trying to build an app which is retrieve data from remote database. i am using wamp server to do the task. Whether local path which is given by me is correct or not. THanks in advance

Here url is not accepted that's why this error occur.the path for php is correct but overall i dont know. so how can i solve this.
this my activity class:

Java
package com.example.remotedatabase;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
    private JSONParser jsonParser;
    //10.0.2.2 is the address used by the Android emulators to refer to the host address
    // change this to the IP of another host if required
    private static String ageURL = "D:/wamp/www/android_remote/android_api.php";
    private static String getAge = "getAge";
    private static String jsonResult = "success";
    String uname;
    String age_res;
    TextView Results;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Invoke the Json Parser
        jsonParser = new JSONParser();
     final EditText Enter = (EditText) findViewById(R.id.Enter);
     Results = (TextView) findViewById(R.id.Results);
     Button GetAge = (Button) findViewById(R.id.GetAge);
    //Get Age Button
    GetAge.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            //Get the contents of the edit text
            uname = Enter.getText().toString();
            //Pass the name to the JSON method and create a JSON object from the return
            JSONObject json = getAge(uname);
            // check the success of the JSON call
            try {
                if (json.getString(jsonResult) != null) {
                    Results.setText("");
                    String res = json.getString(jsonResult);
                    if(Integer.parseInt(res) == 1){
                        //If it's a success create a new JSON object for the user element
                        JSONObject json_user = json.getJSONObject("user");
                        //Set the results text to the age from the above JSON object
                        Results.setText("User Age: " + json_user.getString("age"));
                    }else{
                        //If the user could not be found
                        Results.setText("User could not be found");
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    }
    //The below passes the tag and the user name over to the JSON parser class
    public JSONObject getAge(String name){
        List<namevaluepair> params = new ArrayList<namevaluepair>();
        params.add(new BasicNameValuePair("tag", getAge));
        params.add(new BasicNameValuePair("name", name));
        JSONObject json = jsonParser.getJSONFromUrl(ageURL, params);
        return json;
    }
}</namevaluepair></namevaluepair>
Posted
Updated 11-Oct-13 0:11am
v2
Comments
prabu19 11-Oct-13 7:08am    
when i add the last two line then i get error like "insert } to complete classbody"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900