Another DiveLog can't resolve symbol error
I am using NetBeans to go through the DiveLog tutorial, which I have first typed, then cut/pasted in (hence I've not included it here). On compilation I get the following error:
divelog/DiveLog.java [41:1] cannot resolve symbol
symbol : method addTab (java.lang.String,<nulltype>,divelog.Welcome,java.lang.String)
location: class javax.swing.JTabbedPane
tabbedPane.addTab("Welcome",
^
1 error
Errors compiling divelog (->).
The rest of the line looks like this:
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
(Note that I have cut out all the other tabs, just to focus the mind)
As I am sure you expect if I set the component parameter to null (rather than new Welcome()) it compiles just fine.
I have read the troubleshooting tips on the tutorial, and understand that I am not compiling the whole package, but as far as I know I am! I highlight the package and compile all, I have compiled the project, and both with the same result. I have also read many, many newsgroup entries on the same subject and I have been trying all the various solutions for the last two days.
I note that whilst the others have an error that points to Welcome, the error message I get is on the symbol addTab.
I get the same error if I javac it too. (from the Divelog directory I typed javac -classpath d:\java\myjava\ DiveLog.java, and also tried setting a CLASSPATH environmental variable)
I have my path (environmental variable) set to: d:\java\j2sdk_nb\j2sdk1.4.2\bin
I have also set CLASSPATH to d:\java\myJava
Please remember the pain of newbie!
Thanks, Myles
PS I am working in Windows XP
The compiler is saying that in the JTabbedPane class, there is no method that takes a String, a null, a divelog.Welcome, and another String as parameters. I am guessing that in the divelog.Welcome class source code, you are missing something like the bolded text below.
public class Welcome extends JPanel
I'm making this guess because the JTabbedPane needs a Component for the third argument. If you still can't make sense of this, post the page of the tutorial so we can look at it.
Similar Messages
-
Error in Hashtable put method-Can not resolve symbol
Hi there!I am new to using java.util.Hashtable.
I am using it for a command line instant messaging program for holding the list of clients and list of client names currently connected to the server.
However when I compile my server with the command javac server.java it seems to give errors can not resolve symbol method put (java.lang.object,int).
Here is my code for my server:
* @(#)server.java
* @author
* @version 1.00 2008/3/22
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
public class server {
static int key1=0;
static Hashtable nameHolder=new Hashtable();
//static ArrayList nameHolder=new ArrayList();
//static ArrayList clientsConnected =new ArrayList();
static Hashtable clientsConnected =new Hashtable();
public static void main(String[] args) throws IOException {
//nameHolder.add("controlelement");
Socket connect=null;
String name =null;
PrintWriter out=null;
BufferedReader in =null;
String machinename;
int port=0;
ServerSocket serverSocket = null;
serverSocket = new ServerSocket(2222);
boolean listeningports = true;
try {
if(args.length > 0)
port = Integer.parseInt(args[0]);
System.out.println(port);
else
System.out.println("You must enter port number");
System.exit(1);
while(true)
System.out.println("Hakan");
connect=serverSocket.accept();
in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
System.out.println("Hakan");
String girdi = in.readLine();
StringTokenizer nameAl=new StringTokenizer(girdi);
String ad=null;
String host=null;
int portofclient=0;
int m=0;
while(nameAl.hasMoreTokens())
if(m==0)
ad=nameAl.nextToken();
System.out.println("Adim"+ad);
else if(m==1)
host=nameAl.nextToken();
System.out.println("Hostum"+host);
else if(m==2)
portofclient = Integer.parseInt(nameAl.nextToken());
System.out.println("Listening portum"+portofclient);
break;
m++;
out = new PrintWriter(connect.getOutputStream(), true);
System.out.println("Haso");
if(!isUsed(ad))
System.out.println(girdi);
System.out.println("H�so");
//Object fason=(Object)ad;
nameHolder.put(key1,ad);
//The error seems to occur here
client myclient=new client(ad,host,portofclient);
//Object garson=(Object)myclient;
clientsConnected.put(key1,myclient);
key1++;
//clientInfoHolder.add(girdi);
out.println("Kullanımda");
System.out.println("Haso");
new MultiClientManager(connect).start();
else
//System.out.println("kulanilmaz");
out.println("Kullanim disi");
catch(Exception e)
System.out.println("You did not specify port number");
System.out.println("Or connection was not established due to specifying invalid or used port");
e.printStackTrace();
public static boolean isUsed( String name )
if( nameHolder.containsValue(name) )
return true;
return false;
public static client Ask(String name)
ArrayList lombak=(ArrayList) clientsConnected.values();
for(int i=0;i<lombak.size();i++)
client semsi = (client)lombak.get(i);
if(semsi.nickname.compareTo(name)==0)
return semsi;
return null;
public static int returnkeyoffromclients(String name)
ArrayList lombak=(ArrayList)clientsConnected.values();
for(int i=0;i<lombak.size();i++)
client semsi = (client)lombak.get(i);
if(semsi.nickname.compareTo(name)==0)
return i;
return 0;
public static int returnkeyoffromnames(String name)
ArrayList lombak=(ArrayList)nameHolder.values();
for(int i=0;i<lombak.size();i++)
String semsi = lombak.get(i).toString();
if(semsi.compareTo(name)==0)
return i;
return 0;
}Excuse me for not putting my code between tags. I am just sleepless.
I am sending it again.
* @(#)server.java
* @author
* @version 1.00 2008/3/22
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
public class server {
static int key1=0;
static Hashtable nameHolder=new Hashtable();
//static ArrayList nameHolder=new ArrayList();
//static ArrayList clientsConnected =new ArrayList();
static Hashtable clientsConnected =new Hashtable();
public static void main(String[] args) throws IOException {
//nameHolder.add("controlelement");
Socket connect=null;
String name =null;
PrintWriter out=null;
BufferedReader in =null;
String machinename;
int port=0;
ServerSocket serverSocket = null;
serverSocket = new ServerSocket(2222);
boolean listeningports = true;
try {
if(args.length > 0)
port = Integer.parseInt(args[0]);
System.out.println(port);
else
System.out.println("You must enter port number");
System.exit(1);
while(true)
System.out.println("Hakan");
connect=serverSocket.accept();
in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
System.out.println("Hakan");
String girdi = in.readLine();
StringTokenizer nameAl=new StringTokenizer(girdi);
String ad=null;
String host=null;
int portofclient=0;
int m=0;
while(nameAl.hasMoreTokens())
if(m==0)
ad=nameAl.nextToken();
System.out.println("Adim"+ad);
else if(m==1)
host=nameAl.nextToken();
System.out.println("Hostum"+host);
else if(m==2)
portofclient = Integer.parseInt(nameAl.nextToken());
System.out.println("Listening portum"+portofclient);
break;
m++;
out = new PrintWriter(connect.getOutputStream(), true);
System.out.println("Haso");
if(!isUsed(ad))
System.out.println(girdi);
System.out.println("H�so");
//Object fason=(Object)ad;
nameHolder.put(key1,ad);
client myclient=new client(ad,host,portofclient);
//Object garson=(Object)myclient;
clientsConnected.put(key1,myclient);
key1++;
//clientInfoHolder.add(girdi);
out.println("Kullanımda");
System.out.println("Haso");
new MultiClientManager(connect).start();
else
//System.out.println("kulanilmaz");
out.println("Kullanim disi");
catch(Exception e)
System.out.println("You did not specify port number");
System.out.println("Or connection was not established due to specifying invalid or used port");
e.printStackTrace();
public static boolean isUsed( String name )
if( nameHolder.containsValue(name) )
return true;
return false;
public static client Ask(String name)
ArrayList lombak=(ArrayList) clientsConnected.values();
for(int i=0;i<lombak.size();i++)
client semsi = (client)lombak.get(i);
if(semsi.nickname.compareTo(name)==0)
return semsi;
return null;
public static int returnkeyoffromclients(String name)
ArrayList lombak=(ArrayList)clientsConnected.values();
for(int i=0;i<lombak.size();i++)
client semsi = (client)lombak.get(i);
if(semsi.nickname.compareTo(name)==0)
return i;
return 0;
public static int returnkeyoffromnames(String name)
ArrayList lombak=(ArrayList)nameHolder.values();
for(int i=0;i<lombak.size();i++)
String semsi = lombak.get(i).toString();
if(semsi.compareTo(name)==0)
return i;
return 0;
These are the lines that are responsible from the error.
nameHolder.put(key1,ad);
client myclient=new client(ad,host,portofclient);
//Object garson=(Object)myclient;
clientsConnected.put(key1,myclient); -
Cannot resolve symbol error even with class imported
Hi
I'm trying to print out a java.version system property but keep getting a
cannot resolve symbol error
symbol: class getProperty
location: class java.lang.System
I've looked at the API and getProperty() is a method of lang.System
Can anyone throw any light?
thanks
import java.lang.System;
class PropertiesTest {
public static void main(String[] args) {
String v = new System.getProperty("java.version");
System.out.println(v);
}Thanks Jos
It compiles but I now get a runtime error
Exception in thread "main"
java.lang.NoClassDefFoundError:PropertiesTest
What do you reckon is the problem?
thanks
java -cp .;<any other directories or jars>
YourClassNameYou get a NoClassDefFoundError message because the
JVM (Java Virtual Machine) can't find your class. The
way to remedy this is to ensure that your class is
included in the classpath. The example assumes that
you are in the same directory as the class you're
trying to run.I know it's a bad habit but I've put this file (PropertiesTest.java) and the compiled class (PropertiesTest.class) both in my bin folder which contains the javac compiler -
Help.. incompatiable type and cannot resolve symbol error...
I have this class Box
class Box{
private int width;
private int height;
private int depth;
private int BoxCounter;
public void click()
BoxCounter = 0;
}and in my main code, I'm calling it via
private Box arrBox[];All this goes fine until I try to place code in to make array empty upon a selected action by
if (color == blue) {arrBox = new Box();}Here I'm getting the error saying that its an incompatible type... it says I have Box but it requires class Box[]...(the ^ pointing at the word "new")
also, I have this
public void button()
arrBox.click()
}This returns the unable to resolve symbol error (the ^ points at the dot).... I tried changing things around but the problem persists, can someone point out where I hv gone wrong?
Many thanksprivate Box arrBox[];The line above does not create an array, it only declares that the variable arrBox can refernce an array of type Box. Arrays are objects just like Box - you need a new Box[10], for example, to create the array.
if (color == blue) {arrBox = new Box();}
Here I'm getting the error saying that its an
incompatible type... it says I have Box but it
requires class Box[]...(the ^ pointing at the word
"new")As previously stated, arrBox is a reference to an array of Box, not an object instance of Box.
A lot of your trouble can be resolved by understanding how arrays work in java. Try here.
http://java.sun.com/docs/books/tutorial/java/data/arrays.html
You must create an array similar to creating any object. Next, you must create objects to go inside the array. It's difficult without knowing the rest of your code, but here goes.
private Box[] arrBox = new Box[10];
for(int index=0;index<arrBox.length;index++) {
int color = getColor(index); //I'm making this up
if(color == blue) arrBox[index] = new Box();
}The above code will create a new Box for any index where the color is blue. The indices where the color isn't blue are equal to null. -
Cannot find package error and cannot resolve symbol error
Hi
I have a file Assignment.java in C:\TIJCode\c03 folder. But this file belongs to the default package. This file imports a package com.bruceeckel.simpletest which is in C:\TIJCode\ folder. Now this package has a file named Test.java which accesses a few more files fromt he same package.
I set the classpath to C:\TIJCode. When i try to run the Assignment file I get an error saying package com.bruceeckel.simpletest cannot be found and cannot resolve symbol error. symbol: Test Class: Assignment.
The files in com.bruceeckel.simpletest package were not compiled. So I first tried to do that. But I get a cannot resolve symbol error while trying to compile a file NumOfLinesException which inherits SImpleTestException file. The exact error message is
NumOfLinesException.java : 7 : cannot resolve symbol
symbol : class SimpleTestException
location : class com.bruceeckel.simpletest.NumOfLinesException extends SimpleTestException
The exact code in each of above mentioned files is
//: c03:Assignment.java
// Assignment with objects is a bit tricky.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import com.bruceeckel.simpletest.*;
class Number {
int i;
public class Assignment {
static Test monitor = new Test();
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
n1.i = 9;
n2.i = 47;
System.out.println("1: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1 = n2;
System.out.println("2: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1.i = 27;
System.out.println("3: n1.i: " + n1.i +
", n2.i: " + n2.i);
monitor.expect(new String[] {
"1: n1.i: 9, n2.i: 47",
"2: n1.i: 47, n2.i: 47",
"3: n1.i: 27, n2.i: 27"
} ///:~
//: com:bruceeckel:simpletest:SimpleTestException.java
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package com.bruceeckel.simpletest;
public class SimpleTestException extends RuntimeException {
public SimpleTestException(String msg) {
super(msg);
} ///:~
//: com:bruceeckel:simpletest:NumOfLinesException.java
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package com.bruceeckel.simpletest;
public class NumOfLinesException extends SimpleTestException {
public NumOfLinesException(int exp, int out) {
super("Number of lines of output and "
+ "expected output did not match.\n" +
"expected: <" + exp + ">\n" +
"output: <" + out + "> lines)");
} ///:~
//: com:bruceeckel:simpletest:Test.java
// Simple utility for testing program output. Intercepts
// System.out to print both to the console and a buffer.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package com.bruceeckel.simpletest;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class Test {
// Bit-shifted so they can be added together:
public static final int
EXACT = 1 << 0, // Lines must match exactly
AT_LEAST = 1 << 1, // Must be at least these lines
IGNORE_ORDER = 1 << 2, // Ignore line order
WAIT = 1 << 3; // Delay until all lines are output
private String className;
private TestStream testStream;
public Test() {
// Discover the name of the class this
// object was created within:
className =
new Throwable().getStackTrace()[1].getClassName();
testStream = new TestStream(className);
public static List fileToList(String fname) {
ArrayList list = new ArrayList();
try {
BufferedReader in =
new BufferedReader(new FileReader(fname));
try {
String line;
while((line = in.readLine()) != null) {
if(fname.endsWith(".txt"))
list.add(line);
else
list.add(new TestExpression(line));
} finally {
in.close();
} catch (IOException e) {
throw new RuntimeException(e);
return list;
public static List arrayToList(Object[] array) {
List l = new ArrayList();
for(int i = 0; i < array.length; i++) {
if(array[i] instanceof TestExpression) {
TestExpression re = (TestExpression)array;
for(int j = 0; j < re.getNumber(); j++)
l.add(re);
} else {
l.add(new TestExpression(array[i].toString()));
return l;
public void expect(Object[] exp, int flags) {
if((flags & WAIT) != 0)
while(testStream.numOfLines < exp.length) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
List output = fileToList(className + "Output.txt");
if((flags & IGNORE_ORDER) == IGNORE_ORDER)
OutputVerifier.verifyIgnoreOrder(output, exp);
else if((flags & AT_LEAST) == AT_LEAST)
OutputVerifier.verifyAtLeast(output,
arrayToList(exp));
else
OutputVerifier.verify(output, arrayToList(exp));
// Clean up the output file - see c06:Detergent.java
testStream.openOutputFile();
public void expect(Object[] expected) {
expect(expected, EXACT);
public void expect(Object[] expectFirst,
String fname, int flags) {
List expected = fileToList(fname);
for(int i = 0; i < expectFirst.length; i++)
expected.add(i, expectFirst[i]);
expect(expected.toArray(), flags);
public void expect(Object[] expectFirst, String fname) {
expect(expectFirst, fname, EXACT);
public void expect(String fname) {
expect(new Object[] {}, fname, EXACT);
} ///:~What do you have in the C:\TIJCode\ directory? Does the directory structure mimic the package structure for the stuff you're importing?
-
Cannot resolve symbol error when compiling a class that calls another class
I've read all the other messages that include "cannot resolve symbol", but no luck. I've got a small app - 3 classes all in the same package. BlackjackDAO and Player compile OK, but BlackjackServlet throws the "cannot resolve symbol" (please see pertinent code below)...
I've tried lots: ant and javac compiling, upgrading my version of tomcat, upgrading my version of jdk/jre, making sure my servlet.jar is being seen by the compiler (at least as far as I can see from the -verbose feedback)...any help would be GREAT! Thanks in advance...
classes: BlackjackServlet, BlackjackDAO, Player
package: myblackjackpackage
tomcat version: 4.1.1.8
jdk version: j2sdk 1.4.0
ant version: 1.4.1
I get the same error message from Ant and Javac...
C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage>javac *.java -verbose
C:\Tomcat4118\src\webapps\helloblackjack>ant all -verbose
compile error:
BlackjackServlet.java:55: cannot resolve symbol
symbol: method addPlayer (javax.servlet.http.HttpServletRequest,javax.servlet.http.Http
ServletResponse)
location: class myblackjackpackage.BlackjackServlet
addPlayer(request, response);
^
My code is:
package myblackjackpackage;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.lang.*;
/** controller servlet in a web based blackjack game application @author Ethan Harlow */
public class BlackjackServlet extends HttpServlet {
private BlackjackDAO theBlackjackDAO;
public void init() throws ServletException {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433";
String userid = "testlogin";
String passwrd = "testpass";
try {
theBlackjackDAO = new BlackjackDAO(driver, dbUrl, userid, passwrd);
catch (IOException exc) {
System.err.println(exc.toString());
catch (ClassNotFoundException cnf) {
System.err.println(cnf.toString());
catch (SQLException seq) {
System.err.println(seq.toString());
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String command = request.getParameter("command");
if (command == null || (command.equals("stats"))) {
else if (command.equals("add")) {
try {
//the following line is caught by compiler
addPlayer(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<p>Hi, your command was " + request.getParameter("command") + "!!!</p>");
out.println("</body>");
out.println("</html>");
catch (Exception exc) {
System.err.println(exc.toString());
else if (command.equals("play")) {
else if (command.equals("bet")) {
else if (command.equals("hit")) {
else if (command.equals("stand")) {
else if (command.equals("split")) {
else if (command.equals("double")) {
else if (command.equals("dealerdecision")) {
else if (command.equals("reinvest")) {
else if (command.equals("changebet")) {
else if (command.equals("deal")) {
package myblackjackpackage;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.lang.*;
public class BlackjackDAO {
private Connection myConn;
public BlackjackDAO(String driver, String dbUrl, String userid, String passwrd)
throws IOException, ClassNotFoundException, SQLException {
System.out.println("Loading driver: " + driver);
Class.forName(driver);
System.out.println("Connection to: " + dbUrl);
myConn = DriverManager.getConnection(dbUrl, userid, passwrd);
System.out.println("Connection successful!");
public void addPlayer(HttpServletRequest request, HttpServletResponse response)
throws IOException, SQLException {
//I've commented out all my code while debugging, so I didn't include
//any here
compiler feedback
C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage>javac *.java -verbose
[parsing started BlackjackDAO.java]
[parsing completed 90ms]
[parsing started BlackjackServlet.java]
[parsing completed 10ms]
[parsing started Player.java]
[parsing completed 10ms]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/Object.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/sql/Connection.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/String.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/IOException.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/ClassNotFoundException.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/sql/SQLException.class)]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/http/HttpServletRequ
est.class)]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/http/HttpServletResp
onse.class)]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/http/HttpServlet.cla
ss)]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/GenericServlet.class
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/Servlet.class)]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/ServletConfig.class)
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/Serializable.class)]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/ServletException.cla
ss)]
[checking myblackjackpackage.BlackjackDAO]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/Throwable.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/Exception.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/System.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/PrintStream.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/FilterOutputStream.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/OutputStream.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/Class.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/sql/DriverManager.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/util/Properties.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/Error.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/RuntimeException.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/lang/StringBuffer.class)]
[wrote BlackjackDAO.class]
[checking myblackjackpackage.BlackjackServlet]
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/ServletRequest.class
BlackjackServlet.java:55: cannot resolve symbol
symbol : method addPlayer (javax.servlet.http.HttpServletRequest,javax.servlet
.http.HttpServletResponse)
location: class myblackjackpackage.BlackjackServlet
addPlayer(request, response);
^
[loading c:\tomcat4118\common\lib\servlet.jar(javax/servlet/ServletResponse.clas
s)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/PrintWriter.class)]
[loading c:\j2sdk14003\jre\lib\rt.jar(java/io/Writer.class)]
[checking myblackjackpackage.Player]
[total 580ms]
1 error
C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage>
and here's the ant feedback...
C:\Tomcat4118\src\webapps\helloblackjack>ant all -verbose
Ant version 1.4.1 compiled on October 11 2001
Buildfile: build.xml
Detected Java version: 1.4 in: c:\j2sdk14003\jre
Detected OS: Windows 2000
parsing buildfile C:\Tomcat4118\src\webapps\helloblackjack\build.xml with URI =
file:C:/Tomcat4118/src/webapps/helloblackjack/build.xml
Project base dir set to: C:\Tomcat4118\src\webapps\helloblackjack
Build sequence for target `all' is [clean, prepare, compile, all]
Complete build sequence is [clean, prepare, compile, all, javadoc, deploy, dist]
clean:
[delete] Deleting directory C:\Tomcat4118\src\webapps\helloblackjack\build
[delete] Deleting C:\Tomcat4118\src\webapps\helloblackjack\build\images\a_s.g
if
[delete] Deleting C:\Tomcat4118\src\webapps\helloblackjack\build\images\q_s.g
if
[delete] Deleting directory C:\Tomcat4118\src\webapps\helloblackjack\build\im
ages
[delete] Deleting C:\Tomcat4118\src\webapps\helloblackjack\build\index.html
[delete] Deleting C:\Tomcat4118\src\webapps\helloblackjack\build\newplayer.ht
ml
[delete] Deleting C:\Tomcat4118\src\webapps\helloblackjack\build\WEB-INF\clas
ses\myblackjackpackage\BlackjackDAO.class
[delete] Deleting directory C:\Tomcat4118\src\webapps\helloblackjack\build\WE
B-INF\classes\myblackjackpackage
[delete] Deleting directory C:\Tomcat4118\src\webapps\helloblackjack\build\WE
B-INF\classes
[delete] Deleting C:\Tomcat4118\src\webapps\helloblackjack\build\WEB-INF\web.
xml
[delete] Deleting directory C:\Tomcat4118\src\webapps\helloblackjack\build\WE
B-INF
[delete] Deleting directory C:\Tomcat4118\src\webapps\helloblackjack\build
prepare:
[mkdir] Created dir: C:\Tomcat4118\src\webapps\helloblackjack\build
[copy] images\a_s.gif added as C:\Tomcat4118\src\webapps\helloblackjack\bui
ld\images\a_s.gif doesn't exist.
[copy] images\q_s.gif added as C:\Tomcat4118\src\webapps\helloblackjack\bui
ld\images\q_s.gif doesn't exist.
[copy] index.html added as C:\Tomcat4118\src\webapps\helloblackjack\build\i
ndex.html doesn't exist.
[copy] newplayer.html added as C:\Tomcat4118\src\webapps\helloblackjack\bui
ld\newplayer.html doesn't exist.
[copy] WEB-INF\web.xml added as C:\Tomcat4118\src\webapps\helloblackjack\bu
ild\WEB-INF\web.xml doesn't exist.
[copy] omitted as C:\Tomcat4118\src\webapps\helloblackjack\build is up to
date.
[copy] images added as C:\Tomcat4118\src\webapps\helloblackjack\build\image
s doesn't exist.
[copy] WEB-INF added as C:\Tomcat4118\src\webapps\helloblackjack\build\WEB-
INF doesn't exist.
[copy] Copying 5 files to C:\Tomcat4118\src\webapps\helloblackjack\build
[copy] Copying C:\Tomcat4118\src\webapps\helloblackjack\web\images\q_s.gif
to C:\Tomcat4118\src\webapps\helloblackjack\build\images\q_s.gif
[copy] Copying C:\Tomcat4118\src\webapps\helloblackjack\web\images\a_s.gif
to C:\Tomcat4118\src\webapps\helloblackjack\build\images\a_s.gif
[copy] Copying C:\Tomcat4118\src\webapps\helloblackjack\web\index.html to C
:\Tomcat4118\src\webapps\helloblackjack\build\index.html
[copy] Copying C:\Tomcat4118\src\webapps\helloblackjack\web\newplayer.html
to C:\Tomcat4118\src\webapps\helloblackjack\build\newplayer.html
[copy] Copying C:\Tomcat4118\src\webapps\helloblackjack\web\WEB-INF\web.xml
to C:\Tomcat4118\src\webapps\helloblackjack\build\WEB-INF\web.xml
compile:
[mkdir] Created dir: C:\Tomcat4118\src\webapps\helloblackjack\build\WEB-INF\
classes
[javac] myblackjackpackage\BlackjackDAO.class skipped - don't know how to ha
ndle it
[javac] myblackjackpackage\BlackjackDAO.java added as C:\Tomcat4118\src\weba
pps\helloblackjack\build\WEB-INF\classes\myblackjackpackage\BlackjackDAO.class d
oesn't exist.
[javac] myblackjackpackage\BlackjackServlet.java added as C:\Tomcat4118\src\
webapps\helloblackjack\build\WEB-INF\classes\myblackjackpackage\BlackjackServlet
.class doesn't exist.
[javac] myblackjackpackage\Player.java added as C:\Tomcat4118\src\webapps\he
lloblackjack\build\WEB-INF\classes\myblackjackpackage\Player.class doesn't exist
[javac] Compiling 3 source files to C:\Tomcat4118\src\webapps\helloblackjack
\build\WEB-INF\classes
[javac] Using modern compiler
[javac] Compilation args: -d C:\Tomcat4118\src\webapps\helloblackjack\build\
WEB-INF\classes -classpath
"C:\Tomcat4118\src\webapps\helloblackjack\build\WEB-I
NF\classes;
C:\tomcat4118\common\classes;
C:\tomcat4118\common\lib\activation.jar;
C:\tomcat4118\common\lib\ant.jar;
C:\tomcat4118\common\lib\commons-collections.jar;
C:\tomcat4118\common\lib\commons-dbcp.jar;
C:\tomcat4118\common\lib\commons-logging-api.jar;
C:\tomcat4118\common\lib\commons-pool.jar;
C:\tomcat4118\common\lib\jasper-compiler.jar;
C:\tomcat4118\common\lib\jasper-runtime.jar;
C:\tomcat4118\common\lib\jdbc2_0-stdext.jar;
C:\tomcat4118\common\lib\jndi.jar;
C:\tomcat4118\common\lib\jta.jar;
C:\tomcat4118\common\lib\mail.jar;
C:\tomcat4118\common\lib\mysql_uncomp.jar;
C:\tomcat4118\common\lib\naming-common.jar;
C:\tomcat4118\common\lib\naming-factory.jar;
C:\tomcat4118\common\lib\naming-resources.jar;
C:\tomcat4118\common\lib\servlet.jar;
C:\tomcat4118\common\lib\tools.jar;
C:\j2sdk14003\lib\tools.jar;
C:\tomcat4118\ant141\lib\servlet.jar;
C:\tomcat4118\ant141\lib\jaxp.jar;
C:\tomcat4118\ant141\lib\crimson.jar;
C:\tomcat4118\ant141\lib\ant.jar;
C:\Tomcat4118\src\webapps\helloblackjack;
C:\mysql\jdbc_dvr\mm.mysql.jdbc-1.2c;
C:\Program Files\SQLserverjdbcdriver\lib\msbase.jar;
C:\Program Files\SQLserverjdbcdriver\lib\msutil.jar;
C:\Program Files\SQLserverjdbcdriver\lib\mssqlserver.jar"
-sourcepath C:\Tomcat4118\src\webapps\helloblackjack\src -g -O
[javac] Files to be compiled:
C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage\BlackjackDAO
.java
C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage\BlackjackSer
vlet.java
C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage\Player.java
[javac] C:\Tomcat4118\src\webapps\helloblackjack\src\myblackjackpackage\Blac
kjackServlet.java:55: cannot resolve symbol
[javac] symbol : method addPlayer (javax.servlet.http.HttpServletRequest,j
avax.servlet.http.HttpServletResponse)
[javac] location: class myblackjackpackage.BlackjackServlet
[javac] addPlayer(request, response);
[javac] ^
[javac] 1 error
BUILD FAILED
C:\Tomcat4118\src\webapps\helloblackjack\build.xml:212: Compile failed, messages
should have been provided.
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:559)
at org.apache.tools.ant.Task.perform(Task.java:217)
at org.apache.tools.ant.Target.execute(Target.java:184)
at org.apache.tools.ant.Target.performTasks(Target.java:202)
at org.apache.tools.ant.Project.executeTarget(Project.java:601)
at org.apache.tools.ant.Project.executeTargets(Project.java:560)
at org.apache.tools.ant.Main.runBuild(Main.java:454)
at org.apache.tools.ant.Main.start(Main.java:153)
at org.apache.tools.ant.Main.main(Main.java:176)
Total time: 1 second
C:\Tomcat4118\src\webapps\helloblackjack>yes!
early on i tried: BlackjackDAO.addPlayer(request, response);
instead of: theBlackjackDAO.addPlayer(request, response);
you rock - thanks a ton -
"cannot resolve symbol" error when using super.paintComponent
I am trying to override the paintComponent method in a class extending a JFrame, but when I call super.paintComponent(g) from inside the overridden method I get the error
QubicGUI.java:63: cannot resolve symbol
symbol : method paintComponent (java.awt.Graphics)
location: class javax.swing.JFrame
super.paintComponent(g);
^
1 error
I can't see where I am deviating from examples I know work. It is a very small program, so I have included it here:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.net.URL;
class QubicGUI extends JFrame
private int width;
private int height;
private Image background;
public int getWidth()
{ return width; }
public int getHeight()
{ return height; }
public boolean isOpaque()
return true;
public QubicGUI()
super("Qubic"); //set title
// The following gets the default screen device for the purpose of finding the
// current settings of height and width of the screen
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = environment.getDefaultScreenDevice();
DisplayMode display = device.getDisplayMode();
width = display.getWidth();
height = display.getHeight();
// Here we set the window to cover the entire screen with a black background, and
// remove the decorations. (This includes the title bar and close, minimize and
// maximize buttons and the border)
setUndecorated(false);
setVisible(true);
setSize(width,height);
setResizable(false);
setBackground(Color.black);
// Initializes the background Image
Image background = Toolkit.getDefaultToolkit().getImage("background.gif");
// This is included for debugging with a decorated window.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} // end constructor
public void paintComponent(Graphics g)
super.paintComponent(g);
} // end paintComponenet
} // end QubicGUITwo things I want to know:
1. I was trying to access a variable as JLabel
myLabel; defined in the constructor of a class from
the constructor of another class. I got this error
message - "Cannot access non-static variable from a
static context". Why(When both are non-static am I
getting the message as static context)?Post some code. It's hard to pinpoint a syntax error like that without seeing the code.
Also, there may be cleaner ways of doing what you want without having classes sharing labels.
2. I am using a map to set the attributes of a font.
One of the key-value pair of the map is
TextAttributesHashMap.put(TextAttribute.FOREGROUND,Colo
.BLUE);
But when I using the statement g.drawString("First
line of the address", 40, 200); the text being
displayed is in black and not blue. Why?You need to use the drawString that takes an AttributedCharacterIterator:
import java.awt.*;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class Example extends JPanel {
public static void main(String[] args) {
JFrame f = new JFrame("Example");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = f.getContentPane();
cp.add(new Example());
f.setSize(400,300);
f.setLocationRelativeTo(null);
f.setVisible(true);
protected void paintComponent(Graphics g) {
super.paintComponent(g);
String text = "Every good boy does fine always";
AttributedString as = new AttributedString(text);
as.addAttribute(TextAttribute.FAMILY, "Lucida Bright");
as.addAttribute(TextAttribute.SIZE, new Float(16));
as.addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 5);
as.addAttribute(TextAttribute.FOREGROUND, Color.GREEN, 6, 10);
as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 11, 14);
as.addAttribute(TextAttribute.FOREGROUND, Color.YELLOW, 15, 19);
as.addAttribute(TextAttribute.FOREGROUND, Color.MAGENTA, 20, 24);
as.addAttribute(TextAttribute.FOREGROUND, Color.CYAN, 25, 31);
g.drawString(as.getIterator(), 10, 20); -
I have two small java programs one refferring to another.When I try to complie main program I get following error:
GenericMaintenance.java:12: cannot resolve symbol
symbol : class csvfile
location: package csv
import com.csv.csvfile;
^
1 error
Here csvfile is the child class which i am trying to call from main program
The codes are asfollows:
GenericMaintenance.java:
package com.others;
import java.io.*;
import java.util.StringTokenizer;
import java.sql.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import Util;
import jxl.*;
import com.csv.csvfile;
public class GenericMaintenance
csvfile.java:
package com.csv.csvfile;
import java.io.*;
import java.util.StringTokenizer;
import java.sql.*;
import java.util.*;
import java.text.*;
import jxl.*;
//import Util;
public class csvfile {
I don't see anything wrong with code.Could somebody please advice me ASAP on this.I have two small java programs one refferring to
another.When I try to complie main program I get
following error:
GenericMaintenance.java:12: cannot resolve symbol
symbol : class csvfile
location: package csv
import com.csv.csvfile;
^
csvfile is the child class which i am trying to call
from main program
The codes are asfollows:
GenericMaintenance.java:
package com.others;
import java.io.*;
import java.util.StringTokenizer;
import java.sql.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import Util;
import jxl.*;
import com.csv.csvfile;
Hey, I think the import is wrong here.. looking at the two classes you hve given in ur description.. <b>csvfile.java</b> belongs to a package called <b>com.csv.csvfile</b>, so you should import this as
import com.csv.csvfile.csvfile;but not
import com.csv.csvfile; // u can't import package like this.. u should use .*
// if u want to import only one class u should write till the class name
public class GenericMaintenance
csvfile.java:
package com.csv.csvfile;
hope it helps.. -
Weird cannot resolve symbol error.
I'm having a problem with the most simple thing, but I really don't know what is th error, maybe I can�t see the error because the lack of rest.
I have two classes, both are in a package and in the same folder.
This is are the problematic lines.
tmpLong = calculateSizeFile("sonido.wav");
tmpInt = calculateSizeSegment("sonido.wav");
SendFile file1 = new SendFile(args[0], "sonido.wav", 2, 32, 2, 2, tmpLong, tmpInt);
The SendFile is the other class and it�s a thread.
The package decalaration is:
package com.sigmatao.gde.batch;
This is the constructor of the other class:
public SendFile(String httpServlet, String file, int numberRetry, int maxTimeWait,int multiplier,int timeMin, long sizeFileToSend, int sizeSegmentFile)
Thanks in advanced for the help.C:\Temp\URL\com\sigmatao\gde\batch>javac BatchTransfer.java
BatchTransfer.java:20: cannot resolve symbol
symbol : class SendFile
location: class com.sigmatao.gde.batch.BatchTransfer
SendFile file1 = new SendFile(args[0], "sonido.wav", 2, 32, 2, 2, tmpLon
g, tmpInt);
^
BatchTransfer.java:20: cannot resolve symbol
symbol : class SendFile
location: class com.sigmatao.gde.batch.BatchTransfer
SendFile file1 = new SendFile(args[0], "sonido.wav", 2, 32, 2, 2, tmpLon
g, tmpInt);
This is the problem. -
HELP PLEASE Cannot resolve symbol error
Only just started to atempt simple java programs and this same error keeps appearing. code i am using is:
import java.io.*;
class Q1
public static void main(String[] args) throws IOException
int num1,num2,sum;
/*program statements start here*/
System.out.printIn ("Input a number");
num1= Course_io.readInt();
System.out.printIn ("Input another number");
num2= Course_io.readInt();
sum= num2 - num1;
System.out.printIn ("Total is" +sum );
and this is the error message i keep getting:
javac -d . -g "C:\Java Programs\Q1.java"
C:\Java Programs\Q1.java:12: cannot resolve symbol
symbol : method printIn (java.lang.String)
location: class java.io.PrintStream
System.out.printIn ("Input a number");
^
C:\Java Programs\Q1.java:16: cannot resolve symbol
symbol : method printIn (java.lang.String)
location: class java.io.PrintStream
System.out.printIn ("Input another number");
^
C:\Java Programs\Q1.java:22: cannot resolve symbol
symbol : method printIn (java.lang.String)
location: class java.io.PrintStream
System.out.printIn ("Total is" +sum );
^
3 errors
Please help me, Thankyou.sum= num2 - num1;
System.out.printIn ("Total is" +sum );While you're at it, do something about this, it's misleading.
kind regards,
Jos -
Cannot resolve symbol error while trying to define methods in a class
Well, I'm fairly new to java and I'm trying to write a simple program that will take user input for up to 100 die and how many sides they have and will then roll them and output the frequencies of numbers occuring. I have overloaded the constructor for the Die class to reflect different choices the user may have when initializing the Die.
Here is my code:import java.util.*;
import java.io.*;
public class Die
private final int MIN_FACES = 4;
private int numFaces;
private int i = 0;
private int faceValue;
private Die currentDie;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private String line = null;
public Die()
numFaces = 6;
faceValue = 1;
public Die (int faces)
if (faces < MIN_FACES) {
numFaces = 6;
System.out.println ("Minimum number of faces allowed is 6.");
System.out.println ("Setting faces to 6... . . . . . . . . .");
else
numFaces = faces;
faceValue = 1;
//Returns an array of Die Objects
public Die (int num_die, int faces)
numFaces = faces;
Die[] protoDie = new Die[num_die];
for (i = 0; i <= num_die-1; i++)
Die currentDie = new Die(numFaces);
protoDie = protoDie.initMultiDie(currentDie, i);
public Die (double num_die)
int numberOfDie = (int) num_die;
Die[] protoDie = new Die[numberOfDie];
System.out.print ("Enter the number of sides for die #" + i);
for (i=0; i <= protoDie.length; i++) {
do {
try {
line = br.readLine();
numFaces = Integer.parseInt(line);
catch (NumberFormatException nfe) {
System.out.println ("You must enter an integer.");
System.out.print ("Setting number of dice to 0, please reenter: ");
if (numFaces < 0) {
System.out.println ("The number of sides must be positive.");
numFaces *= -1;
System.out.println ("Number of sides is: " + numFaces);
else
if (numFaces = 0) {
System.out.println ("Zero dice is no fun. =[");
System.out.print ("Please reenter the number of sides: ");
numFaces = 0;
while (numFaces == 0);
Die currentDie = new Die(numFaces);
protoDie[i] = protoDie.initMultiDie(currentDie, i);
i = 0;
public Die[] initMultiDie (Die[] protoDie, Die currentDie, int i)
protoDie[i] = currentDie;
return protoDie;
public Die reInit (int sides)
currentDie.roll();
return currentDie;
public int roll()
faceValue = (int) (Math.random() * numFaces) + 1;
return faceValue;
}When I compile I get 2 errors at lines 42 and 73 saying:
Cannot resolve symbol | symbol: method initMultiDie(Die, int) | location: class Die[] | protoDie[i] = protoDie.initMultiDie(currentDie, i)
I've tried mixing things up with invoking the method, such as including protoDie in the parameter liist, instead of invoking the initMultiDie method thru the protoDie Die[] object. I'm a little confused as to what I can and cannot do with defining arrays of Objects like Die. Thank you for any input you may be able to provide.
~LijeI may as well just replace Die with Dice and allow
Dice to represent a collection of 1 die.. I just like
to cut on bloat and make my programs be as efficient
as possible.Efficiency and avoiding code bloat are good goals, but you don't necessarily achieve it by creating the smallest number of classes. If you have N algorithms in M lines, then you have that many, regardless of whether they're in one class or two. A really long source file can be a worse example of bloat than two source files of half the size -- it can be harder to read, less clear in the design, and thus with more bugs...
The important thing is clarity and a strong design.
The weird thing is, that initMultiDie is
what seems to be throwing up the error, but I don't
see why. Meh, I'm sure I'll figure it out.Refactoring a class to make the design more transparent often helps you figure out bugs. -
JMS "cannot resolve symbol" error
I am a bit new to JMS...
I am trying to compile a sample code available on net to receive message from a queue....
I am using MQSeries JMSAdmin as the JMS provider...
however the code is giving the following compile time error...
MqJmsProp.java:257: cannot resolve symbol
symbol : method createSession (boolean,int)
location: interface javax.jms.Connection
QueueSession session = connection.createSession(transacted,Sessi
on.AUTO_ACKNOWLEDGE);
^
1 error
Can anyone suggest me what might be the problem...
Thanks in advance...
PatsHi Shanu...
Thanks for all the interest that you have shown....
I have IBM MWebSphere MQSeries installed on my system...
and as I mentioned earlier am using the JMS implementation provided by MQSeries...
I have created a queue in the queue manager which is on the local system....
I have done JNDI binding for the queue manager and the queue that i m gonna use....
how ever if u look at the error ... it does not say any thing about the queue not available....
its more a pure java related error which i am not able to track.... :(
i know this error looks silly and very novice ... but thats the situation i m in right now...
the code which is giving me this error is like this ....
QueueSession session;
session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
where connection is a javax.jms.QueueConnection object...
I hope this explains my problem in a much better way...
would appreciate if u can throw any light on this...
Thanks,
Pats... -
"cannot resolve symbol" error...please help
when itry to compile my program i get the error " cannot resolve
symbol" variable setLayout.
My program is very small. Can someone tell me why i keep
getting error?
thanx
trin.
import java.applet.*;
import java.awt.*;
public class MyProg extends Applet
Button btnOne = new Button("One");
Button btnTwo = new Button("Two");
public void init()
Panel pOne = new Panel( ) ;
pOne.setLayout = ( new GridLayout( ));
pOne.add(btnOne);
pOne.add(btnTwo);
add(pOne);Change:
pOne.setLayout = ( new GridLayout( ));to
pOne.setLayout( new GridLayout());It's a method call, not an assignment :) -
Please?!? Cannot Resolve Symbol Error Message
//Elizabeth Skelton Section 001 Homework Set 3
import javax.swing.JOptionPane;
public class skeltonMaxofThree
public static void main (String[] args)
//ask user for numbers
String stringnum1= JOptionPane.showInputDialog(null, "Please enter first number", "Input", JOptionPane.QUESTION_MESSAGE);
String stringnum2=JOptionPane.showInputDialog(null, "Please enter second number", "Input", JOptionPane.QUESTION_MESSAGE);
String stringnum3=JOptionPane.showInputDialog(null, "Please enter third number", "Input", JOptionPane.QUESTION_MESSAGE);
//convert to numerical
double num1=Double.parseDouble(stringnum1);
double num2=Double.parseDouble(stringnum2);
double num3=Double.parseDouble(stringnum3);
//call max method
double biggest=maximum(num1,num2,num3);
//display answer
String output = "The biggest is " + biggest;
JOptionPane.showMessageDialog(null, output, "Result", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
public static double maximum(double num1, double num2, double num3)
//determine biggest
double biggest=Math.max(num1,num2,num3);
return biggest;
Returns error:
:\My Documents\BD120\skeltonMaxofThree.java:36: cannot resolve symbol
symbol : method max (double,double,double)
location: class java.lang.Math
double biggest=Math.max(num1,num2,num3);
^
1 error
Tool completed with exit code 1the max method of the Math class requires 2 parameters not 3...to find the maximum of 3 numbers u can do something like this...
double biggest = Math.max(num1, Math.max(num2, num3)); -
Can not resolve symbol in method showMessageDialog
I tried to dispaly a mesg using JOptionPane, it gives error mesg like
HWS.java:27: cannot resolve symbol
symbol : method showMessageDialog (<anonymous java.awt.event.ActionListener>,j
ava.lang.String,java.lang.String,int)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog (this, "The","Exit", JOptionPane.INFORMATION_M
ESSAGE);
^
pls help.
Sabarish
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HWS extends JFrame{
public HWS() {
super("Learning...");
setSize(300,300);
JLabel label2 = new JLabel("Jegan Rao");
JButton button = new JButton("Click here");
Container pane = getContentPane();
pane.setLayout(new FlowLayout());
pane.add(button);
pane.add(label2);
ActionListener al = new ActionListener(){
public void actionPerformed (ActionEvent ae){
JOptionPane.showMessageDialog (this, "The","Exit", JOptionPane.INFORMATION_MESSAGE);
button.setHorizontalAlignment(JButton.CENTER);
button.addActionListener(al);
button.setVerticalAlignment(JButton.CENTER);
label2.setHorizontalAlignment(JLabel.CENTER);
label2.setVerticalAlignment(JLabel.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
public static void main(String [] args){
HWS h = new HWS();
}Please post code using the code tags. There is a code button when you enter text for your message. Click on it then paste your code between the tags.
All of the JOptionPane showMessageDialog() methods require a Component as the first object argument. Your code calls showMessageDialog from inside an actionPerformed() method, which is inside an ActionListener. So 'this' is an ActionListener, not a JFrame or other Component.
Are you sure you want to call up a dialog in an actionPerformed() method? This method is called from the event thread, and blocks this thread until the dialog completes. This means no events can occur until the dialog completes, but it may require an event to complete the dialog.
Maybe you are looking for
-
Can't open mail and this morning couldn't open Safari
Can someone review this for me to tell me what is going on? I installed Leopard in late October, 2007 and no problems, really until last night when I started having some problems keeping Safari pages open. Then this morning I could not open Safari-I
-
HT4061 Hi I've just boUght Apple TV, how do I turn on home sharing from my ipad
I've just bought Apple TV and to set up with my iTunes account I need to enable home sharing. All I have is an iPad mini and an iPhone how do I do this please Thanks
-
i bought my daughters ipod shuffle 4th gen last week for xmas. set them all up easily etc and wrapped them for xmas. kids opened them up for xmas played them most of the day so i thought i would charge them both overnight on the computer. pc went int
-
...but when I fill a table with merge fields, it ends up creating multiple entries for the same address, rather than one table full of each address. Please help. Thanks!
-
Waveburner not opening saved files
Hi guys have had some major problems with my Waveburner from Logic 9 Upgrade. When i go to save my project that's no bother but when i go to open the project a warning box comes up and says "Bounce wb3. Waveburner cannot open this file type".... what