Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Char cannot be dereferenced

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Default Char cannot be dereferenced

    Hi everyone. I'm a beginner at Java and I have some code that keeps giving me an error.

    import java.util.Scanner;
    public class Assignment3
      public static void main(String [] args)
    	Scanner scan = new Scanner(System.in);
    	String firstName, middleName, lastName;
    	char firstInitial, middleInitial, lastInitial;
    	System.out.println("What is your first name? ");
    	firstName = scan.nextLine();
    	System.out.println("What is your middle name? ");
    	middleName = scan.nextLine();
    	System.out.println("What is your last name? ");
    	lastName = scan.nextLine();
    	firstInitial = firstName.charAt(0);
    	middleInitial = middleName.charAt(0);
    	lastInitial = lastName.charAt(0);
    	System.out.println("Your initials are " + firstInitial.toUpperCase() + middleInitial.toUpperCase() + lastInitial.toUpperCase());
    	System.out.println("Your name is " + lastName.toUpperCase() + ", "+firstInitial + "." + middleInitial + ".");

    I get the error java:32: char cannot be dereferenced at the periods before toUpperCase in the line about initials, but not in the one about the last name, if that makes sense. I've been staring at it for like half an hour and I just can't figure it out. Can someone help me out? Thanks!

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 832 Times in 772 Posts
    Blog Entries

    Default Re: Char cannot be dereferenced

    char is a primitive and String is an object, so you are trying to call a method on a primitive that does not exist. Solution would be to use the Character.toUpperCase method or Character.toString() method then call toUpperCase

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Default Re: Char cannot be dereferenced

    omgg thank you xD

Similar Threads

  1. Char cannot be dereferenced!! Please help
    By humdinger in forum Object Oriented Programming
    Replies: 5
    Last Post: February 14th, 2010, 03:18 PM
  2. char (toUppercase?)
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 12th, 2009, 10:01 AM
  3. Need help with concatenizing char? to string?
    By bh-chobo in forum Java SE APIs
    Replies: 3
    Last Post: October 16th, 2009, 08:40 AM
  4. reading a char with SCANNER
    By lotus in forum Java SE APIs
    Replies: 6
    Last Post: July 29th, 2009, 05:03 AM
  5. Program to convert Hexadecimal to its Character equivalent
    By nathanernest in forum Java Theory & Questions
    Replies: 2
    Last Post: April 8th, 2009, 03:12 AM