You have declared your result
String array but did not initialize it.
Try this:
@SuppressWarnings("null")
public String[] request(String requesturl, String user, String password)
{
String result[] = new String[ <Insert value> ];
// Code...
}
Let me explain further to avoid downvotes. This is why I think this:
You first initialize the array to null, so it can't be used yet. Further down the line you have this statement String results = ""
but your array is still null
. Then you do this result[0] = ""
, oh dear. That is where the nullPointerException
comes from, I think.
You have to initialize your array and you are right if you say that you need to know the size of your array up front. Use the maximum value you expect for the size or, better yet, use a list
and not an array
.
Here is a nice source for the list
datastructure: List in Android Development.
There is also a nice discussion about list
versus arrays
here, it is for C# but the principles remain more or less the same.