“java.lang.String 无法转换为 java.lang.Object” public class SheetsQuickstart { private static final String APPLICATION_NAME = "Google Sheets API Java Quickstart"; private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); private static final String TOKENS_DIRECTORY_PATH = "tokens"; /** * Global instance of the scopes required by this quickstart. * If modifying these scopes, delete your previously saved tokens/ folder. */ private static final List<String> SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS_READONLY); private static final String CREDENTIALS_FILE_PATH = "/credentials.json"; /** * Creates an authorized Credential object. * @param HTTP_TRANSPORT The network HTTP Transport. * @return An authorized Credential object. * @throws IOException If the credentials.json file cannot be found. */ public ValueRange getValues(String spreadsheetId, String range, Sheets service) throws IOException { // [START sheets_get_values] ValueRange result = service.spreadsheets().values().get(spreadsheetId, range).execute(); int numRows = result.getValues() != null ? result.getValues().size() : 0; System.out.printf("%d rows retrieved.", numRows); // [END sheets_get_values] return result; }它抛出错误:(104, 30) java: incompatible types: java.util.List< java.util.List< java.lang.String >> cannot be convert to java.util.List< java.util.List < java .lang.Object>> 我是否错过了创建类?为什么会抛出这个错误。
1 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
更改String
为Object
。
ValueRange body = new ValueRange().setValues( Arrays.asList( Arrays.asList((Object)"Row 1 Cell 1", (Object)"Row 1 Cell 2",(Object) "Row 1 Cell 3"), Arrays.asList((Object)"Row 2 Cell 1",(Object) "Row 2 Cell 2", (Object)"Row 2 Cell 3")));
添加回答
举报
0/150
提交
取消