2012-05-16 2 views
0

나는이 응용 프로그램에 문제가 :ArrayIndexOutOfBoundsException가

https://play.google.com/store/apps/details?id=org.me.gp.project.holidays.countdown

내가이 raport 있습니다. 내 친구 전화 및 에뮬레이터에서 모든 것이 정상입니다. 문제가있는 래프팅과 클래스 아래. 4x2 위젯을 담당하는 클래스입니다.

public class CountdownService extends Service { 
public static final String UPDATE = "update"; 
public static final String PLUS = "plus"; 
public static final String MINUS = "minus"; 
public static final long MODIFY= 86400000; 
Bitmap bla[]=null; 
private static final int kDigitsViewIds[] = { 
     R.id.bmp0, 
     R.id.bmp1, 

    }; 

@Override 
public void onStart(Intent intent, int startId) { 
    if (bla==null){ 
     getDigits(); 
    } 

    String command = intent.getAction(); 
    int appWidgetId = intent.getExtras().getInt(
      AppWidgetManager.EXTRA_APPWIDGET_ID); 
    RemoteViews remoteView = new RemoteViews(getApplicationContext() 
      .getPackageName(), R.layout.countdownwidget); 
    AppWidgetManager appWidgetManager = AppWidgetManager 
      .getInstance(getApplicationContext()); 
    SharedPreferences prefs = getApplicationContext().getSharedPreferences(
      "prefs", 0); 
    int year = prefs.getInt("year", 0); 
    int month =prefs.getInt("month", 0); 
    int day = prefs.getInt("day", 0); 

    //plus button pressed 

    TimeZone tz = TimeZone.getTimeZone("GMT+1:00"); 
    Date date1 = new Date(); 
    //Calendar calendar = new GregorianCalendar(2012, 05, 8, 18); 
    Calendar calendar = new GregorianCalendar(year, month, day); 
    calendar.setTimeZone(tz); 
    long timme = calendar.getTimeInMillis() - date1.getTime(); 
    int d = (int) ((timme/1000)/(3600*24)); 

    Bitmap[] bla = getDigits(); 

    String days=String.format("%02d", d); 

String time = days; 
char[] digits = time.toCharArray(); 

for (int i = 0; i <= 1; i++) { 
    char c =digits[i]; 
    int a=Character.getNumericValue(c); 
remoteView.setImageViewBitmap(kDigitsViewIds[i], bla[a]); 

} 


    // apply changes to widget 
    appWidgetManager.updateAppWidget(appWidgetId, remoteView); 
    super.onStart(intent, startId); 
} 
public Bitmap[] getDigits(){ 
    if (bla == null){ 
     bla = prepareDigits(); 

     } 
    return bla; 
    } 

@Override 
public IBinder onBind(Intent arg0) { 
    return null; 
} 

private Bitmap[] prepareDigits() { 
    int index = 10; 
    Bitmap[] bla = new Bitmap[index]; 
    for (int i = 0; i < index; i++) { 
    bla[1] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit1); 
    bla[2] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit2); 
    bla[3] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit3); 
    bla[4] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit4); 
    bla[5] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit5); 
    bla[6] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit6); 
    bla[7] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit7); 
    bla[8] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit8); 
    bla[9] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit9); 
    bla[0] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit0); 
    } 
    return bla; 
} 
} 

및 raport :

java.lang.RuntimeException: Unable to start service  
[email protected] with Intent { act=update 
dat=countdownwidget://widget/id/26#update26 flg=0x4 
cmp=org.me.gp.project.holidays.countdown/.CountdownService (has extras) }: 
java.lang.ArrayIndexOutOfBoundsException 
Caused by: java.lang.ArrayIndexOutOfBoundsException 
at org.me.gp.project.holidays.countdown.CountdownService.onStart 
(CountdownService.java:72) 
at android.app.Service.onStartCommand(Service.java:428) 
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2115) 

나는 내 기본 값은 0이

int year = prefs.getInt("year", 0); 
    int month =prefs.getInt("month", 0); 
    int day = prefs.getInt("day", 0); 

에, 잘못 데이터가 0.0.0이었다 지금 무엇을.

+0

CountdownService.java의 72 번째 줄은 어느 것입니까? – Squonk

+0

이것은 최고입니다 ... 72 행이 비어 있습니다 ... – Azor

답변

0
private Bitmap[] prepareDigits() { 
    int index = 10; 
    Bitmap[] bla = new Bitmap[index]; 
    for (int i = 0; i < index; i++) { 
     bla[1] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit1); 
     bla[2] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit2); 
     bla[3] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit3); 
     bla[4] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit4); 
     bla[5] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit5); 
     bla[6] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit6); 
     bla[7] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit7); 
     bla[8] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit8); 
     bla[9] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit9); 
     bla[0] =(Bitmap) BitmapFactory.decodeResource(getResources(), R.drawable.digit0); 
     } 
     return bla; 
    } 
} 

이것은 나에게 흥미 롭습니다. 10 크기의 비트 맵 배열을 만들고 10 회 반복하고 10 개의 드로어 블을 추가하는 것은 맞습니까? 또는 최소한 루프를 사용하지 않고도 bla[1] = ... 행을 유지할 수 있습니다. 또 다른 odditiy 당신이 개인적으로, 배열 인덱스 1에 0이 아닌

Bitmap[] bla = new Bitmap[index]; 
bla[0] = ((BitmapDrawable)getResources().getDrawable(R.drawable.digit0)).getBitmap(); 
bla[1] = ((BitmapDrawable)getResources().getDrawable(R.drawable.digit1)).getBitmap(); 
bla[2] = ((BitmapDrawable)getResources().getDrawable(R.drawable.digit2)).getBitmap(); 
// etc 

을 요소를 추가하기 시작하고있다, 난 당신이 List<Bitmap>를 사용한다고 생각합니다. 배열은 5 년 전입니다.

+0

Lol 덕분에 24digitalclock에서이 코드를 얻었고 어떻게 작동하는지 생각하지 않습니다. 나는 그것을 corect :) – Azor