Outdated code and tutorial for dropbox API?

Daniels :

I don't understand why Android studios isn't recognizing .runOnUiThread (Cannot resolve method) and "main" (Cannot resolve symbol).

I was following youtube tutorial (the video is 4+ years old) on how to program app that uploads and downloads files through dropbox. Copying source code right in to MainActivity.java results in some code being red, but pressing "ALT+ENTER" resolves the problem just like in video except .runOnUiThread and "main". What causes this problem and how to solve it?

private void DownloadFromDropboxFromPath (String downloadPathTo, String downloadPathFrom)
{
    DropboxDownloadPathTo = downloadPathTo;
    DropboxDownloadPathFrom = downloadPathFrom;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), "Download file ...", Toast.LENGTH_SHORT).show();
            Thread th = new Thread(new Runnable() {
                public void run() {
                    File file = new File(DropboxDownloadPathTo + DropboxDownloadPathFrom.substring(DropboxDownloadPathFrom.lastIndexOf('.')));
                    if (file.exists()) file.delete();
                    try {
                        FileOutputStream outputStream = new FileOutputStream(file);
                        main.dropboxAPI.getFile(DropboxDownloadPathFrom, null, outputStream, null);
                        getMain().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(), "File successfully downloaded.", Toast.LENGTH_SHORT).show();
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            th.start();
        }
    });
}
Freddy :

I am guessing that this is the tutorial you watched: https://youtu.be/0PjND_7Fzd8. Based on that, "main" gets highlighted in red either because your java file is not "main.java" or your class name is not "main" or both. The public class name and the file name must be the same and are case sensitive. As for "runOnUiThread" - it might be because your class does not extend ActionBarActivity or because you might have not set up your Android SDK correctly.

P.S. have you tried pCloud? It is easier to set up and has a better API.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=156229&siteId=1