ajspacemanspiff
ajspacemanspiff

Reputation: 478

Android DAO adding a query "'@Query not applicable for field"

Here is a DAO i have created for a rooms library with a list of participants. The data is very simple.

package com.example.tag;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface ParticipantDAO {

    @Query("SELECT * FROM Participants ORDER BY Name")
    LiveData<List<Participant>> getAllParticipants();

    @Query("SELECT * FROM Participants LIMIT 1")
    Participant[] getAnyParticipant;


    @Insert
    void insert(Participant participant);

    @Update
    void update(Participant participant);

    @Delete
    void delete(Participant participant);

    @Query("DELETE FROM Participants")
    void deleteAll();

}

The problem is with the second @Query statement (getAnyParticipant). I receive the error: "'@Query' not applicable to field".

I am attempting to modify the android tutorials for my needs (using participants instead of words) located here: https://codelabs.developers.google.com/codelabs/android-training-room-delete-data/index.html?index=..%2F..android-training#2

What am I doing wrong?

Upvotes: 1

Views: 2008

Answers (1)

cgb_pandey
cgb_pandey

Reputation: 1025

Only method can be annotated with @Query. Here, you are trying to annotate a class field with @Query. You missed a pair of parentheses.

Upvotes: 2

Related Questions