File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting Incompatible Types java.lang.String" Watch "Getting Incompatible Types java.lang.String" New topic

Getting Incompatible Types java.lang.String

Toshiro Hitsuguya

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

Joined: Oct 27, 2005
Posts: 20271

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?

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

Joined: Oct 13, 2005
Posts: 46337
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:
subject: Getting Incompatible Types java.lang.String
It's not a secret anymore!