我在mainactivity java文件中出错了

时间:2015-10-07 20:45:46

标签: java android apache http

package com.example.darrey;


import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.net.http.HttpResponseCache;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity<HttpPost, NameValuePair> extends Activity {


Button ba;
TextView name,id,des;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    name=(TextView) findViewById(R.id.name);
    id=(TextView) findViewById(R.id.id);
    des=(TextView) findViewById(R.id.des);

    ba =(Button) findViewById(R.id.send);
    ba.setOnClickListener(new View.OnClickListener(){

        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "we are going", Toast.LENGTH_LONG).show();

            Intent me = new Intent(MainActivity.this,Second.class);
            startActivity(me);


        }



    });

}

    public void send(View v){

     new Send().execute();

}



class Send<HttpClient> extends AsyncTask<String, Void,Long > {



protected Long doInBackground(String... urls) { 

String namestr=name.getText().toString();
String idstr=id.getText().toString();
String desstr=des.getText().toString();

HttpClient httpclient = new HttpClient();
HttpPost httppost = new HttpPost("http://example.com/done.php");

try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("name", name));
    nameValuePairs.add(new BasicNameValuePair("id", id));
    nameValuePairs.add(new BasicNameValuePair("des", des));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));



    // Execute HTTP Post Request
    HttpResponseCache response = httpclient.execute(httppost);

} catch (Exception e) {
    // TODO Auto-generated catch block
}
return null;

   }
    protected void onProgressUpdate(Integer... progress) {

     }

     protected void onPostExecute(Long result) {

         }
    }

}

并得到以下错误

结果

Description          Resource        Path       Location        Type
HttpResponse cannot be resolved to a type--MainActivity.java--  /darrey/src/com/example/darrey--line 82 Java Problem
HttpClient cannot be resolved to a type--MainActivity.java--    /darrey/src/com/example/darrey--line 68 Java Problem
DefaultHttpClient cannot be resolved to a type--MainActivity.java-- /darrey/src/com/example/darrey--line 68 Java Problem
Cannot instantiate the type HttpPost--MainActivity.java --/darrey/src/com/example/darrey--line 69--Java Problem
BasicNameValuePair cannot be resolved to a type--MainActivity.java--    /darrey/src/com/example/darrey  --line 74   --Java Problem
BasicNameValuePair cannot be resolved to a type--   MainActivity.java-- /darrey/src/com/example/darrey  --line 75   Java Problem
BasicNameValuePair cannot be resolved to a type--   MainActivity.java-- /darrey/src/com/example/darrey  --line 76   Java Problem
UrlEncodedFormEntity cannot be resolved to a type   --MainActivity.java--   /darrey/src/com/example/darrey  --line 77   Java Problem

但我无法理清问题是什么? }有什么问题吗?

错误显示波纹管结果选项。我也无法导入错误。无法导入HTTP post或clints

1 个答案:

答案 0 :(得分:0)

您没有导入那些导致这些错误的类

如果您使用 eclipse with adt ,您可以通过运行 Ctrl + Shift + O (如果您使用的是Windows或Linux)来执行此操作如果你在Mac上,请执行 Cmd + Shift + O 来组织导入。

如果您使用Android工作室悬停在类上并单击黄色灯泡并导入包...