LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 06: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, 06: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, 12:20 AM   #3
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
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



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 05:11 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
"undeclared identifier is reported only once for each " KDel Linux - Software 1 04-29-2004 05:40 PM
I cannot use "java chat". Browser says plugin required "x-java-vm". jdruin Linux - Software 4 04-18-2004 05:44 PM
lpd "no identifier" error abyss Linux - Software 0 08-28-2002 08:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:12 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration