我正在尝试使用ParseQuery获取数据。但是findInBackground()方法总是返回NullPointerException。 以下是代码段:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if ((ni != null) && (ni.isConnected())) {
ParseQuery<Alert> query = Alert.getQuery();
query.whereEqualTo("category", "Emergency");
Log.d(TAG,"before calling query");
query.findInBackground(new FindCallback<Alert>() {
public void done(List<Alert> list, ParseException exp)
{
if(exp == null){
for(int i=0;i<list.size();i++)
{
Alert alert = list.get(i);
Log.d(TAG, "Title = "+ alert.getTitle() + " link = "+ alert.getLink());
}
} else {
Log.d(TAG,"no results !!"+ exp.getMessage()+" code ="+ exp.getCode());
}
};
});
}
我也检查了权限,在表格中显示了公共读/写ACL。
[编辑]在我的Application.java
中ParseObject.registerSubclass(Alert.class);
Parse.initialize(this, "ABC", "XYZ");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
所以有人可以建议我缺少什么吗?
答案 0 :(得分:2)
查询中的NullPointerException仅在2种情况下发生 -
该类尚未注册Parse.Solution是在Parse.initialize
之后添加以下行 -
ParseObject.registerSubclass(Alert.class);
类模型已在解析网站或Android代码中更改。解决方案是将表放在解析仪表板上。
答案 1 :(得分:0)
添加到Tushar的回复中,我遗漏的另一件事是Manifest文件中标记中的android:name字段。
<application
android:name ="com.tutorial.Alert.SampleApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >