1.我在我的Android应用程序中使用两个不同的Azure本地数据库表,然后同步到Azure数据库。
2.无论何时我在单一类中使用两个不同的本地数据库表凭据,我将获得空指针异常。
错误Logcat:
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数据库本地表。
答案 0 :(得分:0)
我希望这个问题是由于你如何使用initLocalStore(),特别是调用它两次。
如果我们从快速入门查看initLocalStore的代码,它可以提供一些功能:
您应该创建一个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();