Results 1 to 7 of 7
- 05-04-2011, 06:07 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 38
- Rep Power
- 0
ERROR - char cannot be dereferenced HELP
Hi guys,
I am recieving a "char cannot be dereferenced" error when I try and compare to char's. This is only a section of the program. No other errors anywhere else.
Thanks.
Java Code:for (int i =0; i < list.size(); i++) { StringTokenizer st = new StringTokenizer(list.get(i), "|"); while(st.hasMoreTokens()) { System.out.println("Would you like to see another line?"); String moreText = s.next().toLowerCase();//converts string to lower case char c = moreText.charAt(0); while (c.equals("y")) { System.out.println(st.nextToken()); } break; } }
- 05-04-2011, 06:10 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Chars are compared with ==, only objects are compared with the equals method.
- 05-04-2011, 06:17 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 38
- Rep Power
- 0
Ok. Thats funny because the Character class does have a equals() Method. Thanks.
- 05-04-2011, 06:21 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
The Character class does have one, it's an object, the char is a primitive. The Character class is used as a wrapper class. If you wanted to create a generic bound list you need a proper class. It wont allow a primitive type. Through the wrapper class and aitoboxing you can declare a generically bound list of primitives.
Notice this uses Character, you can store chars in it though.Java Code:ArrayList<Character> x = new ArrayList<Character>();
Java Code:char z = 'g'; x.add(z);
- 05-04-2011, 06:25 AM #5
Java Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-04-2011, 06:40 AM #6
Um, Character overrides the equals(...) method inherited from Object.Character class inherits the equals method from Object.
db
- 05-04-2011, 06:54 AM #7
Similar Threads
-
int cannot be dereferenced
By jackrush in forum Advanced JavaReplies: 2Last Post: 11-12-2010, 08:47 AM -
How can I solve "void cannot be dereferenced" error?
By fervent07 in forum New To JavaReplies: 2Last Post: 04-05-2010, 08:54 PM -
Long Cannot Be Dereferenced?
By caps_lock in forum New To JavaReplies: 1Last Post: 01-18-2009, 01:49 AM -
Help!! error message "long cannot be dereferenced"
By soc86 in forum New To JavaReplies: 2Last Post: 11-30-2008, 03:24 PM -
Cannot convert from char to String error
By sondratheloser in forum New To JavaReplies: 1Last Post: 12-13-2007, 09:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks