Home > Java Help > Cannot Find Symbol Error using JOptionPane.showMessageDialog...

Cannot Find Symbol Error using JOptionPane.showMessageDialog...



The past few times I got this error it was basically something I typed incorrectly that was causing the error. I have looked and looked at these two bits of code but I am unable to find what is wrong.



Error 1:

F:\ClassAverageAJP.java:19: cannot find symbol

symbol : method showMessageDialog(<nulltype>,java.lang.String,int)

location: class javax.swing.JOptionPane

JOptionPane.showMessageDialog(null, "This program will ask the names and test scores"




Code:


JOptionPane.showMessageDialog(null, "This program will ask the names and test scores"
+ "of 5 students. \n It will then calculate the grade of each student. All of this"
+ "information \n will be placed in a file of your specification. Once all of the"
+ "grades have \n been entered, the program will calculate the class average and"
+ " place it in the file.", JOptionPane.INFORMATION_MESSAGE);








Error 2:

F:\ClassAverageAJP.java:50: cannot find symbol

symbol : method showMessageDialog(<nulltype>,java.lang.String,int)

location: class javax.swing.JOptionPane

JOptionPane.showMessageDialog(null, "Each student's average score has been calculated "




Code:


JOptionPane.showMessageDialog(null, "Each student's average score has been calculated "
+ "\nalong with their appropriate grade. The class average has also been calculated."
+ "\nThe results can be found in this file: " + outputFileName + ".txt",
JOptionPane.INFORMATION_MESSAGE);






Any help is greatly appreciated.

Thanks.

    
Guest
Best Answer


The arguments you're giving don't quite match what's required by ?a rel=nofollow href="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showMessageDialog(java.awt.Component, java.lang.Object, java.lang.String, int)" target="_blank">the method you're probably trying to use - you're missing the Title (java.lang.String) parameter.




Code:


public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType)
throws HeadlessException








("Cannot find symbol" doesn't just mean that you've typoed the name of something, but it could be that there's no method which takes the number/type of arguments you've given)

Was this answer helpful ? Yes No   
Guest


There is no showMessageDialog() method for JOptionPane that takes three arguments (i.e., null, String, and int).



~

Was this answer helpful ? Yes No   
Guest


Bah, I completely forgot the boxTitleString parameter. Thanks for pointing that out!(yet another easy fix ). Seems like there is always something I just can't find.



Thanks again.

Was this answer helpful ? Yes No   
Guest
Me too getting same error .. can anyone help..

Contact1.java:175: cannot find symbol
symbol : method showMessageDialog(<nulltype>,java.lang.String,int)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(null,"Enter the Details",1);
Was this answer helpful ? Yes No   
MNSP
HEY HAVE U TYPED THE IMPORT STATEMENTS,
import javax.swing.*;
import java.lang.*;
in your program??
if not, try this out.
Was this answer helpful ? Yes No   
rami
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2010 by Infoqu. All rights reserved