Results 1 to 9 of 9
  1. #1
    Levian is offline Senior Member
    Join Date
    Jun 2011
    Posts
    109
    Rep Power
    0

    Default null in 2 dimensional array problem

    I have a problem on checking process to determine validity.

    Code is something like :
    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;
    		}
    	}
    qfield is tablemodel extended from abstracttablemodel.
    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.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default 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.

  3. #3
    Levian is offline Senior Member
    Join Date
    Jun 2011
    Posts
    109
    Rep Power
    0

    Default 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.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: null in 2 dimensional array problem

    Quote Originally Posted by Levian View Post
    If there's no more post then it's solved

    If you are satisfied with others' comments you can mark the thread solved.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: null in 2 dimensional array problem

    Quote Originally Posted by Eranga View Post

    If you are satisfied with others' comments you can mark the thread solved.
    How does one do this with the new forum software?

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: null in 2 dimensional array problem

    Quote Originally Posted by Fubarable View Post
    How does one do this with the new forum software?
    Sorry about that, with our new s/w we cannot do that as far as I know. Just by editing the thread we can do that. Sorry, since I get use of to do that I think others will do the same.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: null in 2 dimensional array problem

    Quote Originally Posted by Fubarable View Post
    How does one do this with the new forum software?
    Sorry about that, with our new s/w we cannot do that as far as I know. Just by editing the thread we can do that. Sorry, since I get use of to do that I think others will do the same.

  8. #8
    Levian is offline Senior Member
    Join Date
    Jun 2011
    Posts
    109
    Rep Power
    0

    Default 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.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default Re: null in 2 dimensional array problem

    Quote Originally Posted by Levian View Post
    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,
    Sure I'll let you know.

Similar Threads

  1. Help with Two Dimensional Array
    By johnjacob in forum New To Java
    Replies: 2
    Last Post: 06-03-2011, 08:22 PM
  2. Replies: 5
    Last Post: 03-12-2011, 01:04 AM
  3. Replies: 6
    Last Post: 10-18-2010, 10:40 AM
  4. about two dimensional array
    By matin1234 in forum New To Java
    Replies: 2
    Last Post: 06-01-2010, 11:09 AM
  5. Problem - input in two-dimensional array
    By PVL268 in forum New To Java
    Replies: 5
    Last Post: 03-09-2009, 04:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •