Error Cannot convert from int to boolean

I am facing Error Cannot convert from int to boolean, Here is the code where i am getting this problem.

private boolean seeDB()
  {
    int i = 1;
    SQLiteDatabase localSQLiteDatabase = null;
    try
    {
      localSQLiteDatabase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, 1);
      localSQLiteDatabase = localSQLiteDatabase;
      label01: 
          if (localSQLiteDatabase != null)
        localSQLiteDatabase.close();
      if (localSQLiteDatabase != null);
      while (true)
      {
        return i;
      }
    }
    catch (SQLiteException localSQLiteException)
    {
      break label01;
    }
  }
Jon Skeet
people
quotationmark

Well yes, the problem is here:

while (true)
{
    return i;
}

The method is declared to return boolean, but i is declared as an int. That's not going to work. You need to either change the return type to int, or work out when you want to return true and when you want to return false.

Additionally:

  • The value of i is always going to be 1
  • You're returning it in a while(true) loop, which is pointless
  • Your approach of breaking to a label in a catch block is invalid as far as I'm aware.
  • You've got a pointless if statement here:

    if (localSQLiteDatabase != null);
    

What are you actually trying to achieve with this code? It looks like it's just badly-decompiled code, to be honest. I suggest you start again from scratch, work out exactly what you're trying to achieve, and proceed from there. Your current code is so confused as to be unhelpful.

people

See more on this question at Stackoverflow