Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法启动意图为{flg=0x4(有附加项)}的服务_Php_Android - Fatal编程技术网

Php 无法启动意图为{flg=0x4(有附加项)}的服务

Php 无法启动意图为{flg=0x4(有附加项)}的服务,php,android,Php,Android,我想从服务中插入PHP。但我有这样的错误: Unable to start service skripsi.ubm.studenttracking.altitudeSurvey@366d624d with Intent { flg=0x4 cmp=skripsi.ubm.studenttracking/.altitudeSurvey (has extras) }: android.os.NetworkOnMainThreadException 这是我的代码: public void inser

我想从服务中插入PHP。但我有这样的错误:

Unable to start service skripsi.ubm.studenttracking.altitudeSurvey@366d624d with Intent { flg=0x4 cmp=skripsi.ubm.studenttracking/.altitudeSurvey (has extras) }: android.os.NetworkOnMainThreadException
这是我的代码:

public void insert() {
        String time;
        SimpleDateFormat dayFormat = new SimpleDateFormat("HH:mm:ss", Locale.US);
        Calendar calendars = Calendar.getInstance();
        time = dayFormat.format(calendars.getTime());
        try {
            httpClient = new DefaultHttpClient();
            httpPost = new HttpPost("http://studentstracking.hol.es/altitudeSurvey.php");
            nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("baro", value));
            nameValuePairs.add(new BasicNameValuePair("jam", time));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            response = httpClient.execute(httpPost);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            final String response = httpClient.execute(httpPost, responseHandler);
            Toast.makeText(altitudeSurvey.this, "Response from Server : " + response, Toast.LENGTH_SHORT).show();
            if (response.equalsIgnoreCase("Success")) {
                Toast.makeText(getApplicationContext(), "Data has been Inserted", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Data Failed", Toast.LENGTH_SHORT).show();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void insert(){
串时间;
SimpleDataFormat dayFormat=新的SimpleDataFormat(“HH:mm:ss”,Locale.US);
日历日历=Calendar.getInstance();
time=dayFormat.format(calendars.getTime());
试一试{
httpClient=新的DefaultHttpClient();
httpPost=新的httpPost(“http://studentstracking.hol.es/altitudeSurvey.php");
nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“baro”,value));
添加(新的BasicNameValuePair(“jam”,time));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
response=httpClient.execute(httpPost);
ResponseHandler ResponseHandler=新BasicResponseHandler();
最终字符串响应=httpClient.execute(httpPost,responseHandler);
Toast.makeText(altitudeSurvey.this,“来自服务器的响应:”+Response,Toast.LENGTH\u SHORT.show();
if(response.equalsIgnoreCase(“Success”)){
Toast.makeText(getApplicationContext(),“数据已插入”,Toast.LENGTH_SHORT.show();
}否则{
Toast.makeText(getApplicationContext(),“数据失败”,Toast.LENGTH_SHORT.show();
}
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(不支持的编码异常e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}

此方法是内部服务。您能帮我解决这个问题吗?

您面临的是android.os.NetworkOnMainThreadException这意味着您正在从oncreate调用insert()方法。您需要使用
AsyncTask
,这将使您免于此异常

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         insert()
         return result;
     }

     protected void onProgressUpdate(Integer... progress) {

     }

     protected void onPostExecute(Long result) {

     }
 }

您面临的是这个
android.os.NetworkOnMainThreadException
,这意味着您正在从oncreate调用insert()方法。您需要使用
AsyncTask
,这将使您免于此异常

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         insert()
         return result;
     }

     protected void onProgressUpdate(Integer... progress) {

     }

     protected void onPostExecute(Long result) {

     }
 }

您面临的是这个
android.os.NetworkOnMainThreadException
,这意味着您正在从oncreate调用insert()方法。您需要使用
AsyncTask
,这将使您免于此异常

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         insert()
         return result;
     }

     protected void onProgressUpdate(Integer... progress) {

     }

     protected void onPostExecute(Long result) {

     }
 }

您面临的是这个
android.os.NetworkOnMainThreadException
,这意味着您正在从oncreate调用insert()方法。您需要使用
AsyncTask
,这将使您免于此异常

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         insert()
         return result;
     }

     protected void onProgressUpdate(Integer... progress) {

     }

     protected void onPostExecute(Long result) {

     }
 }

错误:

无法启动服务 skripsi.ubm.studenttracking。altitudeSurvey@366d624d带Int

从错误中,我可以看到您正在主线程上运行网络操作。您不能在应用程序的主线程上运行网络操作


您必须创建asynctask或线程才能在后台线程中运行网络操作

错误:

无法启动服务 skripsi.ubm.studenttracking。altitudeSurvey@366d624d带Int

从错误中,我可以看到您正在主线程上运行网络操作。您不能在应用程序的主线程上运行网络操作


您必须创建asynctask或线程才能在后台线程中运行网络操作

错误:

无法启动服务 skripsi.ubm.studenttracking。altitudeSurvey@366d624d带Int

从错误中,我可以看到您正在主线程上运行网络操作。您不能在应用程序的主线程上运行网络操作


您必须创建asynctask或线程才能在后台线程中运行网络操作

错误:

无法启动服务 skripsi.ubm.studenttracking。altitudeSurvey@366d624d带Int

从错误中,我可以看到您正在主线程上运行网络操作。您不能在应用程序的主线程上运行网络操作


您必须创建asynctask或线程才能在后台线程中运行网络操作

在异步任务中编写此方法。它将完美地工作。

在异步任务中编写此方法。它将完美地工作。

在异步任务中编写此方法。它将完美地工作。

在异步任务中编写此方法。它将完美地工作。

您不能在主线程上执行网络操作。最好使用
AsyncTask
执行与网络相关的操作。您不能在主线程上执行网络操作。最好使用
AsyncTask
执行与网络相关的操作。您不能在主线程上执行网络操作。最好使用
AsyncTask
执行与网络相关的操作。您不能在主线程上执行网络操作。最好使用
AsyncTask
执行与网络相关的操作。