0

I am new to android, json, processing and stackoverflow, so please bear with me. I took some processing code, made sure it worked, and tried to create an android apk. I have one error that is unresolved. I have a function, int getFeedLength(). It has to catch an exception, and returns a null.

Every time I return a null (replacing it with anything else fails), the Android build fails, and I have looked at a lot of online resources to no avail.

Is there an alternate way to return null, or something else that will allow the build to proceed? I tried float and double, and they all resulted in other types of errors.

Here is the function, if need be, I can share the entire processing sketch:

int getFeedLength() {
    int result;
    String response = loadStrings(BASE_URL + APIKEY)[0];

    if (response != null) {
        try {
            JSONObject root = new JSONObject(response);
            JSONArray feeds = root.getJSONArray("feeds");
            result = feeds.length();
            println("number of feed entries: " + result);
            return result;
        }

        catch (JSONException e) {
            throw new Exception("Unable to perform action such an such");
            return null;
        }
    }

}

Here is the error:

C:\Users\SYAMAN~1\AppData\Local\Temp\android3618104784291490945.pde\src\changethispackage\beforesubmitting\tothemarket\app\app.java:248: incompatible types
[javac] found   : <nulltype>
[javac] required: int
[javac] return null;
1
  • Which exact line is 248? Commented Mar 6, 2012 at 8:15

2 Answers 2

1

Instead of return null write return 0 cause you have set return type to int returning 0 will be more comfortable at the end to know that is there any feeds or not.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello Soni, if I return zero, I get errors suggesting the catch is not working. Thanks!
0

Have you try to make the returning type of the getFeedLength() method a Integer? Something like this:

Integer getFeedLength() {

Hpe it helps.

1 Comment

Hello, I tried that, it did not help. When I use integer, I get an error for every line in the function. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.