This question is an exact duplicate:
- Problem when displaying html in android 2 answers
Please help me with the error. When you click on the button, the data should be sent to the server.
buttonBy1 = (Button) view.findViewById(R.id.buttonBy1); buttonBy1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String str; try { File file = new File(context.getFilesDir(), MainActivity.FILENAME); if (!file.exists()) { file.createNewFile(); System.out.println( "Fail sozdan"); } BufferedReader br = new BufferedReader(new FileReader(file)); str = br.readLine(); if (str == null) { Intent intent = new Intent(view.getContext(), Telefon.class); startActivity(intent); } else { MyTask mt = new MyTask(); mt.execute(str); } } catch (FileNotFoundException e){ System.out.println("FAIL NE SOZDAN"); } catch (IOException e) { e.printStackTrace(); } } }); class MyTask extends AsyncTask<String, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBackground(String... params) { HttpClient httpclient = new DefaultHttpClient(); // указываем адрес вашего сервера и путь принимающего скрипта HttpPost httppost = new HttpPost("http://aqualine09.ru/send.php"); try { List nameValuePairs = new ArrayList(2); for (String x : params) { nameValuePairs.add(new BasicNameValuePair("name", x)); } httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httpclient.execute(httppost); // отправка на сервер // отправляемое сообщение } catch (ClientProtocolException e) { // ... } catch (IOException e) { // ... } return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); } } The error takes off:
FATAL EXCEPTION: AsyncTask #1 Process: com.ferisov.aqualive, PID: 9256 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:304) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) at java.util.concurrent.FutureTask.setException(FutureTask.java:222) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?) at java.net.InetAddress.lookupHostByName(InetAddress.java:451) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:142) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470) at com.ferisov.aqualive.FirstFragment$MyTask.doInBackground(FirstFragment.java:170) at com.ferisov.aqualive.FirstFragment$MyTask.doInBackground(FirstFragment.java:152) at android.os.AsyncTask$2.call(AsyncTask.java:292) What doesn't he like?