Java Android http请求失败。。。我的错误在哪里?

Java Android http请求失败。。。我的错误在哪里?,java,android,eclipse,apache,import,Java,Android,Eclipse,Apache,Import,不知道我的错误在哪里 import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.wid

不知道我的错误在哪里

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

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

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
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.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import java.io.InputStreamReader;
import org.apache.http.message.BasicNameValuePair;



public class MainActivity extends Activity {
    EditText email;
    EditText passsword;
    Button   btn_send;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_send = (Button)findViewById(R.id.send_session);
        btn_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    Send();
            }
        });

    }

    public void Send(){
        String text ="";

        try {
            email = (EditText)findViewById(R.id.email);
            passsword = (EditText)findViewById(R.id.password);

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://172.16.1.196:3000/clients/login.json");

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("email",email.getText().toString()));
            params.add(new BasicNameValuePair("password",passsword.getText().toString()));

            httppost.setEntity(new UrlEncodedFormEntity(params));

            Log.v("URL" , httppost.toString());

            HttpResponse resp = httpclient.execute(httppost);

            HttpEntity ent= resp.getEntity();

            text = EntityUtils.toString(ent);

        }
        catch (Exception e) {
            Log.v("mesage" , e.getMessage().toString());
        }


        email.setText(text);
    }




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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
导入android.app.Activity;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
导入java.io.UnsupportedEncodingException;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.HttpEntity;
导入org.apache.http.NameValuePair;
导入java.io.BufferedReader;
导入java.io.IOException;
导入java.io.InputStream;
导入org.apache.http.HttpResponse;
导入org.apache.http.client.ClientProtocolException;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.entity.UrlEncodedFormEntity;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.entity.StringEntity;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.util.EntityUtils;
导入org.json.JSONObject;
导入java.io.InputStreamReader;
导入org.apache.http.message.BasicNameValuePair;
公共类MainActivity扩展了活动{
编辑文本电子邮件;
编辑文本传递剑;
按钮btn_发送;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_send=(按钮)findviewbyd(R.id.send_会话);
btn_send.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Send();
}
});
}
公共无效发送(){
字符串文本=”;
试一试{
email=(EditText)findviewbyd(R.id.email);
Passbrow=(EditText)findViewById(R.id.password);
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://172.16.1.196:3000/clients/login.json");
List params=new ArrayList();
add(新的BasicNameValuePair(“email”,email.getText().toString());
add(新的BasicNameValuePair(“密码”,passSwarm.getText().toString());
setEntity(新的UrlEncodedFormEntity(参数));
Log.v(“URL”,httppost.toString());
HttpResponse resp=httpclient.execute(httppost);
HttpEntity ent=resp.getEntity();
text=EntityUtils.toString(ent);
}
捕获(例外e){
Log.v(“mesage”,例如getMessage().toString());
}
email.setText(文本);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单菜单菜单主菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}
还有我的活动

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:background="#283439">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="50dip"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/email"
        android:layout_marginTop="132dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textColor="#00c189"
        android:textAlignment="center"
        android:clickable="false"
        android:background="@drawable/customs_borders"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="50dip"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/password"
        android:textAlignment="center"
        android:textColor="#00c189"
        android:clickable="false"
        android:background="@drawable/customs_borders"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/email"
        android:layout_alignStart="@+id/email" />

    <Button
        android:layout_width="218dip"
        android:layout_height="50dip"
        android:text="Login"
        android:id="@+id/send_session"
        android:textColor="#0cc189"
        android:background="#282934"
        android:layout_marginTop="50dp"
        android:layout_below="@+id/password"
        android:layout_alignRight="@+id/password"
        android:layout_alignEnd="@+id/password" />

</RelativeLayout>

还有我的舱单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.xxxxx.xxxxxx" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.xxxxx.xxxxxx.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />

</manifest

日志控制台的一部分

20:21.178 27635-27635/com.example.xxxx.xxxxx W/dalvikvm﹕ threadid=1:线程以未捕获异常退出(组=0x40ffb930) 10-24 13:20:21.178 27635-27635/com.example.xxxx.xxxxx E/AndroidRuntime﹕ 致命异常:主 java.lang.NullPointerException 位于com.example.xxxx.xxxxx.MainActivity.Send(MainActivity.java:81) 位于com.example.xxxx.xxxxx.MainActivity$1.onClick(MainActivity.java:49) 在android.view.view.performClick上(view.java:4421) 在android.view.view$PerformClick.run(view.java:18190) 位于android.os.Handler.handleCallback(Handler.java:725) 位于android.os.Handler.dispatchMessage(Handler.java:92) 位于android.os.Looper.loop(Looper.java:175) 位于android.app.ActivityThread.main(ActivityThread.java:5279) 位于java.lang.reflect.Method.Invokenactive(本机方法) 位于java.lang.reflect.Method.invoke(Method.java:511) 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)上 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 在dalvik.system.NativeStart.main(本机方法)

请帮忙

错误日志显示:

com.example.xxxx.xxxxx.MainActivity.Send上的java.lang.NullPointerException(MainActivity.java:81)

这表示在
Send
方法中,
MainActivity
的第81行有不应该为空的内容


此外,一旦问题得到解决,您将立即遇到问题,因此请确保阅读该答案以使应用程序正常运行。

那么com.example.xxxx.xxxxx.MainActivity.Send(MainActivity.java:81)上的
null是什么
?注意:在解决问题后,您将立即遇到问题,因此请提前警告。xxxx.xxxxx是我的包名,因为公司名为private,sorry@ianhanniballakeAsyncTask在othe.class中并从activity.class调用?哪一行是第81行?