Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: A problem with return.

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default A problem with return.

    String rows[] = new String[] {KEY_GAL_ID};   
    Cursor c = ourDatabase.query(GALLERY_TABLE, rows,KEY_ROWID + "=" + rowId,null, null, null, null);
    String result = "";
     
    if(c.moveToFirst())
    {
    	result = c.getString(0);
    	return result;
    }
    else{
    	return "null";
    }
    Why always null is returned even when c.moveToFirst() is true and the program start to execute this row:result = c.getString(0);


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: A problem with return.

    Why always null is returned
    Is the value: null returned
    or is the String: "null" returned?

    There is a difference.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: A problem with return.

    The string "null" is returned.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: A problem with return.

    Then either:
    the method: c.moveToFirst() is returning false
    or c.getString(0) is returning: "null"
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Problem with return value.
    By E.K.Virtanen in forum Object Oriented Programming
    Replies: 3
    Last Post: March 27th, 2013, 12:45 PM
  2. [SOLVED] Problem with return and 2D array
    By J-moges in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 21st, 2013, 11:53 PM
  3. TemperatureConverter Return Problem
    By ShadowKing98 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 17th, 2011, 11:17 AM
  4. Problem with Return Function
    By Tracy22 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2010, 03:32 PM
  5. Error of missing return statement while implementing Array
    By MS_Dark in forum Collections and Generics
    Replies: 1
    Last Post: December 10th, 2008, 03:18 PM