0

I know this has been asked a lot,but i'm really sorry,i am a noob in this,i'll just attach the code,here

 l =adminUserlst.split(",");
      UsrList = new ArrayList<String>();
      for(i=0;i<=l.length-1;i++){
      DatabaseReference db33 =firebaseDatabase.getReference("USERS/");
          db33.addListenerForSingleValueEvent(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  ***String spl=dataSnapshot.child(l[i]).child("sList").getValue().toString();//.split(",");
                  splits =spl.split(",");
                  for(ii=0;ii<=splits.length-1;ii++){
                      UsrList.clear();
                      UsrList.add(splits[ii]);
                      usrAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_dropdown_item, UsrList);
                      spinner.setAdapter(usrAdapter);

                  }

              }

              @Override
              public void onCancelled(DatabaseError databaseError) {

              }
          });


      }

I have some references in l,by which i want to extract some data from firebase database,so once i split the data,i'm using the split data present as a child node to get some more information,but for some reason i'm getting a ArrayIndexOutofBounds:length=1;index=1 at ***

Any help would be appreciated

3
  • 1
    Just check for 'less than' instead of 'less than or equal to' in a for-loop Commented Jul 19, 2017 at 9:58
  • @0xDEADC0DE should i do it in just one for loop or the second one as well ?? Commented Jul 19, 2017 at 10:04
  • You typically do that in each for loop, because containers are zero-based (i.e. they have an index 0) while the length function returns the size which is not zero-based. Commented Jul 19, 2017 at 10:09

1 Answer 1

1

check with writing your for loop condition in bracket like this

for(i=0;i<=(l.length-1);i++)

on both places

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.