namevaluepair nicht in einen Typ aufgelöst

Habe ich ein sehr einfaches Programm in android. Es gibt Fehler, die namevaluepair kann nicht aufgelöst werden zu einem Typ.ich bin neu auf android. ich habe Hinzugefügt was auch immer importieren Aussagen, die ich dachte, würde das problem beheben

 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;
}

}

InformationsquelleAutor user3190959 | 2014-01-15
Schreibe einen Kommentar