Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes cannot be applied in java.lang.string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot be applied in java.lang.string" Watch "cannot be applied in java.lang.string" New topic

cannot be applied in java.lang.string

Lana Angela Yambao

Joined: Jul 25, 2009
Posts: 2
Since I'm a beginner I can't easily identify what solution is applicable for the error that is appearing...Could you please give me hand out here..
Well... The error says that \\setYrLvl(int) in StudentInformation cannot be applied to (java.lang.String)\\
And below that line says shows a part of my code from StudentRecord, it goes like this: \\mystudents.setYrLvl(;\\

This is my main class code:

import java.util.Scanner;
import java.lang.Object;

public class StudentRecord{
public static void main(String[] args)
System.out.print("First Name:");
Scanner in=new Scanner(;
StudentInformation mystudents=new StudentInformation();
System.out.print("Year Level:");
Scanner sc=new Scanner(;
StudentInformation mystudents=new StudentInformation();
int stringInput=sc.nextInt();

And then, this is the other part of that program:

public class StudentInformation
private String FName;
private int YrLvl;

public String getFName()
public void setFName(String temp1)

public int getYrLvl()
public void setYrLvl(int temp2)

>>>Please Help immediately?..'Cause I need it July 26??..
Lana Angela Yambao

Joined: Jul 25, 2009
Posts: 2
Uhmm, I've found the error.. But could any1 help me wid another prob. of the same program..
Well, when it ran in command prompt.. The first name just appeared w/o the year level..haha
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Welcome to JavaRanch

Please note we have a button for putting round code fragments (details here); please use it because the code is difficult to read otherwise. Please avoid any1 and w/o because many people on this website didn't learn English as children and may not understand those contractions: details here.
Don't try setting a delimiter on a Scanner, unless you really want it. The default delimiter of "whitespace" will probably suffice. What's more, using the delimiter you have chosen (\n) may cause portability problems; different operating systems use different line-ends.
Please explain the correction you made; I can see what it is, but other people reading this might not.

Please explain what your problem about not printing the year is; I can't seem to see any code which prints the year.
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
So, what problem is it you are having? The fact that it asks for "First Name:" and not for "Year Level:"? Well, if you code was correctly indented, it would be obvious; here:Does that help? You know "main" runs OK. You know your "Year Level" code does not run after main. Why?

And when you fix that, you're going to have one other problem to solve (plus what Campbell has told you).

I agree. Here's the link:
subject: cannot be applied in java.lang.string
It's not a secret anymore!