0

I wanna ask something about android programming..so, I have a value from one class called list_movie, here is the code > I only post a half

public void adapter_listview() {
    ListAdapter adapter = new SimpleAdapter(this, dftr,R.layout.list_item,new String[] { "title", "id"}, new int[] {R.id.tangk, R.id.kodeangk});

    setListAdapter(adapter);
    ListView lv = getListView();


    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
            String kode_ang = ((TextView) view.findViewById(R.id.kodeangk)).getText().toString();
            Intent in = new Intent(getApplicationContext(), studio.class);
            in.putExtra("kode_intent", kode_ang);

            startActivity(in);
        }
    });
}

So, I have a value "kode_intent" that contains id (This id is getting from a field id_movie in a table) . Next, it used in a class named studio..here is the code

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.studio);


    Bundle b = getIntent().getExtras(); 
    kode = b.getString("kode_intent");

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("id_movie", kode.getText().toString())); >> this line "kode" is getting an error

so my question is, how to pass the value of kode = b.getString("kode_intent") into postParameters.add(new BasicNameValuePair("id_movie", kode.getText().toString()));

here is my php code:

$db_host  = "127.0.0.1";

$db_uid  = "root";

$db_pass = "";

$db_name  = "platinum";

$db_con = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');
mysql_select_db($db_name);

$sql = "Select studio_name, date from cinema where id_movie = '".   $_POST["id_movie"]."'";

$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
$output[]=$row;
print(json_encode($output));
mysql_close(); 

Since I'm new in android programming, any help would be so great for me.. thank's

I've tried to change the postParameters.add(new BasicNameValuePair("id_film", kode.getText().toString())); into this one postParameters.add(new BasicNameValuePair("id_movie", kode));

It seems fine..but now I've got another error.here is the code :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.studio);

    Bundle b = getIntent().getExtras(); 
    kode = b.getString("kode_intent");

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("id_movie", kode));

    try
    {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://10.0.2.2/cinemainfo/movie_time.php");
            HttpResponse response = httpclient.execute(httppost,postParameters); 
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.e("Pass 1", "success!");
    }

    catch(Exception e)
    {
        Log.e("Fail 1", e.toString());
        Toast.makeText(getApplicationContext(), "Invalid IP Address",
        Toast.LENGTH_LONG).show();
    }

I've got error on this line HttpResponse response = httpclient.execute(httppost,postParameters); >> execute has an error message : "The method execute(HttpUriRequest, HttpContext) in the type HttpClient is not applicable for the arguments (HttpPost, ArrayList)"

did I do something wrong???

Aprilia
  • 53
  • 2
  • 13
  • The declaration of PostParameters is right, can you post the logCat and add the `executeHttpPost()` function – Coderji Jan 05 '14 at 04:31
  • Actually I'm a little bit confuse about which one of the value that I have to used in this line `"id_film", kode.getText().toString()' , the "kode" is getting an error..here is the message : "The method getText() is undefined for the type String"...so, what should I do? I can't run the program bcz of that error – Aprilia Jan 05 '14 at 04:38
  • just change this `postParameters.add(new BasicNameValuePair("id_movie", kode.getText().toString()));` to this: `postParameters.add(new BasicNameValuePair("id_movie", kode);` no need for getText() because it is already a String. let me know if it worked – Coderji Jan 05 '14 at 04:40
  • oke, I'll give it try and I'll post the result here~ hope it'll gonna be work > – Aprilia Jan 05 '14 at 04:44
  • @Coderji I've edited my question, would you want to help me? thank you – Aprilia Jan 05 '14 at 11:13

1 Answers1

0
postParameters.add(new BasicNameValuePair("id_movie", kode.getText().toString()));

"The method getText() is undefined for the type String"

postParameters.add(new BasicNameValuePair("id_movie", kode);

Once you fixed it you will run into another error, NetworkOnMainThreadException

You got 2 options to fix it:

  1. StrictMode check this answer
  2. AsyncTask

It is recommended to use the second option.

Community
  • 1
  • 1
meda
  • 45,103
  • 14
  • 92
  • 122