Java Android应用程序在向服务器发送数据时崩溃

Java Android应用程序在向服务器发送数据时崩溃,java,android,networking,android-emulator,android-ui,Java,Android,Networking,Android Emulator,Android Ui,我正在尝试向我的服务器发送一些数据,这些数据在互联网上是公开的。 应用程序在启动完成(添加权限)后作为服务启动,无论应用程序如何崩溃。 我已经缩小了密码的范围。 它似乎在试图向服务器发送数据时崩溃 下面是我的代码。 如果你们能在这件事上帮助我,我真的很感激 package com.example.bootstart; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.

我正在尝试向我的服务器发送一些数据,这些数据在互联网上是公开的。 应用程序在启动完成(添加权限)后作为服务启动,无论应用程序如何崩溃。 我已经缩小了密码的范围。 它似乎在试图向服务器发送数据时崩溃

下面是我的代码。 如果你们能在这件事上帮助我,我真的很感激

package com.example.bootstart;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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 android.os.AsyncTask;
import android.util.Log;

class SendData extends AsyncTask<Void, Void, Boolean> {


    public void sendinfo(){
            // Creating HTTP client
        HttpClient httpClient = new DefaultHttpClient();
        // Creating HTTP Post
        HttpPost httpPost = new HttpPost(
                "http://www.mydomain.com/controller_name/funtion_name");

        // Building post parameters
        // key and value pair
        List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4);
        nameValuePair.add(new BasicNameValuePair("imei", "12345"));
        nameValuePair.add(new BasicNameValuePair("welawa", "12315646545"));
        nameValuePair.add(new BasicNameValuePair("lat", "123.25"));
        nameValuePair.add(new BasicNameValuePair("long", "52.22323"));

        // 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
    protected Boolean doInBackground(Void... params) {
        // TODO Auto-generated method stub
        return null;
    }




}
package com.example.bootstart;
导入java.io.IOException;
导入java.io.UnsupportedEncodingException;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.HttpResponse;
导入org.apache.http.NameValuePair;
导入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.impl.client.DefaultHttpClient;
导入org.apache.http.message.BasicNameValuePair;
导入android.os.AsyncTask;
导入android.util.Log;
类SendData扩展异步任务{
public void sendinfo(){
//创建HTTP客户端
HttpClient HttpClient=新的DefaultHttpClient();
//创建HTTP Post
HttpPost HttpPost=新的HttpPost(
"http://www.mydomain.com/controller_name/funtion_name");
//建筑柱参数
//键和值对
List nameValuePair=新的ArrayList(4);
添加(新的BasicNameValuePair(“imei”、“12345”);
添加(新的BasicNameValuePair(“welawa”、“12315646545”);
添加(新的BasicNameValuePair(“lat”,“123.25”));
添加(新的BasicNameValuePair(“长”、“52.22323”);
//对POST参数进行Url编码
试一试{
setEntity(新的UrlEncodedFormEntity(nameValuePair));
}捕获(不支持的编码异常e){
//将错误写入日志
e、 printStackTrace();
}
//发出HTTP请求
试一试{
HttpResponse response=httpClient.execute(httpPost);
//将响应写入日志
Log.d(“Http响应:,Response.toString());
}捕获(客户端协议例外e){
//将异常写入日志
e、 printStackTrace();
}捕获(IOE异常){
//将异常写入日志
e、 printStackTrace();
}
}
@凌驾
受保护的布尔doInBackground(Void…params){
//TODO自动生成的方法存根
返回null;
}
}
我是一名php开发人员,试图编写一个简单的应用程序来记录GPS Cordinate

我无法检查控制台,因为某些东西使模拟器工作。我总是发现emulator-arm.exe已经停止工作了。所以每次我测试的时候我都会用我的手机重新启动。所以很不幸,我也没有访问日志的权限


非常感谢您的帮助。

我不知道在哪里调用了
sendinfo()
?但我认为在你主要的活动中你称之为:

newsenddata().sendInfo():(

请将sendInfo放到doInBackground


在你的活动中:
new SendData().execute();
我不知道在哪里调用了
sendinfo()
?但我想在你的主要活动中你称之为:

新建SendData().sendInfo();
:(

请将sendInfo放到doInBackground


在你的活动中:
new SendData().execute();
我不知道在哪里调用了
sendinfo()
?但我想在你的主要活动中你称之为:

新建SendData().sendInfo();
:(

请将sendInfo放到doInBackground


在你的活动中:
new SendData().execute();
我不知道在哪里调用了
sendinfo()
?但我想在你的主要活动中你称之为:

新建SendData().sendInfo();
:(

请将sendInfo放到doInBackground


在您的活动中
new SendData().execute();

调用了
sendinfo()
方法之前,您在哪里检查Internet连接?如果您没有日志,则生成带有异常消息的
Toast
。从doInbackground()调用sendinfo()@谢谢你的提示。当我了解了基本知识后,我肯定会加上这个。我只是通过将手机连接到wifi进行测试来确保互联网连接。哪里是
sendinfo()
呼叫?在呼叫
sendinfo()之前检查互联网连接的地方
method?如果您没有日志,则生成带有异常消息的
Toast
。从doInbackground()调用sendInfo()@谢谢你的提示。当我了解了基本知识后,我肯定会加上这个。我只是通过将手机连接到wifi进行测试来确保互联网连接。哪里是
sendinfo()
呼叫?在呼叫
sendinfo()之前检查互联网连接的地方
method?如果您没有日志,则生成带有异常消息的
Toast
。从doInbackground()调用sendInfo()@谢谢你的提示。当我了解了基本知识后,我肯定会加上这个。我只是通过将手机连接到wifi进行测试来确保互联网连接。哪里是
sendinfo()
呼叫?在呼叫
sendinfo()之前检查互联网连接的地方
method?如果您没有日志,则生成带有异常消息的
Toast
。从doInbackground()调用sendInfo()@ρц∑ѕρєK感谢您提供的提示。当我了解基本知识时,肯定会添加此内容。我只是确保互联网