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 Build a Simple Android App (2014) Coding the Fun Facts Using an Array

James Ward
James Ward
1,787 Points

Stuck with conversion of String to Int

I think I know what the problem is, but not how to fix it, My result is a string and the object (?) is an int.

Heres the error;

JavaTester.java:42: error: cannot find symbol int numberOfSports = bestSport.nextInt(sports.length); ^ symbol: method nextInt(int) location: variable bestSport of type String 1 error

I tried a few things, but the challenges are quite finicky for exact syntax so googling and using parseInt etc obviously doesnt work :)

Thanks team appreciate the help

Array.java
String[] sports = {
  "Basketball",
  "Baseball",
  "Tennis"};

String bestSport = sports[0];

int numberOfSports = bestSport.nextInt(sports.length);

2 Answers

Axel McCode
Axel McCode
13,869 Points
//My guess is that you are initializing the variable numberOfSports
// to the number of sports in your sports array, in this case you would
// not need to have bestSport.nextInt(Sports.length)


String[] sports = {
  "Basketball",
  "Baseball",
  "Tennis"};

String bestSport = sports[0];

int numberOfSports = sports.length;

Hope this helps :)

James Ward
James Ward
1,787 Points

Thanks Axel, that worked a treat

Axel McCode
Axel McCode
13,869 Points

You're very welcome, glad I could help out!