wonhaen
wonhaen

Reputation: 1

java- android- custom HttpClient cannot be resolved

i made a simple android application. all of the code seemed right to me because i followed tutorial from some websites but this 1 line error wont change

it says "customhttpclient cannot be resolved", but i have imported "import org.apache.http.client.HttpClient;"

here is the code:

{        
      package com.android.string;

import java.io.BufferedReader;

import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import android.util.Log;
import android.view.View.OnClickListener;


public class MainActivity extends Activity {
EditText kode_parkir, license_plate;
Button simpan;

@Override
public void onCreate(Bundle savedInstanceState)
{   super.onCreate(savedInstanceState);
try
    {
    setContentView(R.layout.activity_main);
    kode_parkir = (EditText)findViewById(R.id.Parkiran);
    license_plate = (EditText)findViewById(R.id.Plate);
    simpan = (Button)findViewById(R.id.btnKirim);
    simpan.setOnClickListener (new OnClickListener() 
            {      
            @Override
            public void onClick(View v) {
                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("kode_parkir", kode_parkir.getText().toString()));
                postParameters.add(new BasicNameValuePair("license_plate", license_plate.getText().toString()));
                String response = null;
                try     {
                    response = CustomHttpClient.executeHttpPost("http://192.168.73.1/android/android.php", postParameters);
                    String res = response.toString();
                    res = res.trim();
                    res = res.replaceAll("\\s", "");
                    if(res.equals("1"))
                        Toast.makeText(MainActivity.this, "Data Tersimpan", Toast.LENGTH_LONG).show();
                    else
                        Toast.makeText(MainActivity.this,  "Data Tersimpan ke Server", Toast.LENGTH_LONG).show();

                        }
                catch (Exception e) {
                    Toast.makeText(MainActivity.this, "Error : "+ e.toString(), Toast.LENGTH_LONG).show();
                                    }
                                        }
            });
    }
    catch (Exception e) {
        Toast.makeText(MainActivity.this, "Error : "+e.getMessage(), Toast.LENGTH_LONG).show();

                        }

    }

}

}       

i am new to eclipse, so any help would be appriciated

Upvotes: 0

Views: 1221

Answers (1)

EJK
EJK

Reputation: 12526

You need to add an import for the CustomHttpClient class.

This line of code

response = CustomHttpClient.executeHttpPost("http://192.168.73.1/android/android.php", postParameters);

references the CustomHttpClient class, yet that class does not have an import statement. In your post, you state that you have include the import for "org.apache.http.client.HttpClient", however that is a different class.

It is not clear to me where the CustomHttpClient comes from. It does not look like an Apache class. In any case, adding the import statement for this class should fix the problem.

Upvotes: 2

Related Questions