I have different tables according to the level the user is in, my code should set the rows of every active table to Visible. So if the user is in level 5, all rows are set as visible until we reach the tablelevel5. The problem is that when I get the row whit getChildAt I get a NullPointerException. Why is that?
for (int i = 0; i<=sharedPreferences.getInt("tableCurrentNumber",1); i++){
for (int n = 1; i <= verticalLayout.getChildCount(); n++){
String tableID = "tableLevel" + Integer.toString(n);
int resID = getResources().getIdentifier(tableID, "id", getPackageName());
tableFor = ((TableLayout) findViewById(resID));
for (int z = 1; z<=tableFor.getChildCount(); z++){
tableFor.getChildAt(z).setVisibility(View.VISIBLE);
}
}
}
logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.root.exercicis/com.example.root.exercicis.SettingsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.TableLayout.getChildCount()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.TableLayout.getChildCount()' on a null object reference
at com.example.root.exercicis.SettingsActivity.onCreate(SettingsActivity.java:200)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
your for loop starts with 1 , it should start with 0
for (int z = 0; z < tableFor.getChildCount(); z++){
tableFor.getChildAt(z).setVisibility(View.VISIBLE);
}
for (int n = 0; i < verticalLayout.getChildCount(); n++){
}
Related
so im doing a school project on a movie review app. so heres my code for the next and previous button. The next button works fine without crashing. when i press back it works but once it reaches the very first movie and i press back again the app crashes.
private Movie movies[]= new Movie[5];
public MovieCollection(){
prepareMovies();
}
public Movie searchById(String id){
Movie movie = null;
for(int index=0; index < movies.length; index++){
movie = movies[index];
if(movie.getId().equals(id)){
return movie;
}
}
return movie;
}
public Movie getNextMovie(String currentMovieId){
Movie movie = null;
for(int index = 0; index < movies.length; index++) {
String tempMovieId = movies[index].getId();
if (tempMovieId.equals(currentMovieId) && (index < movies.length - 1)) {
movie = movies[index + 1];
break;
}
}
return movie;
}
public Movie getPrevMovie(String currentMovieId){
Movie movie = null;
for(int index = 0; index < movies.length; index++){
String tempMovieId = movies[index].getId();
if(tempMovieId.equals(currentMovieId) && (index > 0)){
movie = movies[index - 1];
break;
}
}
return movie;
}
my code for the button.
public void goNext(View view){
Movie nextMovie = movieCollection.getNextMovie(movieId);
if(nextMovie != null){
movieId = nextMovie.getId();
title = nextMovie.getTitle();
plot = nextMovie.getPlot();
movieArt = nextMovie.getMovieArt();
rating = nextMovie.getRating();
review1 = nextMovie.getReview1();
review2 = nextMovie.getReview2();
displayMovie(title , plot, movieArt, rating, review1, review2);
}
}
public void goPrevious(View view){
Movie prevMovie = movieCollection.getPrevMovie(movieId);
if (prevMovie != null){
movieId = prevMovie.getId();
title = prevMovie.getTitle();
plot = prevMovie.getPlot();
movieArt = prevMovie.getMovieArt();
rating = prevMovie.getRating();
review1 = prevMovie.getReview1();
review2 = prevMovie.getReview2();
displayMovie(title , plot, movieArt, rating, review1, review2);
}
}
error report can anyone tell me what is wrong with my code. thanks
07-06 14:19:36.635 3782-3782/com.example.growt.lucascomt E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.growt.lucascomt, PID: 3782
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:4452)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.growt.lucascomt.Movie.getId()' on a null object reference
at com.example.growt.lucascomt.MovieCollection.getPrevMovie(MovieCollection.java:38)
at com.example.growt.lucascomt.MovieInfo.goPrevious(MovieInfo.java:86)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I have used the BluetoothLeGatt example from Android and now I want to load a xml file depending on the UUID of the device I'm connecting with.
I've tried to compare the UUID's with the following code.
mBluetoothLeService.getSupportedGattServices().equals("0003CBBB-0000-1000-8000-00805F9B0131")
With the function:
public List<BluetoothGattService> getSupportedGattServices() {
if (mBluetoothGatt == null) return null;
return mBluetoothGatt.getServices();
}
What am I doing wrong?
Here is the error code:
FATAL EXCEPTION: main
Process: com.example.android.bluetoothlegatt, PID: 1314
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.bluetoothlegatt/com.example.android.bluetoothlegatt.DeviceControlActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.example.android.bluetoothlegatt.BluetoothLeService.getSupportedGattServices()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.example.android.bluetoothlegatt.BluetoothLeService.getSupportedGattServices()' on a null object reference
at com.example.android.bluetoothlegatt.DeviceControlActivity.onCreate(DeviceControlActivity.java:483)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358
As per I understand your question :
List<BluetoothGattService> services = mBluetoothLeService.getSupportedGattServices();
for (int i = 0; i < services.size(); i++) {
BluetoothGattService gattService = services.get(i);
if(gattService.getUuid().toString().equalsIgnoreCase("0003CBBB-0000-1000-8000-00805F9B0131"))
Log.e("SERVICES : ", "" + gattService.getUuid());
}
}
On trying the following code i get the error:
Cursor cursor1 = db.rawQuery("SELECT * FROM " + TABLE_TRAVEL +
" WHERE " + KEY_CITY + " = ? AND " + KEY_STATE + " = ?",null);
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.anvipuri.databaseplaces, PID: 11773
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.anvipuri.databaseplaces/com.anvipuri.databaseplaces.MainActivity}:
android.database.CursorIndexOutOfBoundsException: Index -1 requested,
with a size of 6
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: android.database.CursorIndexOutOfBoundsException: Index -1
requested, with a size of 6
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.anvipuri.databaseplaces.DatabaseHelper.findOnep(DatabaseHelper.java:132)
at
com.anvipuri.databaseplaces.MainActivity.onCreate(MainActivity.java:119)
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)
You should do
if(cursor.moveToFirst()) {
do {
Obj obj = createObjectFromCursor(cursor);
} while(cursor.moveToNext());
}
Or at least you shouldn't forget to call moveToPosition() or moveToFirst() so that you initialize the cursor's index from the default -1.
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);
}
}
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();
}