Exception in removing item from array list in recycler view - android

I wrote some code for removing items from a recycler view objects. That is inside an array list
It works until the size and the index become equal or index become bigger. I really can't find the problem
public void deleteSelectedItems(){
if (selectedItemList.size() < 1)
return;
for(int i = 0 ; i < selectedItemList.size() ; i++){
int index = selectedItemList.get(i) ;
Log.e("AAA",index + "");
guitaristsList.remove(index);
}
selectedItemList.clear();
notifyDataSetChanged();
}
public void onClick(View v) {
if (isOnActionMode) {
if (chxDelete.isChecked())
selectedItemList.add(getAdapterPosition());
else
selectedItemList.remove((Object)getAdapterPosition());
if (onCheckboxClickListener != null)
onCheckboxClickListener.onCheckboxCheckedChanged(selectedItemList.size());
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.amehrvarz.mycontextual, PID: 12492
java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
at java.util.ArrayList.remove(ArrayList.java:503)
at com.amehrvarz.mycontextual.GuitaristAdapter.deleteSelectedItems(GuitaristAdapter.java:120)
at com.amehrvarz.mycontextual.MainActivity$3.onActionItemClicked(MainActivity.java:71)
at androidx.appcompat.app.AppCompatDelegateImpl$ActionModeCallbackWrapperV9.onActionItemClicked(AppCompatDelegateImpl.java:2452)
at androidx.appcompat.app.WindowDecorActionBar$ActionModeImpl.onMenuItemSelected(WindowDecorActionBar.java:1123)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:981)
at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.java:625)
at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:151)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 12492 SIG: 9

Related

illegalStateException about snackBar

I got illegalStateException when I compiled my snackbar. The result of App is that I can execute the first button but once I tried to use my second button the app will crush.
The code and error message are shown like this:
public void callIntent(View view) {
Intent intent = null;
switch (view.getId()) {
case R.id.ZhaoDisplay:
Toast toast = Toast.makeText(getApplicationContext(),
"Zhao Wang, 991556434; Website Name: Amazon", Toast.LENGTH_SHORT);
toast.show();
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.amazon.ca"));
startActivity(intent);
break;
case R.id.WangDisplay:
intent = new Intent(this, WangActivity.class);
//TextMulti
editInput = (EditText)findViewById(R.id.TextMulti);
String userInput = editInput.getText().toString();
intent.putExtra("valueFromUser", userInput);
Snackbar snackbar = null;
snackbar = Snackbar.make(findViewById(R.id.content),
"My Second Screen_Zhao Wang 991556434", 10);
snackbar.show();
startActivity(intent);
break;
default:
break;
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: zhao.wang.s991556434, PID: 15778
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:7125)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:7125)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalArgumentException: No suitable parent found from the given view. Please provide a valid view.
at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:158)
at zhao.wang.s991556434.ZhaoActivity.callIntent(ZhaoActivity.java:60)
at java.lang.reflect.Method.invoke(Native Method)
I tried to put snackbar code part to my second activity and compile it but it showed the same error. May I ask for assistance about this? Thanks.
The issue is with passing a wrong view for the snackbar make method, instead try the following
snackbar = Snackbar.make(findViewById(android.R.id.content),
"My Second Screen_Zhao Wang 991556434", 10);
snackbar.show();

Kotlin: How to call setText() using a Float data type?

