2014-01-15 3 views
2

나는 안드로이드에서 아주 간단한 프로그램을 가지고 있습니다. 그것은 namevaluepair가 type으로 해석 될 수 없다는 에러를 내고 있습니다. 나는 안드로이드를 처음 접했습니다. 내가 지금까지 import 문은 내가 문제namevaluepair가 유형으로 확인되지 않았습니다.

import java.io.IOException; 
import java.io.UnsupportedEncodingException; 
import java.util.List; 

import org.apache.http.HttpResponse; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.entity.UrlEncodedFormEntity; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.message.BasicNameValuePair; 
import java.util.ArrayList; 

import android.os.Bundle; 
import android.app.Activity; 
    import android.util.Log; 
import android.view.Menu; 
import org.apache.http.message.*; 


public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    // Creating HTTP client 
    HttpClient httpClient = new DefaultHttpClient(); 
    // Creating HTTP Post 
    HttpPost httpPost = new HttpPost(
      "http://www.example.com/login"); 

    // Building post parameters 
    // key and value pair 
    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2); 
    nameValuePair.add(new BasicNameValuePair("email", "[email protected]")); 
    nameValuePair.add(new BasicNameValuePair("message", 
      "Hi, trying Android HTTP post!")); 

    // Url Encoding the POST parameters 
    try { 
     httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair)); 
    } catch (UnsupportedEncodingException e) { 
     // writing error to Log 
     e.printStackTrace(); 
    } 

    // Making HTTP Request 
    try { 
     HttpResponse response = httpClient.execute(httpPost); 

     // writing response to log 
     Log.d("Http Response:", response.toString()); 
    } catch (ClientProtocolException e) { 
     // writing exception to log 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // writing exception to log 
     e.printStackTrace(); 

    } 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

}

답변

0

당신은 상단에 가져온 유형은 BasicNameValuePair이다를 해결 것이라고 생각 무엇을 추가했지만 코드 당신은 List<NameValuePair>를 작성했다.

0

BasicNameValuePair를 NameValuePair로 바꾸십시오.

0
- try this method its may help you 




    public void callWebService(ArrayList<String> data1,String refId){ 
       HttpClient httpclient = null; 
     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

    nameValuePairs.add(new BasicNameValuePair("RefNo",refId)); 
            nameValuePairs.add(newBasicNameValuePair("Front_Bumper",data1.get(0))); 
nameValuePairs.add(new BasicNameValuePair("Grills",data1.get(1))); 
       nameValuePairs.add(newBasicNameValuePair("Head_Lamp",data1.get(2))); 


       try{ 
        httpclient = new DefaultHttpClient(); 
        HttpPost httppost = new HttpPost(URL); 
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
        HttpResponse response = httpclient.execute(httppost); 
        String the_string_response = convertResponseToString(response); 
       }catch(Exception e){ 
        System.out.println("0" + e.getMessage()); 
        System.out.println("Error in http connection "+e.toString()); 
       } 
       httpclient.getConnectionManager().shutdown(); 
      } 
관련 문제