-4

I have been attempting to declare an array but there is this NullPointer that comes up and prevents me from continuing. Also, I do not have access to LogCat because my Android Version now requires root for that. I am developing purely on a device with only AIDE.

I cannot implicitly paste code here because my device will not allow, so I have my codes put into PasteBin pages.

MainActivity.java It is at line 45 of the above paste that the NullPointer turns up on

AppFiles.java This is the File that is being referenced with the MainActivity class.

Blisskarthik
  • 1,246
  • 8
  • 20

2 Answers2

1

It seems you haven't initialized an Array object for itemStrings

replace your code public static String[] itemStrings; with this,

 public static String[] itemStrings = new String[Your_Array_Length]; 
user3717646
  • 436
  • 3
  • 10
  • Thank you. Fixed my horrible null Pointer but since I need the Array to be dynamic I couldn't set it up exactly like what you gave. I did public static String[] itemStrings = new String [] {} – user3801378 Jul 03 '14 at 11:36
  • @user3801378 Don't use dynamic arrays. Yeuch. Try `ArrayList` or similar. Read about Java generics. – Simon Jul 03 '14 at 11:37
  • good eye, I missed that – WarrenFaith Jul 03 '14 at 11:55
0

I state the obvious: One of your file types is not there and you get the NPE for that.

The basic issue is that you return null in your return*() methods instead of an empty File[] array. So basically try that:

// just one of the methods picked as an example
public static File[] returnAssignments() {
    Assignments assignments = new Assignments();
    if (assignments.filePath.exists()) {
        return assignments.filePath.listFiles();
    }
    return new File[0];
}

That would prevent your AppFiles.getFileCount(type) to throw an NPE if no file for that type was found.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150