0

In Dropbox API v1 I used:

String userName = dropboxAccount.getAccountInfo().userName;

to get the user name and display it on the screen.

Now I'm using API v2, so I tried the following code:

public String getLoggedAccount()
{
    String userAccountStr;

    if (sDbxClient == null)
        return "N/A";

    try
    {
        userAccountStr  = sDbxClient.users().getCurrentAccount().getAccountId();
        userAccountStr += ", ";

        userAccountStr += sDbxClient.users().getCurrentAccount().getEmail();
        userAccountStr += ", ";
        return userAccountStr;
    }

    catch(IllegalArgumentException e)
    {
        mException = e;
    }

    catch(NullPointerException e)
    {
        mException = e;
    }

    catch (com.dropbox.core.DbxException e)
    {
        mException = e;
    }

    return "N/A";
}

but it's crashing on the "getAccountId()" line, and never get to any on the 'catch' lines.

What may be the problem?

========== ========= ========= ========== ==========

Here is some more information:

I took the Anroid example project that comes with the new Dropbox API v2 and right after the line:

sDbxClient = new DbxClientV2(requestConfig, accessToken);

I added a call to the following function:

private static String getLoggedAccount()
{
    if (sDbxClient == null)
        return "N/A";

    FullAccount dbxAccountInfo;

    try
    {
        dbxAccountInfo = sDbxClient.users().getCurrentAccount();
    }

    catch (DbxException ex)
    {
        System.err.println("Error making API call: " + ex.getMessage());
        System.exit(1);
        return "N/A";
    }

    System.out.print(dbxAccountInfo.toStringMultiline());
}

It's crash on the getCurrentAccount() line, and never reach the catch. In the Logcat window I see this FATAL EXCEPTION:

03-14 14:11:52.400 7870-7870/com.dropbox.core.examples.android I/System.out: debugger has settled (1465) 03-14 14:11:52.468 7870-7870/com.dropbox.core.examples.android W/System: ClassLoader referenced unknown path: /data/app/com.dropbox.core.examples.android-2/lib/arm

03-14 14:12:11.779 7870-7870/com.dropbox.core.examples.android E/AndroidRuntime: FATAL EXCEPTION: main Process: com.dropbox.core.examples.android, PID: 7870 java.lang.RuntimeException: Unable to resume activity {com.dropbox.core.examples.android/com.dropbox.core.examples.android.UserActivity}: android.os.NetworkOnMainThreadException at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273) at java.net.InetAddress.lookupHostByName(InetAddress.java:431) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188) at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100) at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357) at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:437) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:245) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java) at com.dropbox.core.http.StandardHttpRequestor.getOutputStream(StandardHttpRequestor.java:123) at com.dropbox.core.http.StandardHttpRequestor.access$000(StandardHttpRequestor.java:28) at com.dropbox.core.http.StandardHttpRequestor$Uploader.(StandardHttpRequestor.java:133) at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:72) at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:28) at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:237) at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:107) at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:284) at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:102) at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120) at com.dropbox.core.examples.android.DropboxClientFactory.getLoggedAccount(DropboxClientFactory.java:31) at com.dropbox.core.examples.android.DropboxClientFactory.init(DropboxClientFactory.java:91) at com.dropbox.core.examples.android.DropboxActivity.initAndLoadData(DropboxActivity.java:43) at com.dropbox.core.examples.android.DropboxActivity.onResume(DropboxActivity.java:32) at com.dropbox.core.examples.android.UserActivity.onResume(UserActivity.java:63) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258) at android.app.Activity.performResume(Activity.java:6327) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092) .. 03-14 14:16:13.708 7870-7870/? I/Process: Sending signal. PID: 7870 SIG: 9

Does it helps?

  • What error/output are you getting from the crash? – Greg Mar 13 '18 at 18:42
  • I don't see any error, it's just telling me that the application stoped working. What 'catch' should I use in the try-catch to catch any type of dropbox error? – StackOverflow User Mar 13 '18 at 18:44
  • The [`com.dropbox.core.DbxException`](https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/DbxException.html) `catch` should catch all Dropbox exceptions. What are you getting in the console when the app crashes? – Greg Mar 13 '18 at 18:51
  • It's says "Disconnected from the target VM, address: 'localhost:8609', transport: 'socket' ", and as I said it's not stopping on the breakpoint that I set on the com.dropbox.core.DbxException catch, why? – StackOverflow User Mar 13 '18 at 19:03
  • And on my Nexus-5 device screen it's says: "Unfortunately, MyAppName has stopped". – StackOverflow User Mar 13 '18 at 19:06
  • I can't offer help with your development environment itself, but you should be getting some sort of output when your app crashes. In Android Studio, check "Logcat". Be sure to check the filter, if any, you have enabled in Logcat too, as it may be obscuring output. – Greg Mar 13 '18 at 19:20
  • In the 'Logcat' I see many lines of text, some are black, some red and some blue, will it help if I'll post them here? I also see 2 comboboxes, one have the following options: { Varbose, Debug, Info, Warn, Error, Assert } , and the other have: { "Show only selected application", "Firebase", "No Filters", "Edit Filter Configuration" } , what option should I select at each one of this boxes? – StackOverflow User Mar 13 '18 at 19:44
  • I edited my message and I added the FATAL EXCEPTION that I see in the Logcat window, please see if it helps. – StackOverflow User Mar 14 '18 at 12:42
  • From your output, you're getting a `android.os.NetworkOnMainThreadException`. There's a post about that here: https://stackoverflow.com/questions/26537338/uploading-file-to-dropbox-in-android-putfile-method-throws-exception/26538029#26538029 – Greg Mar 14 '18 at 15:41
  • OK it's better now, I added the 'getCurrentAccount' to a doInBackground() thread and now I'm getting the data in the Android Example project. I'm now trying to add it also to my project. – StackOverflow User Mar 18 '18 at 16:09

0 Answers0