Android 如何修复返回代码为-1的Nullpointerexception的解析查询?

Android 如何修复返回代码为-1的Nullpointerexception的解析查询?,android,parse-platform,Android,Parse Platform,我正在尝试使用ParseQuery获取数据。但是findInBackground()方法总是返回NullPointerException。 以下是代码片段: ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if ((ni != null)

我正在尝试使用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());
                    }
                };

            });
        }

有人能告诉我我遗漏了什么吗?

一个查询中的NullPointerException只在2种情况下发生-

  • 该类尚未向Parse注册。解决方案是在
    Parse.initialize
    -

    ParseObject.registerSubclass(Alert.class)

  • parse网站或android代码中的类模型已经更改。解决方案是将表放到parse dashboard上


在Tushar的回复中添加了我遗漏的另一个内容,即清单文件中标记中的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" >


你能不能共享parse table我想你已经创建了
ParseObject
的Alert子类,但是没有在Application.java中注册它,就像
ParseObject.registerSubclass(Alert.class)一样注册它@ParagChauhan你是说从数据浏览器?@ved我尝试过,即使在这之后我得到了nullpointerexception,还缺少什么?是的,请确保您的表名、列名应为sameThanks以便响应…即使添加了它,我仍然得到了相同的nullpointerexception。你说的班级模式改变了是什么意思?因为我没有修改过任何地方。
<application
        android:name ="com.tutorial.Alert.SampleApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >