Jess Yuan
Jess Yuan

Reputation: 1621

What's wrong with android dao error?

I build my android project, but messages output this following error, this error from android dao.

Error:(31, 19) error: mismatched input 'fromJson' expecting {<EOF>, ';', ',', K_ALTER, K_ANALYZE, K_ATTACH, K_BEGIN, K_COMMIT, K_CREATE, K_DELETE, K_DETACH, K_DROP, K_END, K_EXCEPT, K_EXPLAIN, K_FROM, K_GROUP, K_INSERT, K_INTERSECT, K_LIMIT, K_ORDER, K_PRAGMA, K_REINDEX, K_RELEASE, K_REPLACE, K_ROLLBACK, K_SAVEPOINT, K_SELECT, K_UNION, K_UPDATE, K_VACUUM, K_VALUES, K_WHERE, K_WITH, UNEXPECTED_CHAR}

Upvotes: 4

Views: 1745

Answers (3)

dephinera
dephinera

Reputation: 3770

I had the same error but with slightly different cause. It was still a wrong @Query, but the issue was with my table name. I had - in the table name, which was invalid. Removing it fixed the issue.

Upvotes: 0

Gk Mohammad Emon
Gk Mohammad Emon

Reputation: 6938

For my case, I wrote the wrong query. My query was -

 @Query("SELECT * " +
                DbConstants.TABLE_MEDICINE + " WHERE " + DbConstants.MEDICINE_ID + " = (:id)")
        fun read(id: Long): LiveData<Medicine>
 /*Notice here,I missed "FROM" query in the query.*/

Correct query was -

@Query("SELECT * FROM " +
            DbConstants.TABLE_MEDICINE + " WHERE " + DbConstants.MEDICINE_ID + " = (:id)")
    fun read(id: Long): LiveData<Medicine> /*Include "FROM" now. 

So if anyone get this kind of error,then first check if your SQL query is right or not.

Upvotes: 1

Haris B.
Haris B.

Reputation: 71

It is probably a Syntax error in your SQL Query.

Make sure that when you are concatenating your Query (String) that you put a space at the end of each line.

@Query("SELECT c.username, c.first_name, c.last_name, r1.water_amount AS waterAmountLastMonth " +
       "FROM citizen c " +
       "INNER JOIN report r1 ON r1.date_month = :dateMonth " +
       "ORDER BY c.first_name ASC")

Upvotes: 7

Related Questions