• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot be applied in java.lang.string

 
Lana Angela Yambao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(sc.next());\\

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(System.in);
StudentInformation mystudents=new StudentInformation();
mystudents.setFName(in.next());
in.useDelimiter("\n");
String stringInput=in.next();
}
{
System.out.print("Year Level:");
Scanner sc=new Scanner(System.in);
StudentInformation mystudents=new StudentInformation();
mystudents.setYrLvl(sc.next());
sc.useDelimiter("\n");
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()
{
return(this.FName);
}
public void setFName(String temp1)
{
this.FName=temp1;
}

public int getYrLvl()
{
return(this.YrLvl);
}
public void setYrLvl(int temp2)
{
this.YrLvl=temp2;
}
}

>>>Please Help immediately?..'Cause I need it July 26??..
 
Lana Angela Yambao
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 49823
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic