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

Java

Incompatible Types: song is not a string and will not work with prompt action.

My code:

package com.teamtreehouse;

import com.teamtreehouse.model.Song;
import com.teamtreehouse.model.SongBook;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;


public class KaraokeMachine {
    private SongBook mSongBook;
    private BufferedReader mReader;
    private Map<String, String> mMenu;

    public KaraokeMachine(SongBook songBook) {
        mSongBook = songBook;
        mReader = new BufferedReader(new InputStreamReader(System.in));
        mMenu = new HashMap<String, String>();
        mMenu.put("add", "Add a new song to the song book");
        mMenu.put("quit", "Give up.  Exit the program");
    }

    private String promtAction() {
    System.out.printf("There are %d songs available. Your options are:  %n",
                                     mSongBook.getSongCount()); 
                for (Map.Entry<String, String> option : mMenu.entrySet()) {
                System.out.printf("%s - %s %n",
                                                 option.getKey(),
                                                 option.getValue());    
                }
                System.out.print("What do you want to do:  ");
                String choice = mReader.readLine();
                return choice.trim().toLowerCase();
}
  public void run() {
    String choice = ""; 
        do {
            try {
            choice = promtAction();
                switch(choice) {
                case "add":
                Song song = promtAction();
                mSongBook.addSong(song);
                System.out.printf("%s added! %n%n", song);
                break;
                case "quit": 
                System.out.println("Thanks for playing!");
                break;
                default:
                System.out.printf("Unknown choice:  '%s'. Try again. %n%n%n",
                                                 choice);
            }
            } catch(IOException ioe) {
                System.out.println("Problem with input");
                ioe.printStackTrace();
            }
        }while (!choice.equals("quit"));
        }
        private Song promptNewSong() {
            System.out.print("Enter the artist's name:  ");
            String artist = mReader.readLine();
            System.out.print("Enter the Title: ");
            String title = mReader.readLine();
            System.out.print("Enter the video URL:  ");
            String videoUrl = mReader.readLine();
            return new Song(artist, title, videoUrl);
        }
    }

My error:

./com/teamtreehouse/KaraokeMachine.java:45: error: incompatible types: String cannot be converted to Song
Song song = promtAction();
^
1 error

1 Answer

Well it's just as the error says it. Song is not a string. And the method promptAction returns a string. Therefore you cannot assign it to a Song variable. Try looking through your code. Which method returns a song? Try using it. Does it work? WHY? Make sure you can answer those questions clearly. It's one to type what Craig's typing and other to actually understand what you are doing. Make sure to ask again if anything is not clear :)

Hey, Thanks for your reply. I understand that song is a variable that is incompatible with promptAction. I went through my code and asked those questions and there is not a variable that returns a song. In my understanding there is a variable that returns a new song but not a song. I tried that variable just in case and only got four extra errors along with this one. I'm really trying to understand and not just type what Craig is typing. Any help you could offer to help me complete this task would be awesome. =)

Hey I just went through the videos again and noticed somethings that I missed. Thanks again.=)

So it's all good now?

Just one more thing - you said "there is not a variable that returns a song". Variables do not return anything. They just store data. Methods are the ones that return something.