2016-07-29 49 views
1

我有以下問題:分析查詢總是返回一個空列表

我有兩個Android應用:在一個應用程序,我通過解析數據添加到蒙戈DB和其他應用程序,我想要從添加的信息第一個應用程序。

問題是,在第二個應用程序中,每次嘗試查詢數據庫時,都會得到一個空列表。我使用API​​ KEY檢查了Mongo DB的密鑰,並且在我的應用程序中一切似乎都正常。

這裏是代碼的第二應用在RecyclerView

public class ParseDb extends Application { 

@Override 
public void onCreate() { 
    super.onCreate(); 

    // Enable Local Datastore. 
    Parse.enableLocalDatastore(this); 

    // Add your initialization code here 
    Parse.initialize(new Parse.Configuration.Builder(getApplicationContext()) 
      .applicationId(API_KEY) 
      .server("http://injuriesandsuspensions.herokuapp.com/parse/") 
      .build() 
    ); 




    ParseUser.enableAutomaticUser(); 
    ParseACL defaultACL = new ParseACL(); 
    // Optionally enable public read access. 
    defaultACL.setPublicReadAccess(true); 
    ParseACL.setDefaultACL(defaultACL, true); 

} 

public class MainActivity extends Activity { 

private List<AboutTeams> aboutTeamsList = new ArrayList<AboutTeams>(); 
private RecyclerView recyclerView; 
private GamesAdapter gamesAdapter; 

public void retrieveGamesFromDatabase(){ 
    ParseQuery<ParseObject> query = ParseQuery.getQuery("InjuriesAndSuspensions"); 
    query.whereEqualTo("score", "none"); 
    query.findInBackground(new FindCallback<ParseObject>() { 
     public void done(List<ParseObject> gamesList, ParseException e) { 
      if (e == null) { 
       Log.d("score", "Retrieved " + gamesList.size() + " scores"); 
       for(int i = 0; i < gamesList.size(); i++){ 
        AboutTeams aboutTeams = new AboutTeams(); 
        aboutTeams.setId(String.valueOf(gamesList.get(i).getObjectId())); 
        aboutTeams.setScore(String.valueOf(gamesList.get(i).get("score"))); 
        aboutTeams.setHomeTeam(String.valueOf(gamesList.get(i).get("homeTeam"))); 
        aboutTeams.setHomeTeamMissing(String.valueOf(gamesList.get(i).get("homeTeamMissingPlayers"))); 
        aboutTeams.setAwayTeam(String.valueOf(gamesList.get(i).get("awayTeam"))); 
        aboutTeams.setAwayTeamMissing(String.valueOf(gamesList.get(i).get("awayTeamMissingPlayers"))); 
        aboutTeams.setDate(String.valueOf(gamesList.get(i).get("gameDate"))); 
        Log.d("About Teams " , aboutTeams.toString()); 
        aboutTeamsList.add(aboutTeams); 
        gamesAdapter.notifyDataSetChanged(); 
       } 

      } else { 
       Log.d("score", "Error: " + e.getMessage()); 
      } 
     } 
    }); 
} 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_listview); 

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 

    gamesAdapter = new GamesAdapter(aboutTeamsList); 

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext()); 
    recyclerView.setLayoutManager(mLayoutManager); 
    recyclerView.setItemAnimator(new DefaultItemAnimator()); 
    recyclerView.setAdapter(gamesAdapter); 

    retrieveGamesFromDatabase(); 

} 

請幫助爲I`ve這個東西一直在掙扎了將近3天檢索信息。

+0

?你應該提供一些日誌或你得到的錯誤... –

+0

我的查詢query.whereEqualTo(「score」,「none」);在數據庫中有這個。不是查詢是問題,因爲我沒有得到任何錯誤。我一直得到一個空列表。我也試圖從「傷病和懸崖」中獲得所有的物品,但仍然空空如也。 – dragosiv

+0

使用儀表板驗證目標分析對象上的ACL prop值,然後確保查詢具有通過目標對象上的ACL從關聯用戶權限獲得的主鍵或推斷訪問。 –

回答

0

當我加入到收藏數據庫信息,我用didn`t的的parseObject這行加入,我在我的應用程序初始化解析:

defaultACL.setPublicReadAccess(真);

如何初始化解析完整代碼:如果你有空List這是確定的,如果你的查詢犯規匹配任何合適的

public class AddToDB extends Application { 

@Override 
public void onCreate() { 
    super.onCreate(); 

    // Enable Local Datastore. 
    Parse.enableLocalDatastore(this); 

    // Add your initialization code here 
    Parse.initialize(new Parse.Configuration.Builder(getApplicationContext()) 
      .applicationId(API_KEY) 
      .server(SERVER_URL) 
      .build() 
    ); 


    ParseUser.enableAutomaticUser(); 
    ParseACL defaultACL = new ParseACL(); 
    // Optionally enable public read access. 
    **defaultACL.setPublicReadAccess(true);** 
    ParseACL.setDefaultACL(defaultACL, true); 
} 

}