By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

array problem

P: 59
the problem is in for loop. note Log.d prints only 0 than the my problem crashes.

this code seem right to me. is there any thing iam missing?

Expand|Select|Wrap|Line Numbers
  1. public class test extends Activity implements View.OnClickListener {
  2.  
  3. int idArray[] = { R.id.imageButton1, R.id.imageButton2, R.id.imageButton3,
  4. R.id.imageButton4, R.id.imageButton5, R.id.imageButton6,
  5. R.id.imageButton7, R.id.imageButton8, R.id.imageButton9,
  6. R.id.imageButton10, R.id.imageButton11, R.id.imageButton12,
  7. R.id.imageButton13, R.id.imageButton14, R.id.imageButton15,
  8. R.id.imageButton16, R.id.imageButton17, R.id.imageButton18,
  9. R.id.imageButton19, R.id.imageButton20, R.id.imageButton21,
  10. R.id.imageButton22, R.id.imageButton23, R.id.imageButton24,
  11. R.id.imageButton25, R.id.imageButton26, R.id.imageButton27,
  12. R.id.imageButton28, R.id.imageButton29, R.id.imageButton30,
  13. R.id.imageButton31, R.id.imageButton32, R.id.imageButton33,
  14. R.id.imageButton34, R.id.imageButton35, R.id.imageButton36,
  15. R.id.imageButton37, R.id.imageButton38, R.id.imageButton39,
  16. R.id.imageButton40, R.id.imageButton41, R.id.imageButton42,
  17. R.id.imageButton43, R.id.imageButton44, R.id.imageButton45,
  18. R.id.imageButton46, R.id.imageButton47, R.id.imageButton48,
  19. R.id.imageButton49, R.id.imageButton50, R.id.imageButton51,
  20. R.id.imageButton52, R.id.imageButton53, R.id.imageButton54,
  21. R.id.imageButton55 };
  22.  
  23. Button buttons[] = new Button[idArray.length];
  24.  
  25.  
  26. @Override
  27. protected void onCreate(Bundle savedInstanceState) {
  28.     super.onCreate(savedInstanceState);
  29.  
  30.     for (int i = 0; i < idArray.length; i++) {
  31.         Log.d("DEBUG", " "+i);
  32.         buttons[i] = (Button) findViewById(idArray[i]);
  33.         buttons[i].setOnClickListener(this);
  34.       }
  35. }
  36.  
  37.  
  38. @Override
  39. public void onClick(View view) {
  40.  
  41. }
Sep 22 '13 #1
Share this Question
Share on Google+
1 Reply


Nepomuk
Expert 2.5K+
P: 3,112
Well, nothing that I can see is definitely wrong; however I don't know what the error message is. What exception is thrown? What is the stacktrace? Have you tried debugging this to see, where it crashes? I'm assuming it's in line 32 or 33.
Sep 22 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.