Results 1 to 9 of 9
- 09-06-2011, 04:32 AM #1
Senior Member
- Join Date
- Jun 2011
- Posts
- 100
- Rep Power
- 0
null in 2 dimensional array problem
I have a problem on checking process to determine validity.
Code is something like :
qfield is tablemodel extended from abstracttablemodel.Java Code:private boolean isInOtherAField() { try { qfield.setQuery("SELECT afield, acode FROM test WHERE afield = '" + txAField.getText().toString().trim() + "';"); } catch (SQLException e) { e.printStackTrace(); }; if (!(qfield.getValueAt(0, 0).toString().trim()).equals(txAField.getText().toString().trim())){ return true; } else { return false; } }
Then in my main code I call isInOtherAField() and determine what to do on true and false return value.
When the query returns a row whether it's true or false, it works fine.
However then there's problem when the query returns empty result (in case of a new field code), which gives me :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
is there any way to handle this null 2-dimensional array ?
Thanks in advance,First is to make something usable, next is to aim for perfection which means a never ending improvements.
- 09-06-2011, 04:40 AM #2
Re: null in 2 dimensional array problem
Not sure what you are asking but generally you would check the length of an array before trying to access an element in the array.
- 09-06-2011, 05:00 AM #3
Senior Member
- Join Date
- Jun 2011
- Posts
- 100
- Rep Power
- 0
Re: null in 2 dimensional array problem
I skipped checking array length, now doing the length checking first and seems fine
If there's no more post then it's solved
Thanks,Last edited by Levian; 09-06-2011 at 05:03 AM.
First is to make something usable, next is to aim for perfection which means a never ending improvements.
- 09-06-2011, 06:55 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: null in 2 dimensional array problem
-
Re: null in 2 dimensional array problem
- 09-06-2011, 07:06 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: null in 2 dimensional array problem
- 09-06-2011, 07:07 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: null in 2 dimensional array problem
- 09-07-2011, 04:09 AM #8
Senior Member
- Join Date
- Jun 2011
- Posts
- 100
- Rep Power
- 0
Re: null in 2 dimensional array problem
Just have this checked and yes, it was answered and problem solved, but how to do that SOLVED mark that you said ?
So far I have most if not all are solved thanks to the ppl here.
Just let me know how-to and I'll mark it solved.
Thanks,Last edited by Levian; 09-07-2011 at 04:14 AM.
First is to make something usable, next is to aim for perfection which means a never ending improvements.
- 09-07-2011, 07:25 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: null in 2 dimensional array problem
Similar Threads
-
Help with Two Dimensional Array
By johnjacob in forum New To JavaReplies: 2Last Post: 06-03-2011, 08:22 PM -
Problem reading a text file into a two-dimensional character array
By wvu5004 in forum New To JavaReplies: 5Last Post: 03-12-2011, 01:04 AM -
Is it better to set array elements to null before setting the arrayreference to null?
By kreyszig in forum Advanced JavaReplies: 6Last Post: 10-18-2010, 10:40 AM -
about two dimensional array
By matin1234 in forum New To JavaReplies: 2Last Post: 06-01-2010, 11:09 AM -
Problem - input in two-dimensional array
By PVL268 in forum New To JavaReplies: 5Last Post: 03-09-2009, 04:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks