File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes int cannot be dereferenced when attempting to grab lowercase of first letter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "int cannot be dereferenced when attempting to grab lowercase of first letter" Watch "int cannot be dereferenced when attempting to grab lowercase of first letter" New topic
Author

int cannot be dereferenced when attempting to grab lowercase of first letter

William Cantree
Greenhorn

Joined: Feb 25, 2013
Posts: 4

I'm absolutely bewildered by how in other java files I attempt I can actually get the lowercase of something in, say, a for loop. But if I as much as try to get it to show in a println, I come up with the "int cannot be dereferenced" error. Annoying, in my own opinion. Here is the code:



What exactly am I messing up?


EDIT: Some extra info:

Let's say I remove the .toLowerCase(firstname).charAt(0)

It compiles, runs, but after the first scanner, it crashes with this message:

java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at TestEmailMaker.main(TestEmailMaker.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)


What the heck?

So, how would I go about grabbing the lowercase of the firstname? When I get that, it should be easier to grab the first 6 letters of the last name.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2288
    
  49
Welcome to the Ranch.

You can't dereference (ie call a method on) a primitive data type which is why you are getting that message.
BTW why are you asking the user to input their first name and then asking for an int value from the input, surely their name contains letters and not numbers.

The second error message is because the input presumably does not contain a valid float value.
William Cantree
Greenhorn

Joined: Feb 25, 2013
Posts: 4

Tony Docherty wrote:Welcome to the Ranch.

You can't dereference (ie call a method on) a primitive data type which is why you are getting that message.
BTW why are you asking the user to input their first name and then asking for an int value from the input, surely their name contains letters and not numbers.

The second error message is because the input presumably does not contain a valid float value.


I'm not entirely sure why I was using an int to actually get letters and not numbers. And as for the error message, that makes sense. So, with out asking the user to input the first letter of their first name in lowercase, I would need to essentially ask for the first name in,...

Wait a second, I just realized... Man, that was foolish... I think I should have used, say,

instead of what I did use, right?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Welcome Will. I would rather suggest that first read what are primitives and what are objects. Grab a good book and get the fundamentals crystal clear if you are new to the language. You would automatically find the answer to your questions.


~ Mansukh
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7795
    
  21

William Cantree wrote:instead of what I did use, right?

The best answer in cases like this is: suck it and see.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
William Cantree
Greenhorn

Joined: Feb 25, 2013
Posts: 4

Going back over some of the older code I did about a month ago, I found that what I'm looking for is, essentially:


Which seems to actually work. And with that done, that actually fixes the entire thing. Thanks for throwing out ideas!

Hrm, another pickle I'm in is actually showing only the first six or fewer letters of the input for the lastname string.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Don’t know about the six letters problem. I suggest you print the length of the name first. See what that says.
 
Don't get me started about those stupid light bulbs.
 
subject: int cannot be dereferenced when attempting to grab lowercase of first letter