LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-31-2004, 07:29 PM   #1
nro
Member
 
Registered: Oct 2003
Distribution: Mandrake 9
Posts: 46

Rep: Reputation: 15
Java "<identifier> expected" error.


I have a couple simple lines of code, one of which is giving me trouble.

Code:
JTextField txtDisplay = new JTextField();
txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
The text field is created fine, but configuring the alignment is giving trouble. If you see the trouble with my code, please let me know.
The definition for setHorizontalAlignment is:

public void setHorizontalAlignment(int alignment)

Here is my error:

calculator/calculator.java [12:1] <identifier> expected
txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
-------------------------------------^
1 error
Errors compiling calculator
 
Old 08-31-2004, 07:44 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
This compiles for me:
Code:
import javax.swing.*;

public class Foo {
    public static void main(String[] args) {
	JTextField txtDisplay = new JTextField();
	txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
    }
    
}
 
Old 09-01-2004, 01:20 AM   #3
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
I'm not sure if you know about this:

http://java.sun.com/j2se/1.4.2/docs/api/

but it has a lot of examples about Java classes. I also agree with ToniT, looks like you are forgetting to import the classes...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is a "string identifier" and how do I set it Ebisu_Dave Linux - Hardware 1 07-15-2005 06:11 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 04:47 AM
"undeclared identifier is reported only once for each " KDel Linux - Software 1 04-29-2004 06:40 PM
I cannot use "java chat". Browser says plugin required "x-java-vm". jdruin Linux - Software 4 04-18-2004 06:44 PM
lpd "no identifier" error abyss Linux - Software 0 08-28-2002 09:31 AM


All times are GMT -5. The time now is 08:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration