gpt4 book ai didi

android - 从 Azure 移动服务本地数据库访问单个 Android 类中的两个不同表数据时出现错误

转载 作者:行者123 更新时间:2023-11-29 21:30:59 25 4
gpt4 key购买 nike

1.我在 Android 应用程序中使用两个不同的 Azure 本地数据库表,然后同步到 Azure 数据库。

2.每当我在单个类中使用两个不同的本地数据库表凭据时,我都会收到空指针异常

错误日志:

java.util.concurrent.ExecutionException: com.microsoft.windowsazure.mobileservices.table.sync.localstore.MobileServiceLocalStoreException: java.lang.NullPointerException
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at com.knowledgeflex.task.Unit_Activity$6.doInBackground(Unit_Activity.java:1071)
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at com.knowledgeflex.task.Unit_Activity$6.doInBackground(Unit_Activity.java:1058)
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-08 11:23:38.666 4742-5196/com.knowledgeflex.task W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-08 11:23:38.686 4742-5196/com.knowledgeflex.task W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

UnitActivity.class

 private MobileServiceSyncTable<TaskTable> mToDoTable;
private MobileServiceSyncTable<TasKUnitManagementTable>mToDoTablemgmtTable;
private MobileServiceClient mClient;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.unit_activity);


try {
// Create the Mobile Service Client instance, using the provided

// Mobile Service URL and key
mClient = new MobileServiceClient(
"********",
"************",
this).withFilter(new ProgressFilter());





// Offline Sync LOCAL DATABASE TABLE
mToDoTable =mClient.getSyncTable("TaskTable",TaskTable.class);

mToDoTablemgmtTable=mClient.getSyncTable("TasKUnitManagementTable",TasKUnitManagementTable.class);

//Init local storage
initLocalStore().get();
initLocalStore_1().get();





// Load the items from the Mobile Service
// refreshItemsFromTable();

} catch (MalformedURLException e) {

Log.i("Oncreate", "There was an error creating the Mobile Service. Verify the URL......!");

} catch (Exception e) {

Log.i("Oncreate", "Exception Occur......!");
}

}

帮助我如何在 Android 中的单个类中访问两个不同的 Azure 数据库本地表。

最佳答案

我预计此问题是由于您使用 initLocalStore() 的方式造成的,特别是调用它两次。

如果我们从快速入门中查看 initLocalStore 的代码,它将提供一些功能:

  1. 创建 SQLiteLocalStore
  2. 在该商店中定义一个表
  3. 初始化与该存储的同步上下文

您应该创建一个 SQLiteLocalStore,在其上定义所需数量的本地表,并初始化同步上下文。我已经用下面的一些代码演示了这一点。

MobileServiceSyncContext syncContext = mClient.getSyncContext();

if (syncContext.isInitialized())
return null;

SQLiteLocalStore localStore = new SQLiteLocalStore(mClient.getContext(), "OfflineStore", null, 1);

Map<String, ColumnDataType> tableDefinition = new HashMap<String, ColumnDataType>();
tableDefinition.put("id", ColumnDataType.String);
tableDefinition.put("text", ColumnDataType.String);
tableDefinition.put("complete", ColumnDataType.Boolean);

localStore.defineTable("ToDoItem", tableDefinition);

Map<String, ColumnDataType> nameTableDefinition = new HashMap<String, ColumnDataType>();
nameTableDefinition.put("id", ColumnDataType.String);
nameTableDefinition.put("name", ColumnDataType.String);

localStore.defineTable("NameTable", nameTableDefinition);

SimpleSyncHandler handler = new SimpleSyncHandler();

syncContext.initialize(localStore, handler).get();

关于android - 从 Azure 移动服务本地数据库访问单个 Android 类中的两个不同表数据时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35263423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com