• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
William Cantree
Greenhorn
Posts: 4
Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Cantree wrote:instead of what I did use, right?

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

Winston
 
William Cantree
Greenhorn
Posts: 4
Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51456
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t know about the six letters problem. I suggest you print the length of the name first. See what that says.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic