|
|
Re: Can't avoid "cannot be resolved to a type" (Eclipse/JbossStudio) [message #1799119 is a reply to message #1799007] |
Fri, 30 November 2018 03:56 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
When I get this error message it's usually because I've left something off earlier in the file. For instance, I might use the WindowBuilder to make a JTextArea called txtrXcord, and then later add something to the java file that refer to txtrXcord before I come to the entry made by WindowBuilder. But the compiler doesn't know what txtrXcord is. So it cannot be "resolved," which means, "I can't figure out what one of these txtrXcord things I supposed to be. "
Declare txtrXcord as a JTextArea before it ever gets used, and remove the duplication below.
public Drawer() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
//To fix the problem, put up here:
/[color=green]/JTextArea txtrCurrentXCoordinate;[/color] // third thing I did, first thing I did to fix my mistake.
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
/*Second problem factor*/ [color=red]txtrCurrentXCoordinate.setText("Previous x coordinate");[/color] // second thing I did.
//[color=red]RED FLAG[/color] error message : txtrCurrentXCoordinate cannot be resolved.
/*First problem factor*/[color=orangered]JTextArea[/color] txtrCurrentXCoordinate = new JTextArea(); //first thing I did
/[color=green]/txtrCurrentXCoordinate = new JTextArea()[/color];//fourth thing I did and the second I did to fix my mistake.
txtrCurrentXCoordinate.setText("Current x coordinate");
txtrCurrentXCoordinate.setBounds(69, 175, 160, 36);
frame.getContentPane().add(txtrCurrentXCoordinate);
}
}
Another thing might be to use, e.g., some javex item without having included the appropriate javex,whatever above with the other "includes."
|
|
|
|
|
Re: Can't avoid "cannot be resolved to a type" (Eclipse/JbossStudio) [message #1799166 is a reply to message #1799146] |
Fri, 30 November 2018 20:23 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
Start with a simple program.
Include a simplified version of the squib you've provided above. Use just the essentials. You will find that in that context there is nothing wrong with what you have written. You could then go ahead to add the other things that make your file more than a few lines long. If you do so a few lines at a time you should be able to isolate any problems. But I doubt that there will be any.
Here is my ultra simple java file as above but with the addition of the basics of your squib.
import java.awt.EventQueue;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Drawer {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Drawer window = new Drawer();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Drawer() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
JTextArea txtrCurrentXCoordinate;
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
txtrCurrentXCoordinate.setText("Previous x coordinate"); // second thing I did.
txtrCurrentXCoordinate = new JTextArea();
txtrCurrentXCoordinate.setText("Current x coordinate");
txtrCurrentXCoordinate.setBounds(69, 175, 160, 36);
frame.getContentPane().add(txtrCurrentXCoordinate);
}// end initialize
public class CommandData {
private int cmdScheduleID;
public int getCmdScheduleID() {
return cmdScheduleID;
}
}
}
There are no red flags on the above code. Where do your red flags come from???
Now make a dummy class file for CommandData, let's call it CommanderData. It does nothing, and at this point it is not connected with your original program. It shouldn't cause any error messages. If it does, you'll have to ask somebody who knows much more than I do about how there could be a connection that vitiates CommanderData when the only connection Is that it is in the same subdirectory with some other xyz.java files.
Go back to the xyz.java file that calls CommandDataI(), comment that line out and replace it with one that calls CommanderData();
What happens?
I have no idea what it might be, but I think your trouble has to be at this point. There is probably nothing wrong with the code you posted above, so the problem must be somewhere else.
[Updated on: Fri, 30 November 2018 20:27] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.08128 seconds