Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Coding the Fun Facts Using an Array

Daniel Cadwell
Daniel Cadwell
400 Points

Why am I getting the following error: if (bestSport instanceof String && bestSport == sports[0])

I am trying to access data that is in a String Array and assign it to a String Variable. my code looks like this: String V1 = V2[0]; and I keep getting this error: if (bestSport instanceof String && bestSport == sports[0])

Array.java
String[] sports = { "Basketball", "Baseball", "Tennis" };
Jordan Ernst
Jordan Ernst
5,121 Points

hey friend i hope this code will help you out: to access the data in the string array you need to remember that each element is referred to by it's place value. ie. (1st=0, 2nd=1, 3rd=2) in the question it asks you to declare bestSport as a string and assign it to the value of the first elemnt in the array. -----> String bestSport= sports[0];

Daniel Cadwell
Daniel Cadwell
400 Points

Thanks Jordon; I thought so it has to be on the sites end because that is what I have been trying and keep getting the big Bummer. I am a senior at cSU monterrey Bay in computer science....just plowing through these to do a project in android studio which I have never used,,,

Daniel Cadwell
Daniel Cadwell
400 Points

Thanks Jordon; I thought so it has to be on the sites end because that is what I have been trying and keep getting the big Bummer. I am a senior at cSU monterrey Bay in computer science....just plowing through these to do a project in android studio which I have never used,,,

1 Answer

String[] sports = { "Basketball", "Baseball", "Tennis" }; String bestSport = sports[0]; int numberOfSports = sports.length; String lastSport = sports[sports.length-1];