Author |
Message |
KingGrumpz
|
Posted: 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 ]
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
KingGrumpz
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Fri Jan 11, 2013 7:48 pm Post subject: RE:Cannot Find Symbol (checked all obvious problems) |
|
|
Where are you declaring x? |
|
|
|
|
![](images/spacer.gif) |
KingGrumpz
|
Posted: Sat Jan 12, 2013 8:27 am Post subject: Re: Cannot Find Symbol (checked all obvious problems) |
|
|
Line 21 (int x = 0; ) |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
KingGrumpz
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: 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;
} |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
KingGrumpz
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|