从Parse - Null指针异常中检索数据

时间:2014-08-14 17:05:27

标签: java android android-layout android-activity parse-platform

我创建了一个个人资料创建页面,完成后,年龄,姓名,性别,搜索距离等信息将存储到解析中。现在我有了这些信息,检索它就是我遇到问题的地方。特别是,我只能成功检索objectID。从某种意义上说,列表只按其objectID填充列表用户。我试图使用他们的名字来填充,其他信息包括“标题”,“年龄”和“ProfilePicture”。

“姓名”,“年龄”,“标题”是字符串,用户已在其个人资料创建中记录了他们的信息。

“ProfilePicture”是一个文件,用户上传了他们的图片,并将其转换并存储为文件解析。

更新 NullPoint异常

08-14 19:06:09.375: E/AndroidRuntime(8886): FATAL EXCEPTION: main
08-14 19:06:09.375: E/AndroidRuntime(8886): Process: com.dooba.beta, PID: 8886
08-14 19:06:09.375: E/AndroidRuntime(8886): java.lang.NullPointerException
08-14 19:06:09.375: E/AndroidRuntime(8886):     at com.dooba.beta.ProfileCreation$1.onClick(ProfileCreation.java:144)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at android.view.View.performClick(View.java:4438)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at android.view.View$PerformClick.run(View.java:18422)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at android.os.Handler.handleCallback(Handler.java:733)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at android.os.Handler.dispatchMessage(Handler.java:95)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at android.os.Looper.loop(Looper.java:136)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at android.app.ActivityThread.main(ActivityThread.java:5017)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at java.lang.reflect.Method.invokeNative(Native Method)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at java.lang.reflect.Method.invoke(Method.java:515)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-14 19:06:09.375: E/AndroidRuntime(8886):     at dalvik.system.NativeStart.main(Native Method)
08-14 19:06:11.507: I/Process(8886): Sending signal. PID: 8886 SIG: 9
08-14 19:06:11.995: D/dalvikvm(8946): GC_FOR_ALLOC freed 192K, 8% free 2928K/3176K, paused 7ms, total 7ms

@覆盖         protected void onCreate(Bundle savedInstanceState){             super.onCreate(savedInstanceState);             的setContentView(R.layout.matching);

        logoutButton = (Button) findViewById(R.id.logoutButton);
        logoutButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ParseUser.logOut();
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
            }
        });

        setConversationsList();
    }
    private void setConversationsList() {
        currentUserId = ParseUser.getCurrentUser().getObjectId();
        names = new ArrayList<String>();
      // String userActivitySelectionName = null;

           ParseQuery<ParseUser> query = ParseUser.getQuery();

         //  query.whereEqualTo("ActivityName",userActivitySelectionName);

           query.whereNotEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
           // users with Gender = currentUser.Looking_Gender
           query.whereEqualTo("Gender", userLookingGender);
           // users with Looking_Gender = currentUser.Gender
           query.whereEqualTo("Looking_Gender", userGender);
           query.whereEqualTo("ActivityName", activityName);
           query.whereGreaterThanOrEqualTo("Minimum_Age", minimumAge);
           query.whereLessThanOrEqualTo("Maximum_Age", maximumAge);
    //     query.whereWithinKilometers("Maximum_Distance", point, maxDistance)





        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> userList, ParseException e) {
                if (e == null) {
                    for (int i=0; i<userList.size(); i++) {
                        names.add(userList.get(i).get("Name").toString());
                        names.add(userList.get(i).get("Headline").toString());
                        names.add(userList.get(i).get("Age").toString());


                    }

                    usersListView = (ListView)findViewById(R.id.usersListView);
                    namesArrayAdapter =
                        new ArrayAdapter<String>(getApplicationContext(),
                            R.layout.user_list_item, names);
                    usersListView.setAdapter(namesArrayAdapter);

                    usersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> a, View v, int i, long l) {
                            openConversation(names, i);
                        }
                    });

                } else {
                    Toast.makeText(getApplicationContext(),
                        "Error loading user list",
                            Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    public void openConversation(ArrayList<String> names, int pos) {
        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.whereEqualTo("Name", names.get(pos));
        query.findInBackground(new FindCallback<ParseUser>() {
           public void done(List<ParseUser> user, ParseException e) {
               if (e == null) {
                   Intent intent = new Intent(getApplicationContext(), MessagingActivity.class);
                   intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
                   startActivity(intent);
               } else {
                   Toast.makeText(getApplicationContext(),
                       "Error finding that user",
                           Toast.LENGTH_SHORT).show();
               }
           }
        });
    }
}

提前感谢您的支持,并提出建议。

0 个答案:

没有答案