- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将谷歌电子表格用作 android 中的简单数据库。但是当我调用电子表格时,我得到 NullpointerExeptions当我试图获取工作表的大小时,它返回 0。例如,当我调用 getAllCells()
时,我得到一个 NullpointerExeption。感谢您提供的任何帮助/建议。
(我制作了电子表格发布到网络并且知道链接的任何人都可以编辑)
这是电子表格 https://docs.google.com/spreadsheets/d/1arJFUxSghwdv0QpnJJ3lBu36X4I3d_uB4xx_xNGLKHU/edit#gid=0
这是小项目的 zip 文件 https://drive.google.com/file/d/0B36AnWs56yGIdVFpdzNxSE9BSlU/view?usp=sharing
这是apk https://drive.google.com/file/d/0B36AnWs56yGITkIyUGpJcHpuUlk/view?usp=sharing
这里是错误
java.lang.NullPointerException
1at com.google.gdata.data.spreadsheet.WorksheetEntry.getFeedUrlString(WorksheetEntry.java:133)
2at com.google.gdata.data.spreadsheet.WorksheetEntry.getCellFeedUrl(WorksheetEntry.java:113)
3at com.example.tempo.util.SpDatabase.getAllCells(SpDatabase.java:67)
4at com.example.tempo.TempoMain.testDataBase(TempoMain.java:101)
5at com.example.tempo.TempoMain$1$1.doOnBackground(TempoMain.java:70)
6at com.example.tempo.util.AsyncJob$2.run(AsyncJob.java:59)
7at java.lang.Thread.run(Thread.java:841)
这是我用来访问它的java类
package com.example.tempo.util;
import android.widget.Toast;
import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.net.*;
import java.util.*;
public class SpDatabase {
WorksheetEntry worksheet;
SpreadsheetService service;
String spTitle;
public SpDatabase()throws AuthenticationException, MalformedURLException, IOException, ServiceException {
service = new SpreadsheetService("MySpreadsheetIntegration-v1");
// TODO: Authorize the service object for a specific user (see other sections)
// Define the URL to request. This should never change.
String key = "1arJFUxSghwdv0QpnJJ3lBu36X4I3d_uB4xx_xNGLKHU";
URL SPREADSHEET_FEED_URL = FeedURLFactory.getDefault().getWorksheetFeedUrl(key, "public", "basic");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
if (spreadsheets.size() == 0) {
// TODO: There were no spreadsheets, act accordingly.
}
// TODO: Choose a spreadsheet more intelligently based on your
// app's needs.
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
spTitle = spreadsheet.getTitle().getPlainText();
// Make a request to the API to fetch information about all
// worksheets in the spreadsheet.
List<WorksheetEntry> worksheets = spreadsheet.getWorksheets();
// WorksheetEntry worksheet = worksheets.get(0);
worksheet = worksheets.get(0);
}
public int getRowCount(){
int rowCount = worksheet.getRowCount();
return rowCount;
}
public int getColumnCount(){
int columnCount = worksheet.getColCount();
return columnCount;
}
public ArrayList<CellEntry> getAllCells() throws IOException, ServiceException{
// Fetch the cell feed of the worksheet.
URL cellFeedUrl = worksheet.getCellFeedUrl();
CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
return (ArrayList<CellEntry>) cellFeed.getEntries();
}
// or getRow() or getCollumn()
public ArrayList<CellEntry> getSpecificCells(int minRow, int maxRow, int minCol, int maxCol) throws IOException, ServiceException, URISyntaxException{
//example: Fetch column 4, and every row after row 1 --> "?min-row=2&min-col=4&max-col=4"
String pref = "?";
if(minRow != -1){
pref = appendAndIfFirstValue(pref);
pref += "min-row=" + minRow;
}
if(minCol != -1){
pref = appendAndIfFirstValue(pref);
pref += "&min-col=" + minCol;
}
if(maxRow != -1){
pref = appendAndIfFirstValue(pref);
pref += "&max-row=" + maxRow;
}
if(maxCol != -1){
pref = appendAndIfFirstValue(pref);
pref += "&max-col=" + maxCol;
}
// Fetch column 4, and every row after row 1.
URL cellFeedUrl = new URI(worksheet.getCellFeedUrl().toString() + pref).toURL();
CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
return (ArrayList<CellEntry>) cellFeed.getEntries();
}
public int getCellNumValue(CellEntry cell){
return (Integer) cell.getCell().getNumericValue();
}
public String getCellStringValue(CellEntry cell){
return cell.getCell().getValue();
}
public void incrementCellValue(CellEntry cell) throws IOException, ServiceException{
String cellID = cell.getTitle().getPlainText();
cell.changeInputValueLocal("=SUM(" + cellID + ", 1)");
cell.update();
}
public void changeCellValue(CellEntry cell, String value) throws IOException, ServiceException{
cell.changeInputValueLocal(value);
cell.update();
}
private String appendAndIfFirstValue(String str){
if(!str.contains("&")){
return "&" + str;
}else{
return str;
}
}
public String getSpreadSheetTitle() throws IOException, ServiceException, URISyntaxException{
return spTitle;
}
}
最佳答案
事实证明,问题出在投影的范围上,根据 google 的文档,电子表格提要仅支持“私有(private)”可见性和“完整”投影。
我使用的是 'public'
和 'basic'
所以我解决这个问题的方法是像这样直接访问工作表(支持更多可见性参数):
public SpDatabase()throws AuthenticationException, MalformedURLException, IOException, ServiceException {
service = new SpreadsheetService("Test");
FeedURLFactory factory = FeedURLFactory.getDefault();
String key = "1arJFUxSghwdv0QpnJJ3lBu36X4I3d_uB4xx_xNGLKHU";
URL spreadSheetUrl = factory.getWorksheetFeedUrl(key, "public", "full");
WorksheetFeed feed = service.getFeed(spreadSheetUrl, WorksheetFeed.class);
worksheet = feed.getEntries().get(0);
URL cellFeedURL = worksheet.getCellFeedUrl();
CellFeed cellFeed = service.getFeed(cellFeedURL, CellFeed.class);
}
关于java - 尝试从公共(public) Google 电子表格读取数据时出现 NullPointerExceptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29882934/
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: When should [assembly: InternalsVisibleTo()] be used?
问题与微服务有关,当我有多个微服务提供将被订购和计费的功能/服务时。 我正在确定采用哪种方法, a) 每个可计费微服务有一个订单和一个计费服务,有各自的数据库。b) 跨所有微服务的通用订单管理和计费服
我正在尝试使用 gcloud图书馆。 (ns firengine.state (:import [com.google.cloud AuthCredentials] [com.goog
Java 允许定义以下一对类。 class Class1 { ... } public Class2 { public Class2(Class1 c1) { ... } } 如果因为 Class1
我正在尝试查找文件 1 和文件 2 中的共同行。如果公共(public)行存在,我想写入文件 2 中的行,否则打印文件 1 中的非公共(public)行。fin1 和 fin2 是这里的文件句柄。它读
好吧,这是一个满口的标题。不过,这让我明白了。这是我的代码的要点,在 jar 里: public class NetworkShared { public static class Login
我在使用 ltree 时遇到 PHP 问题来自 PostgreSQL .我在 SQL 中这样做: SELECT * FROM tabla t WHERE t.parent_path " for "OP
我知道如何为类/接口(interface)/包的子集生成 Javadoc。但是有没有办法只为公共(public)方法的一个子集生成 Javadoc? 我更喜欢能够将方法(Javadoc 标记或注释)标
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: c#: why have empty get set properties instead of usin
在我们的每个项目中,都有一个文件用于存储该项目中使用的各种SQL 语句。类的声明方式和字符串的声明方式有一些变化。 示例类声明: internal sealed class ClassName int
我根据 http://docs.jquery.com/Plugins/Authoring 定义了我的插件 (function( $ ){ var methods = { init : fu
我正在使用 Inno Setup 来构建我的安装程序,我有 C:\Users\Public文件夹硬编码在我的 [Files] 中放置一些文件的部分(Inno Setup 没有此文件夹的常量) 我的目标
我有一个 dataframe1 包含像 'ID', 'A', 'B', 'C', 'D', 'E', 'F', 'G' 这样的列. 现在,我创建了两个数据框, dataframe2 包含 'ID',
我有一个抽象类,不幸的是我无法更改它的定义,它基本上提供了一个抽象方法,有点像。 public abstract void do(Data someData, BaseInterface interf
我刚刚在重构时偶然发现了一段奇怪的代码。它看起来像是分解出两个 readString() 方法的共同部分的候选者,只是它似乎是不可能的(这对我来说是一个令人毛骨悚然的脑筋急转弯): private f
是否有解析为公用文件夹的属性?显然,我不想在目录结构中对“c:\users\public”进行硬编码,但我找不到预定义的 Property解决这个问题。是否有一种可接受的方式来指定要在此处安装和/或在
我试图将值从一个类传递到另一个类。 subPanel1 类读取全局变量,但当我通过调整监听器更新这些变量时,它不会更改值。我试图将 rc、gc 和 bc 变量从 subPanel2 类传递到 subP
我想使用具有自动属性的干净且编码较少的类。所有属性(property)都是公共(public)的。在同一类的方法中我也使用了该属性。因此,我认为这种方法是可混搭的,因为我将公共(public)属性用于
不久前,我在 Android 应用程序中创建了一个 SQLiteHelper 类。我不是 100% 确定原因,但表名和列名是嵌套公共(public)静态抽象类中的公共(public)静态最终字段。我记
这个问题已经有答案了: Cannot make a static reference to the non-static method (8 个回答) 已关闭 3 年前。 我正在为类(class)做一
我是一名优秀的程序员,十分优秀!