Note that there are some explanatory texts on larger screens.

plurals
  1. POFile not being saved onClick
    primarykey
    data
    text
    <p>Setting up a download onClick. I don't get any errors...the file just never gets saved. Can anyone tell me what I missed. Pulling my hair out for 2 hours, and it's probably something so small...</p> <p>Here's the code:</p> <pre><code> package com.mynavy; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import java.net.*; import android.util.*; import android.os.*; import java.io.*; public class YNrank extends Activity { Button E4; String url1 = "http://doni.daps.dla.mil/SECNAV%20Manuals1/5000.2.pdf"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rank_select); addListenerOnButton(); } public void addListenerOnButton() { E4 = (Button) findViewById(R.id.E4); E4.setOnClickListener(new OnClickListener() { public void onClick(View v){ new download().execute(url1); } class download extends AsyncTask&lt;String, Integer, String&gt;{ protected String doInBackground(String... url1) { try { URL url = new URL(url1[0]); HttpURLConnection urlConnection = (HttpURLConnection) url .openConnection(); String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/download/E4.pdf"; InputStream in = urlConnection.getInputStream(); OutputStream output = new FileOutputStream(path); int read = 0; byte[] buffer = new byte[32768]; while( (read = in.read(buffer)) &gt; 0) { output.write(buffer, 0, read); } output.close(); in.close(); } catch (Exception e) { e.printStackTrace(); } return null; } } }); };} </code></pre> <p>Done some updates to the code. To answer some questions. Yes I have INTERNET and WRITE_EXTERNAL_STORAGE permissions. Took out the Toast.</p> <p>LOGCAT FOR Stack Output:</p> <pre><code>11-03 05:08:13.557: D/dalvikvm(1364): GC_FOR_ALLOC freed 154K, 7% free 3682K/3952K, paused 34ms, total 46ms 11-03 05:08:14.196: W/System.err(1364): java.io.FileNotFoundException: /storage/sdcard/download/E4.pdf: open failed: ENOENT (No such file or directory) 11-03 05:08:14.206: W/System.err(1364): at libcore.io.IoBridge.open(IoBridge.java:409) 11-03 05:08:14.216: W/System.err(1364): at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:88) 11-03 05:08:14.226: W/System.err(1364): at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:128) 11-03 05:08:14.226: W/System.err(1364): at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:117) 11-03 05:08:14.236: W/System.err(1364): at com.mynavy.YNrank$1$download.doInBackground(YNrank.java:54) 11-03 05:08:14.236: W/System.err(1364): at com.mynavy.YNrank$1$download.doInBackground(YNrank.java:1) 11-03 05:08:14.256: W/System.err(1364): at android.os.AsyncTask$2.call(AsyncTask.java:287) 11-03 05:08:14.256: W/System.err(1364): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 11-03 05:08:14.266: W/System.err(1364): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 11-03 05:08:14.266: W/System.err(1364): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 11-03 05:08:14.278: W/System.err(1364): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 11-03 05:08:14.278: W/System.err(1364): at java.lang.Thread.run(Thread.java:841) 11-03 05:08:14.286: W/System.err(1364): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory) 11-03 05:08:14.296: W/System.err(1364): at libcore.io.Posix.open(Native Method) 11-03 05:08:14.306: W/System.err(1364): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 11-03 05:08:14.316: W/System.err(1364): at libcore.io.IoBridge.open(IoBridge.java:393) 11-03 05:08:14.316: W/System.err(1364): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload