Array per popolare la GridView:
static final String[] orari_i = new String[]{
"08:00", "08:15", "08:30", "08:45", "09:00", "09:15", "09:30", "09:45", "10:00", "10:15",
"10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00", "12:15", "12:30", "12:45",
"13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15",
"15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45",
"18:00", "18:15", "18:30", "18:45", "19:00", "19:15", "19:30", "19:45"};
in base alle ore presenti nel database, se la stessa, assegno il colore alla stringa dell'array. perchè ottengo
IndexOutOfBoundsException?
private void Color() {
SQLiteDatabase db = new DatabaseHelper(this).getReadableDatabase();
final List<Dettaglio> dettagli1 = new ArrayList<Dettaglio>();
String tabella_op = "SELECT .......";
Cursor cur = db.rawQuery(tabella_op, null);
while (cur.moveToNext()) {
Dettaglio d1 = new Dettaglio();
d1.coloreOre = cur.getInt(0); //color
d1.stringora= cur.getString(1);
dettagli1.add(d1);
}
cur.close();
db.close();
orari_inizio.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, orari_i) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
Dettaglio d1 = dettagli1.get(position);
if (orari_i[position].equals(d1.ora_inizio)) {
text.setTextColor(d1.colore);
}
return view;
}
});
logcat
FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at appuntamenti.Inserisci_mo$3.getView(Inserisci_mo.java:373)
at android.widget.AbsListView.obtainView(AbsListView.java:2696)
at android.widget.GridView.onMeasure(GridView.java:1048)
at android.view.View.measure(View.java:16271)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:16271)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1034)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:16271)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16271)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2501)
at android.view.View.measure(View.java:16271)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2182)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1330)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1541)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1227)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4995)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
la riga incriminata è:
Dettaglio d1 = dettagli1.get(position);
if (orari_i[position].equals(d1.ora_inizio)) {
text.setTextColor(d1.colore);
}