如何获取Parse用户名的List <parseuser>?

时间:2015-08-27 18:43:10

标签: android list parse-platform android-arrayadapter multiautocompletetextview

我的活动中有这个代码:

ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.findInBackground(new FindCallback<ParseUser>() {
        public void done(List<ParseUser> userList, ParseException e) {
            if (e == null) {
                Log.d("score", "Retrieved " + userList.size() + " scores");
                for (int i = 0; i < userList.size(); i++) {
                    friends.add(userList.toString());
                }
                aAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_dropdown_item_1line, friends);
                friendChooser.setAdapter(aAdapter);
            } else {
                Log.d("score", "Error: " + e.getMessage());
            }
        }
    });

问题是这个数组包含所有列,当我想只得到&#34;用户名&#34;领域。我怎样才能获得&#34;用户名&#34;领域?
另一个问题是,因为在User表中有一个名为&#34; emailVerified&#34;的布尔字段,而aAdapter是ArrayAdapter<String,它内部不能有布尔值,因此应用程序崩溃了。再说一遍,我怎么才能得到&#34;用户名&#34;场?

崩溃的Logcat:

java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
        at com.intap.tof.GameActivity$3.done(GameActivity.java:189)
        at com.intap.tof.GameActivity$3.done(GameActivity.java:184)
        at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:107)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5832)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

使用@MarinaBatista的回答崩溃:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
        at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
        at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
        at com.intap.tof.GameActivity$3.done(GameActivity.java:192)
        at com.intap.tof.GameActivity$3.done(GameActivity.java:184)
        at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:107)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:145)

错误行:
GameActivity.java:192 - friendChooser.setAdapter(aAdapter);
GameActivity.java:184 - public void done(List<ParseUser> userList, ParseException e) {

对你来说:
aAdapterArrayAdapter<String>
friendChooserMultiAutoCompleteTextView
friendsList<String>
userListList<ParseUser>

2 个答案:

答案 0 :(得分:1)

您必须从列表中获取对象,然后从中获取用户名(docs):

Teuchos::RCP

答案 1 :(得分:0)

而不是:

 friends.add(userList.get(i).getUsername());

试试这个:

...
  <repositories>
    <repository>
      <id>my-repo1</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
    <repository>
      <id>my-repo2</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
  </repositories>
...
</project>