How do I call setText() using float data type? I have already tried this
if (response.isSuccessful) {
val destination = response.body()
destination?.let {
client_names.setText(destination.client_name)
product_names.setText(destination.product_name)
amounts.setText(String.valueOf(destination.amount)) ----->
prices.setText(String.valueOf(destination.price)) ----->
comments.setText(destination.comment)
collapsing_toolbar.title = destination.client_name + destination.product_name
}
I have tried this answer from this link
How to call setText() using a Float data type?
but I get this error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartherd.globofly, PID: 8999
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at com.smartherd.globofly.activities.DestinationDetailActivity$loadDetails$1.onResponse(DestinationDetailActivity.kt:58)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 8999 SIG: 9
If you don't need any formatting just do:
setText("${destination.amount}")

java.lang.ArrayIndexOutOfBoundsException: Out of range

This is for app android, running Android studio, db realm and sql server. i need help
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_employee);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
realm = Realm.getDefaultInstance();
preferences = getSharedPreferences(PREFS_LOGIN, Context.MODE_PRIVATE);
recyclerView = findViewById(R.id.recyclerview);
singleItem = new ArrayList<>();
RealmResults<MdtmMandoranEmployeeDetail> resultEmployeeDetails = realm.where(MdtmMandoranEmployeeDetail.class)
.findAll().sort("employeename");
adapterListPemanen = new AdapterListPemanen(this, singleItem, this);
initVerticalRecycler();
for (int i = 0; i < 50; i++) {
DataPemanen data = realm.where(DataPemanen.class)
.equalTo("nik", resultEmployeeDetails.get(i).getEmployeeid())
.findFirst();
if (data == null) {
singleItem.add(new MdtmMandoranEmployeeDetail(resultEmployeeDetails.get(i).getMandoranemployeeid(),
resultEmployeeDetails.get(i).getEmployeeid(),
resultEmployeeDetails.get(i).getEmployeename()));
}
}
}
Error Log
E/REALM_JNI: jni: ThrowingException 2, Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0), .
Exception has been thrown: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hpi.android.bkm, PID: 16623
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hpi.android.bkm/com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity}: java.lang.ArrayIndexOutOfBoundsException: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Out of range in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
at io.realm.internal.OsResults.nativeGetRow(Native Method)
at io.realm.internal.OsResults.getUncheckedRow(OsResults.java:325)
at io.realm.OrderedRealmCollectionImpl.get(OrderedRealmCollectionImpl.java:124)
at io.realm.RealmResults.get(RealmResults.java:62)
at com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity.onCreate(ListEmployeeActivity.java:64)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6523) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
You for loop should be,
for (int i = 0; i < resultEmployeeDetails.size(); i++) {
....
....
}

Exception scrolling arraylist at second time

I have a problem when I try to delete elements on an arrayList. I need to put some elements on other array and then delete this elements from the original array. I put the code below:
private void setOrderAnswers(int position) {
for (int i = 0; i < 4; i++) {
listAnswersAux.add(listAnswers.get((position * 4) + i));
}
for (int i = 0; i < 4; i++) {
listAnswers.remove((position * 4) + i);
}
}
The error I have is an IndexOutOfBounds exception:
Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
I don't know why I have this exception when I try to remove this index, but when I go to the index to copy the element, there is no problem. I mean, the index is OK because I can see the element before delete it.
And I always have the exception on Index value = 10, I can do all this operations before going to index=10 (position = 2).
Can anyone helps me? Thanks a lot!
06-14 09:58:58.455 31337-31337/com.prodintec.am_motion E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.prodintec.am_motion, PID: 31337
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.prodintec.am_motion/com.prodintec.am_motion.QuizActivity}: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
at java.util.ArrayList.get(ArrayList.java:411)
at com.prodintec.am_motion.QuizActivity.setOrderAnswers(QuizActivity.java:201)
at com.prodintec.am_motion.QuizActivity.randomQuestions(QuizActivity.java:168)
at com.prodintec.am_motion.QuizActivity.onCreate(QuizActivity.java:48)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
try this
private void setOrderAnswers(int position) {
for (int i = 0; i < 4; i++) {
listAnswersAux.add(listAnswers.get((position * 4) + i));
listAnswers.remove((position * 4) + i);
}
}

Only getting first value from a record from cursor when trying to make a method to get a 2d array of strings to represent it

