0

This is probably just a stupid mistake but I can't figure it out. I have this code:

TextField passGet=new TextField(10);
    passGet.setEchoChar('*');

and when I try to compile, I get and <identifier> expected error. Anyone know why?

3
Contributors
8
Replies
10
Views
8 Years
Discussion Span
Last Post by BrianK123
0

You've probably missed a type designation on a variable or parameter somewhere above that code then, because there is nothing wrong with those two lines. Which line specifically is indicated as the cause?

0

The setEchoChar() line gets highlighted. And when I put // infront of that line to make it a comment, the program compiles fine. I am using BlueJ wich I heard isn't that great so I don't know if that has anything to do with it.

0

Well, assuming that you have imported the TextArea class, those two lines compile just fine in my IDE.

0

Ok I don't exactly what you want to see. This is what I imported (so I think I'm set there.)

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

I think I actually imported more than I needed.
This is all the code that I have before the problematic segment:

public class GradeBook2 extends JFrame 
{
    JPanel All=new JPanel();
   
    //reference ints for loops
    int stop;
    int index;
   
    //Counter for times Enter is pressed
    int presses=0;
   
    //Declaring the arrays for the classes.
    ArrayList CompSciAP=new ArrayList();
    ArrayList CompSciIB=new ArrayList();
    ArrayList AlgebraII=new ArrayList();
    ArrayList TempRemove=new ArrayList();
    ArrayList EditList=new ArrayList();
   
    //OptionPanes to display class information
    JOptionPane CompSciAPPane=new JOptionPane();
    JOptionPane CompSciIBPane=new JOptionPane();
    JOptionPane AlgebraIIPane=new JOptionPane();
   
    JOptionPane Messages=new JOptionPane();
   
    //String to check the password
    String password;
   
    //Strings needed to add and remove students
    String newStudent;
    String newGrade;
    String studentRemove;
    String StudentClass;
    String ClassFile;
    String studentEdit;
   
    //declares labels for display
    JLabel Title=new JLabel("Enter Password");
    Label APLabel=new Label("");
    Label IBLabel=new Label("");
    Label A2Label=new Label("");
    
    //declares text feild for password 
    TextField passGet=new TextField(10);
    passGet.setEchoChar('*');

I am downloading Xcode now to see if it works there.

0

You can't place this line

passGet.setEchoChar('*');

in the class body directly. It must be within a method.

0

OH! Thanks a lot! I just moved it down some and now it works. Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.