• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java errors finding symbol?  RSS feed

David Evangelista
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code that is supposed to read a user-selected document, create text boxes from that info, and display them. (There is a lot of code in there that may not be relevent, but just ignore that.) When I compile, I receive errors that it can not find the symbols color, xIn, yIn, w, and h.

Here's my code:

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

import java.util.*;
import java.io.*;

public class Ex22 extends Basic
public static void main(String[] args)
Ex22 a = new Ex22("Draw a Bunch of Text Boxes", 50, 100, 500, 500);

// instance variables for the application:
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

private ArrayList<TextBox> list;

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

public Ex22( String title, int ulx, int uly, int pw, int ph )

// create the list of text boxes:
Scanner keys = new Scanner (System.in);
String fileName = "";

System.out.print("Enter data file name: ");
fileName = keys.nextLine();

//Opening/Reading the File

Scanner input = new Scanner(new File(fileName));
System.out.println("File opened successfully.");
catch (Exception e)
System.out.println("Problem opening file!");
System.out.println("" + e);

list = new ArrayList<TextBox>();
String textIn;
Double xIn;
Double yIn;
Double w;
Double h;
int c1;
int c2;
int c3;
Color color;
Scanner input = new Scanner(new File(fileName));

textIn = input.nextLine();
xIn = input.nextDouble();
yIn = input.nextDouble();
w = input.nextDouble();
h = input.nextDouble();
c1 = input.nextInt();
c2 = input.nextInt();
c3 = input.nextInt();
color = new Color(c1, c2, c3);
TextBox tb = new TextBox(textIn, xIn, yIn, w, h, color);
while (input.hasNext());


setBackgroundColor( new Color( 128, 128, 200 ) );

cameras.add( new Camera( 20, 30, 450, 450,
0, 100, 0,
) );

// start up the animation:

public void step()
Camera cam = cameras.get(0);


int x;
int len = list.size();
for (x =0; x < len; x = x+1)
cam.setColor( color );
cam.drawRect (xIn, yIn, w, h);
cam.drawHorizCenteredText(textIn, x+w/2, y+h/2);

Scott Winterbourne
Ranch Hand
Posts: 116
Eclipse IDE Java PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The color, xIn, yIn, w, and h variables are declared as local variables in the constructor, which means they only live inside the constructor. You are then trying to reference them in the Step() method but they do not exist there. Their lives have already ended at the end of the constructor execution.

Also, please place any code inside of [ code ] tags (without the spaces) to make it easier to read code samples.
fred rosenberger
lowercase baba
Posts: 12565
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is your code with the surrounding code tags. Note that the formatting you have is a little off...

Also, it is often of tremendous help if you post the full error message you get when compiling.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!