So I've got a database that's got one table, with two fields and one record. I'm using select to retrieve everything from that table, and passing the resulting cursor through this function to try to turn it into a jagged array of strings that will represent the table.
public String[][] cursorTo2dString (Cursor cursor, String[] fields) {
int columnCount = cursor.getColumnCount();
int count = cursor.getCount();
String[][] string2dArray = new String[columnCount][count];
Log.i("StringLengths", count + " & " + columnCount);
Log.i("CursorConts", DatabaseUtils.dumpCursorToString(cursor));
if (cursor.moveToFirst()) {
for (int j=0; j<count && !cursor.isAfterLast(); j++) {
for (int i=0; i<columnCount; i++) {
Log.i("Cursor", cursor.getString(i));
string2dArray[j][i] = cursor.getString(i);
Log.i("StringPoint", string2dArray[j][i]);
}
cursor.moveToNext();
}
}
For reference, whatever appears as the TagIdNo value is currently just a randomly generated number, I'm not actually going to generate this randomly on implementation, I'm just using this for the purposes of testing.
This consistently crashes with the following appearing in the console:
I/StringLengths: 1 & 2
I/CursorConts: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor#bd9f011
0 {
TagIdNo=998
TagName=No Parental Permission
}
<<<<<
I/Cursor: 998
I/StringPoint: 998
I/Cursor: No Parental Permission
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.programming.workingpomproject, PID: 23796
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5226) 
at android.view.View$PerformClick.run(View.java:21266) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:168) 
at android.app.ActivityThread.main(ActivityThread.java:5845) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.example.programming.workingpomproject.DbHelper.cursorTo2dString(DbHelper.java:132)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:89)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:92)
at com.example.programming.workingpomproject.MainActivity.testDbMethodGet(MainActivity.java:66)
at com.example.programming.workingpomproject.MainActivity.dbStuff(MainActivity.java:61)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5226) 
at android.view.View$PerformClick.run(View.java:21266) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:168) 
at android.app.ActivityThread.main(ActivityThread.java:5845) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 
I've used lots of different methods of taking the contents of the cursor, and no matter what I can only get the first value (the random number in this case) I put into the database. I was wondering if anyone can see why I'm not getting my second value (currently "no parental permission"), and if they could advise me as to how to retrieve it.
Sorry if I've messed up any coding standards; this is my first Android project and my first time in Java but I've been working on this app for a good few months so I'm hoping I'm getting better.
Any and all advice welcome!
EDIT 1:
If, as suggested by Giovanni, I swap the columns and rows in the instantiation, I get this instead:
String[][] string2dArray = new String[count][columnCount];
This leads to the following in the console, in the place of the other results:
I/CursorConts: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor#45e64e9
0 {
TagIdNo=3259
TagName=No Parental Permission
}
<<<<<
I/Cursor: 3259
I/StringPoint: 3259
I/Cursor: No Parental Permission
I/StringPoint: No Parental Permission
I/MovePos: true & false
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.programming.workingpomproject, PID: 24606
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at com.example.programming.workingpomproject.DbHelper.cursorTo2dString(DbHelper.java:155)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:89)
at com.example.programming.workingpomproject.DbHelper.select(DbHelper.java:92)
at com.example.programming.workingpomproject.MainActivity.testDbMethodGet(MainActivity.java:66)
at com.example.programming.workingpomproject.MainActivity.dbStuff(MainActivity.java:61)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5226)
at android.view.View$PerformClick.run(View.java:21266)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
This cursor problem seems to be the root problem, the array index one just being something I messed up in an attempt to avoid the cursor error.
Any further help is greatly appreciated!
You got an ArrayIndexOutOfBoundsException, which means that the array you want to assign in, does not have the correct size you are trying to access. For example, if I create an array like:
String[] array = new String[2];
int i = 3;
String s = array[i];
This will throw an exception, since my array has only place for 2 objects, not 3.
Your array is String[][] string2dArray = new String[columnCount][count];
I think you can fix it by changing it to:
String[][] string2dArray = new String[count][columnCount];
Because here:
for (int j = 0; j < count && !cursor.isAfterLast(); j++) {
for (int i = 0; i < columnCount; i++) {
Log.i("Cursor", cursor.getString(i));
// j should be count size, see the first for loop
string2dArray[j][i] = cursor.getString(i);
Log.i("StringPoint", string2dArray[j][i]);
}
cursor.moveToNext();
}

Categories

Resources