Java Android Httppost运行时异常,带有edittext中的字符串-使用静态字符串成功

Java Android Httppost运行时异常,带有edittext中的字符串-使用静态字符串成功,java,android,string,android-asynctask,http-post,Java,Android,String,Android Asynctask,Http Post,我正在用HTTP向我的php服务器脚本运行POST 当我尝试使用静态字符串时,我确实成功了,但是我需要检索用户正在输入的数据 尝试从用户输入检索数据时 索尼手机: 运行时异常 在eclipse中: Fatal Exception: AsycnTask #1 - java.lang.RunTimeException : An error occured while executing doInBackground() at android.os.AsynkTask$3.FutureTask.fin

我正在用HTTP向我的php服务器脚本运行POST

当我尝试使用静态字符串时,我确实成功了,但是我需要检索用户正在输入的数据

尝试从用户输入检索数据时

索尼手机: 运行时异常

在eclipse中:

Fatal Exception: AsycnTask #1 - java.lang.RunTimeException : An error occured while executing doInBackground()
at android.os.AsynkTask$3.FutureTask.finishCompletion(FutureTask.java:352)
班长:

case R.id.imageButtonServer:
    {
        textView = (TextView)findViewById(R.id.tvUserServerResponse);
        new HttpPostDemo().execute(textView);
        break;
    }
类HttpPostDemo:

   public class HttpPostDemo extends AsyncTask<TextView, Void, String> 
{
    TextView textView;

    //Only present when trying to retrieve text from editText2 field//
    EditText editText2;


@Override
protected String doInBackground(TextView... params)     
{

    this.textView = params[0];
    BufferedReader inBuffer = null;
    String url = "http://myserver.com/android_java.php";
    String result = "fail";

            //This fails//
    String mail = editText2.getText().toString();

            //This runs//
    String mail = 'mail';

    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost request = new HttpPost(url);
        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("operanda", "5"));
        postParameters.add(new BasicNameValuePair("operandb", "6"));
        postParameters.add(new BasicNameValuePair("answer", "11"));
        postParameters.add(new BasicNameValuePair("mail", mail));
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
公共类HttpPostDemo扩展异步任务
{
文本视图文本视图;
//仅在尝试从editText2字段检索文本时出现//
编辑文本编辑文本2;
@凌驾
受保护的字符串doInBackground(文本视图…参数)
{
this.textView=params[0];
BufferedReader inBuffer=null;
字符串url=”http://myserver.com/android_java.php";
字符串result=“fail”;
//这失败了//
String mail=editText2.getText().toString();
//这运行//
字符串mail='mail';
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost请求=新的HttpPost(url);
List postParameters=new ArrayList();
添加(新的BasicNameValuePair(“操作数”、“5”);
添加(新的BasicNameValuePair(“操作数B”、“6”);
添加(新的BasicNameValuePair(“答案”,“11”));
添加(新的BasicNameValuePair(“mail”,mail));
UrlEncodedFormEntity formEntity=新的UrlEncodedFormEntity(后参数);
main.xml:

      <EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Email Address"
    android:inputType="textEmailAddress" />

doInBackground
中添加以下行:

this.editText2 = params[1];

@Niels取决于从何处展开布局以获取此editText。它是在执行switch语句的同一活动中完成的吗?editText2是从调用post类的main.xml/main类中输入的。在我的设备上进行了测试并正在工作。非常感谢!我刚刚对java有了更多的了解:-)
case R.id.imageButtonServer:
    {
        textView = (TextView)findViewById(R.id.tvUserServerResponse);
        new HttpPostDemo().execute(textView, editText2);
        break;
    }
this.editText2 = params[1];