Room “Not sure how to convert a Cursor to this method's return type”: which method?
Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Using Room I'm getting this error and I'd like to find out which method causes it.
I have multiple DAOs, with approximately 60 methods in total, and this error just popped up after adding a method (copy&pasted from another one that worked perfectly, just changed the field to set).
I could post the whole class of DAOs, but I'm asking for a way to know which method failed. I tried with Run with --stacktrace, Run with --info and --debug option, but none of these show any valuable information.
The method I added is a @Query UPDATE with Int return type, as suggested in the documentation
UPDATE or DELETE queries can return void or int. If it is an int, the
value is the number of rows affected by this query.
EDIT: I'd like to add that I tried deleting the method, bringing the DAO back to the working state, but it still gives me this error.
EDIT2: Adding gradle console output because unreadable in comments:
error: Not sure how to convert a Cursor to this method's return type
error: Not sure how to convert a Cursor to this method's return type
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
|
show 5 more comments
Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Using Room I'm getting this error and I'd like to find out which method causes it.
I have multiple DAOs, with approximately 60 methods in total, and this error just popped up after adding a method (copy&pasted from another one that worked perfectly, just changed the field to set).
I could post the whole class of DAOs, but I'm asking for a way to know which method failed. I tried with Run with --stacktrace, Run with --info and --debug option, but none of these show any valuable information.
The method I added is a @Query UPDATE with Int return type, as suggested in the documentation
UPDATE or DELETE queries can return void or int. If it is an int, the
value is the number of rows affected by this query.
EDIT: I'd like to add that I tried deleting the method, bringing the DAO back to the working state, but it still gives me this error.
EDIT2: Adding gradle console output because unreadable in comments:
error: Not sure how to convert a Cursor to this method's return type
error: Not sure how to convert a Cursor to this method's return type
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
1
what is the full error message from gradle console?
– pskink
Sep 27 '17 at 11:17
@pskink added the full error message to the question
– David Corsalini
Sep 27 '17 at 12:51
this is my method which compiles just fine:@Query("SELECT * FROM user") LiveData<List<User>> loadUsers();when i changeListtoVectorfor example i am getting:UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers();in the Gradle Console window of android studio - note it showsUserDao.java:19which is a line location and also it prints the method that is wrong, more developer.android.com/studio/run/index.html#gradle-console
– pskink
Sep 27 '17 at 13:12
I'm building from Kotlin, maybe that's why I don't get the line?
– David Corsalini
Sep 27 '17 at 13:36
imho what you posted here is not gradle console output, are you sure you copied that error message from gradle console?
– pskink
Sep 27 '17 at 13:46
|
show 5 more comments
Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Using Room I'm getting this error and I'd like to find out which method causes it.
I have multiple DAOs, with approximately 60 methods in total, and this error just popped up after adding a method (copy&pasted from another one that worked perfectly, just changed the field to set).
I could post the whole class of DAOs, but I'm asking for a way to know which method failed. I tried with Run with --stacktrace, Run with --info and --debug option, but none of these show any valuable information.
The method I added is a @Query UPDATE with Int return type, as suggested in the documentation
UPDATE or DELETE queries can return void or int. If it is an int, the
value is the number of rows affected by this query.
EDIT: I'd like to add that I tried deleting the method, bringing the DAO back to the working state, but it still gives me this error.
EDIT2: Adding gradle console output because unreadable in comments:
error: Not sure how to convert a Cursor to this method's return type
error: Not sure how to convert a Cursor to this method's return type
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Using Room I'm getting this error and I'd like to find out which method causes it.
I have multiple DAOs, with approximately 60 methods in total, and this error just popped up after adding a method (copy&pasted from another one that worked perfectly, just changed the field to set).
I could post the whole class of DAOs, but I'm asking for a way to know which method failed. I tried with Run with --stacktrace, Run with --info and --debug option, but none of these show any valuable information.
The method I added is a @Query UPDATE with Int return type, as suggested in the documentation
UPDATE or DELETE queries can return void or int. If it is an int, the
value is the number of rows affected by this query.
EDIT: I'd like to add that I tried deleting the method, bringing the DAO back to the working state, but it still gives me this error.
EDIT2: Adding gradle console output because unreadable in comments:
error: Not sure how to convert a Cursor to this method's return type
error: Not sure how to convert a Cursor to this method's return type
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
edited Sep 27 '17 at 16:12
asked Sep 27 '17 at 10:48
David Corsalini
3,98133151
3,98133151
1
what is the full error message from gradle console?
– pskink
Sep 27 '17 at 11:17
@pskink added the full error message to the question
– David Corsalini
Sep 27 '17 at 12:51
this is my method which compiles just fine:@Query("SELECT * FROM user") LiveData<List<User>> loadUsers();when i changeListtoVectorfor example i am getting:UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers();in the Gradle Console window of android studio - note it showsUserDao.java:19which is a line location and also it prints the method that is wrong, more developer.android.com/studio/run/index.html#gradle-console
– pskink
Sep 27 '17 at 13:12
I'm building from Kotlin, maybe that's why I don't get the line?
– David Corsalini
Sep 27 '17 at 13:36
imho what you posted here is not gradle console output, are you sure you copied that error message from gradle console?
– pskink
Sep 27 '17 at 13:46
|
show 5 more comments
1
what is the full error message from gradle console?
– pskink
Sep 27 '17 at 11:17
@pskink added the full error message to the question
– David Corsalini
Sep 27 '17 at 12:51
this is my method which compiles just fine:@Query("SELECT * FROM user") LiveData<List<User>> loadUsers();when i changeListtoVectorfor example i am getting:UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers();in the Gradle Console window of android studio - note it showsUserDao.java:19which is a line location and also it prints the method that is wrong, more developer.android.com/studio/run/index.html#gradle-console
– pskink
Sep 27 '17 at 13:12
I'm building from Kotlin, maybe that's why I don't get the line?
– David Corsalini
Sep 27 '17 at 13:36
imho what you posted here is not gradle console output, are you sure you copied that error message from gradle console?
– pskink
Sep 27 '17 at 13:46
1
1
what is the full error message from gradle console?
– pskink
Sep 27 '17 at 11:17
what is the full error message from gradle console?
– pskink
Sep 27 '17 at 11:17
@pskink added the full error message to the question
– David Corsalini
Sep 27 '17 at 12:51
@pskink added the full error message to the question
– David Corsalini
Sep 27 '17 at 12:51
this is my method which compiles just fine:
@Query("SELECT * FROM user") LiveData<List<User>> loadUsers(); when i change List to Vector for example i am getting: UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers(); in the Gradle Console window of android studio - note it shows UserDao.java:19 which is a line location and also it prints the method that is wrong, more developer.android.com/studio/run/index.html#gradle-console– pskink
Sep 27 '17 at 13:12
this is my method which compiles just fine:
@Query("SELECT * FROM user") LiveData<List<User>> loadUsers(); when i change List to Vector for example i am getting: UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers(); in the Gradle Console window of android studio - note it shows UserDao.java:19 which is a line location and also it prints the method that is wrong, more developer.android.com/studio/run/index.html#gradle-console– pskink
Sep 27 '17 at 13:12
I'm building from Kotlin, maybe that's why I don't get the line?
– David Corsalini
Sep 27 '17 at 13:36
I'm building from Kotlin, maybe that's why I don't get the line?
– David Corsalini
Sep 27 '17 at 13:36
imho what you posted here is not gradle console output, are you sure you copied that error message from gradle console?
– pskink
Sep 27 '17 at 13:46
imho what you posted here is not gradle console output, are you sure you copied that error message from gradle console?
– pskink
Sep 27 '17 at 13:46
|
show 5 more comments
6 Answers
6
active
oldest
votes
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List to anything else inside the Dao. I'd assume Room doesn't know how to deal with other return types. Take the List and cast/convert it into your desired type outside of the Dao.
add a comment |
Add the below code inside defaultConfig in build.gradle
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
add a comment |
For my case, after got "Not sure how to convert a Cursor to this method's return type”:
delete the "build" and re-build, the error disappear.
add a comment |
class IdAndFullName {
public int uid;
@ColumnInfo(name = "full_name")
public String fullName;
}
// DAO
@Query("SELECT uid, name || lastName as full_name FROM user")
public IdAndFullName loadFullNames();
If there is a mismatch between the query result and the POJO, Room will give you this error message.
Or if you are using @SkipQueryVerification, you will also get this error.
add a comment |
Modify your Dao, use Flowable instead of observable and add the following dependency (room with rxjava support)
compile group: 'android.arch.persistence.room', name: 'rxjava2', version: '1.1.1'
Dao returns flowable:
@Query("SELECT * FROM TableX")
public abstract Flowable<List<EntityX>> getAllXs();
add a comment |
In my case i was this problem when i used LiveData<ArrayList<Example Class>> in Dao class for getting all things from Room and i fixed this when i change ArrayList with List.
Example(Kotlin):
@Dao
interface ExampleDao {
@Query("SELECT * from example_table")
fun getAllExample():LiveData<List<Example>>
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46445964%2froom-not-sure-how-to-convert-a-cursor-to-this-methods-return-type-which-meth%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List to anything else inside the Dao. I'd assume Room doesn't know how to deal with other return types. Take the List and cast/convert it into your desired type outside of the Dao.
add a comment |
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List to anything else inside the Dao. I'd assume Room doesn't know how to deal with other return types. Take the List and cast/convert it into your desired type outside of the Dao.
add a comment |
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List to anything else inside the Dao. I'd assume Room doesn't know how to deal with other return types. Take the List and cast/convert it into your desired type outside of the Dao.
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List to anything else inside the Dao. I'd assume Room doesn't know how to deal with other return types. Take the List and cast/convert it into your desired type outside of the Dao.
answered Oct 24 '17 at 8:38
Ali Kazi
9131018
9131018
add a comment |
add a comment |
Add the below code inside defaultConfig in build.gradle
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
add a comment |
Add the below code inside defaultConfig in build.gradle
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
add a comment |
Add the below code inside defaultConfig in build.gradle
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
Add the below code inside defaultConfig in build.gradle
javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true
answered Jun 2 at 6:28
vijay
7318
7318
add a comment |
add a comment |
For my case, after got "Not sure how to convert a Cursor to this method's return type”:
delete the "build" and re-build, the error disappear.
add a comment |
For my case, after got "Not sure how to convert a Cursor to this method's return type”:
delete the "build" and re-build, the error disappear.
add a comment |
For my case, after got "Not sure how to convert a Cursor to this method's return type”:
delete the "build" and re-build, the error disappear.
For my case, after got "Not sure how to convert a Cursor to this method's return type”:
delete the "build" and re-build, the error disappear.
answered May 7 at 3:49
David Guo
93711429
93711429
add a comment |
add a comment |
class IdAndFullName {
public int uid;
@ColumnInfo(name = "full_name")
public String fullName;
}
// DAO
@Query("SELECT uid, name || lastName as full_name FROM user")
public IdAndFullName loadFullNames();
If there is a mismatch between the query result and the POJO, Room will give you this error message.
Or if you are using @SkipQueryVerification, you will also get this error.
add a comment |
class IdAndFullName {
public int uid;
@ColumnInfo(name = "full_name")
public String fullName;
}
// DAO
@Query("SELECT uid, name || lastName as full_name FROM user")
public IdAndFullName loadFullNames();
If there is a mismatch between the query result and the POJO, Room will give you this error message.
Or if you are using @SkipQueryVerification, you will also get this error.
add a comment |
class IdAndFullName {
public int uid;
@ColumnInfo(name = "full_name")
public String fullName;
}
// DAO
@Query("SELECT uid, name || lastName as full_name FROM user")
public IdAndFullName loadFullNames();
If there is a mismatch between the query result and the POJO, Room will give you this error message.
Or if you are using @SkipQueryVerification, you will also get this error.
class IdAndFullName {
public int uid;
@ColumnInfo(name = "full_name")
public String fullName;
}
// DAO
@Query("SELECT uid, name || lastName as full_name FROM user")
public IdAndFullName loadFullNames();
If there is a mismatch between the query result and the POJO, Room will give you this error message.
Or if you are using @SkipQueryVerification, you will also get this error.
answered Jun 19 at 2:03
live-love
15.9k88173
15.9k88173
add a comment |
add a comment |
Modify your Dao, use Flowable instead of observable and add the following dependency (room with rxjava support)
compile group: 'android.arch.persistence.room', name: 'rxjava2', version: '1.1.1'
Dao returns flowable:
@Query("SELECT * FROM TableX")
public abstract Flowable<List<EntityX>> getAllXs();
add a comment |
Modify your Dao, use Flowable instead of observable and add the following dependency (room with rxjava support)
compile group: 'android.arch.persistence.room', name: 'rxjava2', version: '1.1.1'
Dao returns flowable:
@Query("SELECT * FROM TableX")
public abstract Flowable<List<EntityX>> getAllXs();
add a comment |
Modify your Dao, use Flowable instead of observable and add the following dependency (room with rxjava support)
compile group: 'android.arch.persistence.room', name: 'rxjava2', version: '1.1.1'
Dao returns flowable:
@Query("SELECT * FROM TableX")
public abstract Flowable<List<EntityX>> getAllXs();
Modify your Dao, use Flowable instead of observable and add the following dependency (room with rxjava support)
compile group: 'android.arch.persistence.room', name: 'rxjava2', version: '1.1.1'
Dao returns flowable:
@Query("SELECT * FROM TableX")
public abstract Flowable<List<EntityX>> getAllXs();
answered Oct 19 at 18:34
Mr.Q
1,77511826
1,77511826
add a comment |
add a comment |
In my case i was this problem when i used LiveData<ArrayList<Example Class>> in Dao class for getting all things from Room and i fixed this when i change ArrayList with List.
Example(Kotlin):
@Dao
interface ExampleDao {
@Query("SELECT * from example_table")
fun getAllExample():LiveData<List<Example>>
}
add a comment |
In my case i was this problem when i used LiveData<ArrayList<Example Class>> in Dao class for getting all things from Room and i fixed this when i change ArrayList with List.
Example(Kotlin):
@Dao
interface ExampleDao {
@Query("SELECT * from example_table")
fun getAllExample():LiveData<List<Example>>
}
add a comment |
In my case i was this problem when i used LiveData<ArrayList<Example Class>> in Dao class for getting all things from Room and i fixed this when i change ArrayList with List.
Example(Kotlin):
@Dao
interface ExampleDao {
@Query("SELECT * from example_table")
fun getAllExample():LiveData<List<Example>>
}
In my case i was this problem when i used LiveData<ArrayList<Example Class>> in Dao class for getting all things from Room and i fixed this when i change ArrayList with List.
Example(Kotlin):
@Dao
interface ExampleDao {
@Query("SELECT * from example_table")
fun getAllExample():LiveData<List<Example>>
}
answered Dec 20 at 19:44
Fidan Bacaj
7916
7916
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46445964%2froom-not-sure-how-to-convert-a-cursor-to-this-methods-return-type-which-meth%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
what is the full error message from gradle console?
– pskink
Sep 27 '17 at 11:17
@pskink added the full error message to the question
– David Corsalini
Sep 27 '17 at 12:51
this is my method which compiles just fine:
@Query("SELECT * FROM user") LiveData<List<User>> loadUsers();when i changeListtoVectorfor example i am getting:UserDao.java:19: error: Not sure how to convert a Cursor to this method's return type LiveData<Vector<User>> loadUsers();in the Gradle Console window of android studio - note it showsUserDao.java:19which is a line location and also it prints the method that is wrong, more developer.android.com/studio/run/index.html#gradle-console– pskink
Sep 27 '17 at 13:12
I'm building from Kotlin, maybe that's why I don't get the line?
– David Corsalini
Sep 27 '17 at 13:36
imho what you posted here is not gradle console output, are you sure you copied that error message from gradle console?
– pskink
Sep 27 '17 at 13:46