• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Boston tutorial #16 - getting an error  RSS feed

 
Patrick De
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the NewBoston tutorials and have come across an error. After checking it over time and time again, my code is exactly the same (I think). I cannot find out where I went wrong. It is in two classes, here is the code:




classOne code


The error is :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String)

at classOne.saying(classOne.java:12)
at mainClass.main(mainClass.java:13)
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code looks ok to me.
How are you compiling this code?
What version of java are you using?
Are you using the standard sun java compiler/runtime ?



 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per javadoc usage is correct. May be problem is with your version as Stefan mentioned.
 
David Holcomb
Greenhorn
Posts: 10
 
Mark King
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Holcomb wrote:I recommend you steer clear of NewBoston


I agree, I've watched his tutorials, he never explains anything, he just shows you what to do, so when something breaks you have no clue why.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very peculiar error.

Go and hunt for the Java® Language Specification (=JLS) and go through it looking for “varargs”. What is happening is that printf takes a varargs of Objects after the format String and it turns those arguments into an array. If you write the identifier for a single String there (remember that there is only one format String because the compiler joins the two halves with the + operator): girlName
System.out.printf("You have spent years trying to forget %s and this daft%n" +
    "program insists on reminding you of her.%n", girlName);
… then the compiler interprets that as a one‑element array. Obviously if you pass the name of a method, the compiler sees that as a single argument, which in this case is of type String. Did it say anything helpful in the JLS about that? I have never seen that particular compiler error before.

Edit: Add this warning. The JLS can be very difficult to read.
 
Patrick De
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone recommend a better set of videos online?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this or CS106A from standford. For CS106A several videos are available online free. For first course, i have not checked
specifically this course but i took another courses. Instructor is looking good to me. This beginning course is free.
 
David Holcomb
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David De wrote:Can someone recommend a better set of videos online?


https://www.youtube.com/playlist?list=PLE7E8B7F4856C9B19 (Derek Banas)
https://www.youtube.com/playlist?list=PL9DF6E4B45C36D411 (CaveOfProgramming)

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know about first but 2nd one i already recommended to you.
 
David Holcomb
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tushar Goel wrote:i dont know about first but 2nd one i already recommended to you.


LOL we're different people. I can understand why you thought we were the same. You thought we were the same because you only saw the first name which is "David."
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!