键入错误使用 Google 表格 api 将列分配给 Java 中的 ValueRange

“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>> 我是否错过了创建类?为什么会抛出这个错误。


慕运维8079593
浏览 144回答 1
1回答

繁花不似锦

更改String为Object。ValueRange&nbsp;body&nbsp;=&nbsp;new&nbsp;ValueRange().setValues( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Arrays.asList( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Arrays.asList((Object)"Row&nbsp;1&nbsp;Cell&nbsp;1",&nbsp;(Object)"Row&nbsp;1&nbsp;Cell&nbsp;2",(Object)&nbsp;"Row&nbsp;1&nbsp;Cell&nbsp;3"), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Arrays.asList((Object)"Row&nbsp;2&nbsp;Cell&nbsp;1",(Object)&nbsp;"Row&nbsp;2&nbsp;Cell&nbsp;2",&nbsp;(Object)"Row&nbsp;2&nbsp;Cell&nbsp;3")));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java