Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Getting Incompatible Types java.lang.String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting Incompatible Types java.lang.String" Watch "Getting Incompatible Types java.lang.String" New topic
Author

Getting Incompatible Types java.lang.String

Toshiro Hitsuguya
Greenhorn

Joined: May 15, 2009
Posts: 19
Hey guys, I am working on a project right now to create a simple library system. I am trying to compile, but I am getting "Incompatible Types; Found : Book; Required java.lang.string" It is on the lines that return b in the available books constructor.

Here is the code I have so far:



Also, my goal with the availableBooks constructor is to get it to where the book doesn't appear on the list of available books when it is borrowed. How could I rearrange my constructor to accomplish this?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

You may want to use a List<Book> instead; now you're limited to the size you specify when you create the array. Which you don't, by the way. books remains null.

I think you want to swap that assignment around. At this point, address is null. You are then assigning null to the local variable, overwriting its previous value.

What is the type of b? And what is the required return type? Those two do not match, do they?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhijeet Ravankar
Ranch Hand

Joined: Mar 15, 2009
Posts: 62
The return type of avalibleBooks(Book b) function is "String". While you are returning b, where b is of type Book and NOT String.

Try changing the return type to Book:



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37940
    
  22
You have another serious error.

Never write == true. You simply write if (b) . . .

Never write == false. You simply write if (!b) . . .

Those forms with == are both poor style, and you can get all sorts of nasty errors if you mistakenly write = instead of ==. You do in fact appear to have written = instead of == in at least one place.
Also you ought to give the borrowed attribute private access, then you can access it with an isBorrowed method. You ought not to get direct access to fields of an object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Incompatible Types java.lang.String
 
Similar Threads
Having Trouble Referencing a Method from Anonther Method in Another Class
new to write code, pls help!
Getting "Class, Interface or Enum expected" at the end of my code.
Getting a lot of "method cannot be applied to (java.lang.string)"
Array List is Printing Out the Exact Same Thing