Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Cannot Find Symbol (checked all obvious problems)
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
KingGrumpz




PostPosted: Fri Jan 11, 2013 5:55 pm   Post subject: Cannot Find Symbol (checked all obvious problems)

Can someone tell why I keep getting a "Cannot find symbol" error in the code below

Java:

import java.util.Scanner;
import java.io.File;
import javax.swing.JOptionPane;
import javax.media.Player;
import javax.media.Manager;

public class Mp3Player
{

   public static void main (String[] args)throws Exception // what's going on here?
   {
      Scanner input = new Scanner (System.in);

      do
      {
      String [] menuList = {"Mercy", "1 Train", "I Don't Like", "Somebody That I Used to Know","Exit"};
      Object songName = JOptionPane.showInputDialog(null,"What is the name of the song\n you want to hear? (Include .mp3 after name)", "MP3 Player", JOptionPane.QUESTION_MESSAGE,null,menuList,menuList[0]);
      String fileName = "";
      String Repeat = "";
      int x = 0;

      if (songName == "Mercy")
      fileName = "Mercy.mp3";
      else if (songName == "1 Train")
      fileName = "1 Train.mp3";
      else if (songName == "I Don't Like")
      fileName = "I Don't Like.mp3";
      else if (songName == "Somebody That I Used to Know")
      fileName = "Somebody That I Used to Know.mp3";
      else
      System.exit(0);
      playMp3File(fileName);

      int RepeatOption = JOptionPane.showConfirmDialog(null,"Would you like to Repeat?");
      if (RepeatOption == JOptionPane.YES_OPTION)
      {
      Repeat = "Yes";
      x=1;
      }
      else if (RepeatOption == JOptionPane.NO_OPTION)
      {
      Repeat = "No";
      x=2;
      }
      else if (RepeatOption == JOptionPane.CANCEL_OPTION)
      {
      Repeat = "Cancel";
      x=1;
      }

      }while (x != 2);

      System.out.print("\n\nHit 'Enter' to end...");
      System.in.read(); System.in.read();
      input.close();
   }

   private static void playMp3File (String fileNameDotMp3)
   {
      try
      {
         Player myMp3File = Manager.createPlayer(new File(fileNameDotMp3).toURI().toURL());
         myMp3File.start();
         Thread.sleep(30000);
         myMp3File.stop();
         myMp3File.close();
      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
   }

}


Mod Edit:

Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
code:

[syntax="java"] ... code ... [/syntax]

[code] ... code ... [/code ]
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Fri Jan 11, 2013 6:03 pm   Post subject: RE:Cannot Find Symbol (checked all obvious problems)

What symbol can it not find, and on what line is the error?
KingGrumpz




PostPosted: Fri Jan 11, 2013 7:29 pm   Post subject: Re: Cannot Find Symbol (checked all obvious problems)

}while (x != 2);
^
symbol: variable x
location: class Mp3Player
1 error
Insectoid




PostPosted: Fri Jan 11, 2013 7:48 pm   Post subject: RE:Cannot Find Symbol (checked all obvious problems)

Where are you declaring x?
KingGrumpz




PostPosted: Sat Jan 12, 2013 8:27 am   Post subject: Re: Cannot Find Symbol (checked all obvious problems)

Line 21 (int x = 0; )
Insectoid




PostPosted: Sat Jan 12, 2013 8:42 am   Post subject: RE:Cannot Find Symbol (checked all obvious problems)

Do you think there might be a better place to declare it?
KingGrumpz




PostPosted: Sat Jan 12, 2013 3:04 pm   Post subject: Re: Cannot Find Symbol (checked all obvious problems)

I have declared it in multiple places. none worked.
Dreadnought




PostPosted: Sat Jan 12, 2013 3:47 pm   Post subject: Re: Cannot Find Symbol (checked all obvious problems)

Do you understand why the following will not work?
code:
int x = 0;
while (x != 1) {
    int x = 1;
}
Sponsor
Sponsor
Sponsor
sponsor
KingGrumpz




PostPosted: Sun Jan 13, 2013 10:00 am   Post subject: Re: Cannot Find Symbol (checked all obvious problems)

I got fed up and just used a while(true), but thanks for the help.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: