내가 만드는 앱에는 사용자가 스크롤 할 수있는 사진이 많이 있습니다. 앱에는 개체 배열이 있고 각 개체에는 그림과 통계량. 나는 응용 프로그램이 종료 구축하고 오류 "죄송합니다, 응용 프로그램이 예기치 않게 중지"를 불러와 로그 캣 그래도내 배열이 특정 길이 인 경우 Android 앱이 실행되지 않음
10-25 18:46:24.578: ERROR/AndroidRuntime(491): FATAL EXCEPTION: main
10-25 18:46:24.578: ERROR/AndroidRuntime(491): java.lang.RuntimeException: Unable to
instantiate activity ComponentInfo{com.example.notes/com.example.notes.NotesListActivity}:
java.lang.ArrayIndexOutOfBoundsException
를 보여주고 여기에있을 때 내 응용 프로그램은 이제하지만, 내 배열은 58 개체를 포함 할 것입니다 완벽하게 실행되었다 내 현재 코드
public class NotesListActivity extends Activity implements OnClickListener
{
public boolean nextClicked = false;
public boolean prevClicked = false;
public int counter = 1;
public int nextImg;
public FunnyPic[] picArray = new FunnyPic[55];
{
picArray[0] = new FunnyPic(R.raw.img1, 0);
picArray[1] = new FunnyPic(R.raw.img2, 0);
.....
.....
.....
picArray[180] = new FunnyPic(R.raw.img181, 0);
picArray[181] = new FunnyPic(R.raw.img182, 0);
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button changePicButton = (Button) this.findViewById(R.id.button1);
changePicButton.setOnClickListener(this);
}
public void onClick(View view)
{
Log.i("onClick", "BEGIN");
ImageView image = (ImageView) findViewById(R.id.imageView1);
if(counter == picArray.length-1)
counter=0;
image.setImageResource(picArray[counter].getImg());
counter++;
Log.i("onClick", "END");
}
public void prevPicHandler(View traget)
{
if(counter==0)
{
counter = picArray.length-1;
}
counter--;
Log.i("onClick", "BEGIN");
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(picArray[counter].getImg());
Log.i("onClick", "END");
}
}
제안 사항이 있으면 알려주십시오. 또한 누구든지 배열에 개체를 넣을 더 효율적인 방법을 추천 할 수 있다면 새로운 그림을 추가 할 때마다 수동으로 넣지 않아도됩니다.
감사
와우 나는 어리석은 하하를 느낍니다. 어떻게 보지 못했습니까? –