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?

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?

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.

Here is what I see.

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

As Ezzaral has mentioned, I would like to see more code, as these lines are perfectly fine.

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.

You can't place this line

passGet.setEchoChar('*');

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.