Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying To Upload To Dropbox: NetworkOnMainThreadException?
    primarykey
    data
    text
    <p>I have been fighting for like 6 hours with this now. I have followed Dropbox's "tutorials" (if they can be called that, because they are awfully poor), played with the DBRoulette example, and done tons of stuff to get my app working.</p> <p>My app can Authenticate with no problems. But I can't upload anything despite doing exactly what the tutorial is doing:</p> <p>This is the little snippet of code I have (this is to save a created note on the phone itself and then upload to Dropbox):</p> <pre><code> saveBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { try { //Create the directory if it doesn't exist. If it does exist the next two line won't do anything. File dropNotesDir = new File(Environment.getExternalStorageDirectory() + "/documents/AppData/Dropnotes/"); dropNotesDir.mkdirs(); //----------------------------------------------------------------------------------------------- String wholeNoteString = noteBody.getText().toString(); //Now we create the title of the txt file. It will be the first line of the whole note. The name will get truncated to 32 characters //if it's too long. String noteTitle; if(wholeNoteString.indexOf("\n") &gt;= 0) //New line character found. { noteTitle = wholeNoteString.substring(0, wholeNoteString.indexOf("\n")); if(noteTitle.length() &gt;= 32) { noteTitle = wholeNoteString.substring(0, 32); } } else { if(wholeNoteString.length() &gt;= 32) { noteTitle = wholeNoteString.substring(0, 32); }else { noteTitle = wholeNoteString; } } if(extras.getString("file-mode").equals("modify")) { //We will need to delete the existing file if it does exist to save the new one. File existing = new File(Environment.getExternalStorageDirectory() + "/documents/AppData/Dropnotes/" + extras.getString("noteTitle")); existing.delete(); } File newNote = new File(Environment.getExternalStorageDirectory() + "/documents/AppData/Dropnotes/" + noteTitle + ".txt"); PrintWriter newNoteWriter = new PrintWriter(new FileOutputStream(newNote)); newNoteWriter.print(noteBody.getText().toString()); newNoteWriter.close(); //TRYING TO UPLOAD TO DROPBOX HERE File fileToUpload = new File(Environment.getExternalStorageDirectory() + "/documents/AppData/Dropnotes/" + noteTitle + ".txt"); FileInputStream file2Uis = new FileInputStream(fileToUpload); Entry newEntry = mDBApi.putFile("/" + noteTitle + ".txt", file2Uis, fileToUpload.length(), null, null); //END OF TRYING TO UPLOAD TO DROPBOX HERE Toast.makeText(view.getContext(), "Saved successfully", Toast.LENGTH_SHORT).show(); finish(); } catch (FileNotFoundException e) { Toast.makeText(view.getContext(), "File not found: " + e.getMessage(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); } catch(Exception e) { Toast.makeText(view.getContext(), "Some bizarre exception occured: " + e.getClass().toString(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); } } }); </code></pre> <p>It's giving me a NetworkOnMainThreadException and I don't know why. I'm trying to follow the section titled "Uploading a File" <a href="https://www.dropbox.com/developers/start/files#android" rel="nofollow" title="here">here</a>. What baffles me about their snippet is that they are not even trying to catch the exception I'm getting thrown at...</p> <p>Any help? I really need to get this working for next Friday.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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