[Solved] Incomparable types: String and class name


I’m guessing the error is thrown at this line

 if(cari == buku1.Perpus[1])

Since you’re comparing a String to a Perpus object in your array here.

You need to add some getter methods to your class, so that you can compare Strings in your array elements to the String cari.

Eg:

class perpus {
    private String penulis;
    private String namaBuku;
    private String kategori; 

    String getPenulis()
    {
    return penulis;
    }
    //insert other class members here

    }

Then:

if(cari.equals(buku1.Perpus[1].getPenulis()))
//do whatever

solved Incomparable types: String and class name