Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9314759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:12:54+00:00 2026-06-19T02:12:54+00:00

Am I missing something here? My code is kicking a NullPointerException based on this

  • 0

Am I missing something here? My code is kicking a NullPointerException based on this code to upload to Dropbox.

File file = new File(mFileMag.getCurrentDir() +"/"+ mSelectedListItem);
System.out.println(file);
inputStream = new FileInputStream(file);
System.out.println(inputStream);
Entry newEntry = mDBApi.putFile("/" + mSelectedListItem, inputStream,
        file.length(), null, null); 
System.out.println(newEntry);

The results of the system.out commands look ok. The inputStream variable outputs “java.io.FileInputStream@44ecd668” which I’m a little confused about but the systemout for the file variable displays the right path and filename. The nullPointerException seems to be coming from the setting of the newEntry variable which makes zero sense to me. Eclipse shows the code as being syntactically correct. This dropbox crap is killing me.

@BenHolland — If I hardcode the paths as below —

 case D_MENU_SEND:

            // Uploading content.
            FileInputStream inputStream = null;
            try {
                //File file = new File(mFileMag.getCurrentDir() +"/"+ mSelectedListItem);
                File file = new File("/sdcard0/DCIM/100ANDRO/deploy.json");
                System.out.println(file);
                inputStream = new FileInputStream(file);
                System.out.println(inputStream);
                Entry newEntry = mDBApi.putFile("/Dropbox/", inputStream,
                        file.length(), null, null); 
                System.out.println(newEntry);

                Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
            } catch (DropboxUnlinkedException e) {
                // User has unlinked, ask them to link again here.
                Log.e("DbExampleLog", "User has unlinked.");
            } catch (DropboxException e) {
                Log.e("DbExampleLog", "Something went wrong while uploading.");
            } catch (FileNotFoundException e) {
                Log.e("DbExampleLog", "File not found.");
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {}
                }
            }

This simply generates a “File not found” in logcat which of course is coming from catch (FileNotFoundException). I don’t however receive the NullPointerException. If you see at the top of the code — the case statement — this code is being run after a context menu click.

_____________________________________Updated code__________________________________________

 // Uploading content.
        FileInputStream inputStream = null;

        File upfile = new File(mFileMag.getCurrentDir() + "/" + mSelectedListItem);
        try {
            inputStream = new FileInputStream(upfile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println(upfile);
        System.out.println(inputStream);

        try {
            Entry upEntry = mDBApi.putFile("/test.rar", inputStream,upfile.length(), null, null);
            System.out.println(upEntry);
        } catch (DropboxException e) {
            e.printStackTrace();
        }

So I’ve updated the code to this. Whether I hardcode the paths or not seems to be irrelevant. Even If I do, the Entry upEntry line is causing a NullPointerException. I’m at a loss. I cant see anything at all that would be causing this.

________________________________Stack trace from nullPointerException_______________________

02-14 13:28:07.370: W/dalvikvm(311): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-14 13:28:07.380: E/AndroidRuntime(311): FATAL EXCEPTION: main
02-14 13:28:07.380: E/AndroidRuntime(311): java.lang.NullPointerException
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.stavox.zircon.Main.onContextItemSelected(Main.java:722)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.app.Activity.onMenuItemSelected(Activity.java:2199)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2744)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.widget.ListView.performItemClick(ListView.java:3382)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.os.Handler.handleCallback(Handler.java:587)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.os.Looper.loop(Looper.java:123)
02-14 13:28:07.380: E/AndroidRuntime(311):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-14 13:28:07.380: E/AndroidRuntime(311):  at java.lang.reflect.Method.invokeNative(Native Method)
02-14 13:28:07.380: E/AndroidRuntime(311):  at java.lang.reflect.Method.invoke(Method.java:521)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-14 13:28:07.380: E/AndroidRuntime(311):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-14 13:28:07.380: E/AndroidRuntime(311):  at dalvik.system.NativeStart.main(Native Method)

There is the stack trace which occurs when I click “Send to Dropbox” . I think if I break down the whole process it might make it easier for someone to help.

  1. App launches to a list view – its a file manager app – main.java
  2. The user clicks a button on the menu that launches the dropbox authorization – the button loads DropboxfileuploadActivity.java – Thats where the auth is done – this returns them to main.java after auth.
  3. User navigates to file they want to upload
  4. The user long clicks on said file and a context menu appears – this is handled by Main.java as well.
  5. The context menu contains a “Send To Dropbox” item. When clicked, it points to the case statement containing the code we have been looking at here. Thats what is generating the NullPointerException. As you can see above line 722 is the offending line. That line is the

     Entry upEntry = mDBApi.putFile("/test.rar", inputStream,upfile.length(), null, null);
    

    _____________________________________________Solution_______________________________________

So here’s what I ended up doing to solve this:

Previously I was working between two files. I had the Dropbox authcode in Main.java, and the actual upload code in Dropboxfileuploadactivity.java. No matter what I tried, I could not get the upload to work this way. I received a NullPointerException every time. I initially blamed it on the variables and not being able to use then with the Dropbox methods. After days of trying to figure it out, in the end, moving the auth code and the upload code together in to Main.java is what solved my issue. No more NullPointerExceptions. Odd, but it worked. The variables work fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:12:55+00:00Added an answer on June 19, 2026 at 2:12 am

    So heres what I ended up doing to solve this:

    Previously I was working between two files. I had the Dropbox authcode in Main.java, and the actual upload code in Dropboxfileuploadactivity.java. No matter what I tried, I could not get the upload to work this way. I received a NullPointerException every time. I initially blamed it on the variables and not being able to use then with the Dropbox methods. After days of trying to figure it out, in the end, moving the auth code and the upload code together in to Main.java is what solved my issue. No more NullPointerExceptions. Odd, but it worked. The variables work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be missing something obvious here, but how could I rewrite this code
I'm new to Dart, so maybe I'm missing something here: This works: In my
I guess that I am missing something here. After having found this sample within
This may be an easy question and perhaps I am missing something here. The
I am new to Moq, so hopefully I am just missing something here. For
I am trying to create an ajaxy file upload. Here is the asp code:
Its possibly im just missing something here but, when I write some code for
I must be missing something here... I have the following code and output. Can
Okay, I must be missing something here because this should be extremely simple, yet
I know I'm missing something here. In the XSLT transformation below, the actual result

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.