Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

(color) is an error?

I got the Fun Facts app from GitHub as the video showed and now I'm getting an error when I hover over (color). This is the end of the code:

color = mColors[randomNumber];
        int colorAsInt = Color.parseColor(color);

        return colorAsInt;
    }

This is what it says: "Length must be at least 1 (was 0) less... (⌘F1) This inspection looks at Android API calls that have been annotated with various support annotations (such as RequiresPermission or UiThread) and flags any calls that are not using the API correctly as specified by the annotations. Examples of errors flagged by this inspection: Passing the wrong type of resource integer (such as R.string) to an API that expects a different type (such as R.dimen). Forgetting to invoke the overridden method (via super) in methods that require it Calling a method that requires a permission without having declared that permission in the manifest Passing a resource color reference to a method which expects an RGB integer value. ...and many more. "

What does this mean and how can I fix it?

4 Answers

Harrison Court
Harrison Court
4,232 Points

Since I haven't gotten to far with the fun facts app code, I can't really help you. But I recommend and going back to the course again and see if anythings different.

The code is the same as what I imported from GitHub, which is why the error is so weird. Thanks for your response though!

Harrison Court
Harrison Court
4,232 Points

What version of android studio are you using, and what level API?

Android studio 2.2.1 and API 23, I think. I'm super new at this, hence the beginner lessons. I'm having a hard time figuring out what to do on my own.

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Try taking out:

String color = "";

And instead just declaring 'color' right here:

String color = mColors[randomNumber];

Weirdly, the compiler sees 'color' being set to an empty String, and it then sees 'color' being used as a parameter in 'parseColor'. So it gets upset about the possibility of calling 'parseColor' on an empty String. But what the compiler doesn't know, is that 'color' will always be overridden by 'mColors[randomNumber]'. And so strangely, the code runs just fine.

Harrison Court
Harrison Court
4,232 Points

Hey ben, I'm having trouble myself, an error occurs that stats "Cannot resolve symbol mShowFactButton". I got the full complaint Here.

That totally worked! Thank you!