Error Casting Object[] To Contentvalues[]
I'm following a tutorial about content providers and, in a specific code, they inserted some data using a bulkInsert method. They also used a Vector variable (cVVector) to store al
Solution 1:
You can't cast Object[] to ContentValues[], because there is no relationship between these two types. They are different array types.
Just like you can cast an Object to a String like this :
Object a = "aa";
String b = (String) a;
because String is a subclass of Object.
But you can't do this :
Object[] ar = newObject[]{"aa", "bb"};
String[] br = (String[]) ar;
You will find this is OK in compile time, but will not work in runtime. The forced type conversion in JAVA may only work for single object not array.
You can replace your code with:
if (cVVector.size() > 0) {
mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, (ContentValues[]) cVVector.toArray(new ContentValues[1]));
}
Hope this can help you.
Post a Comment for "Error Casting Object[] To Contentvalues[]"