Results 1 to 2 of 2
  1. #1
    Asglv is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Question Missing return statement error

    public String itemType(int item) {
    for (int i = 0; i < Item.capes.length; i++) {
    if (item == Item.capes[i])
    return "cape";
    }
    for (int i = 0; i < Item.hats.length; i++) {
    if (item == Item.hats[i])
    return "hat";
    }
    for (int i = 0; i < Item.boots.length; i++) {
    if (item == Item.boots[i])
    return "boots";
    }
    for (int i = 0; i < Item.gloves.length; i++) {
    if (item == Item.gloves[i])
    return "gloves";
    }
    for (int i = 0; i < Item.shields.length; i++) {
    if (item == Item.shields[i])
    return "shield";
    }
    for (int i = 0; i < Item.amulets.length; i++) {
    if (item == Item.amulets[i])
    return "amulet";
    }
    for (int i = 0; i < Item.arrows.length; i++) {
    if (item == Item.arrows[i])
    return "arrows";
    }
    for (int i = 0; i < Item.rings.length; i++) {
    if (item == Item.rings[i])
    return "ring";
    }
    for (int i = 0; i < Item.body.length; i++) {
    if (item == Item.body[i])
    return "body";
    }
    for (int i = 0; i < Item.legs.length; i++) {
    if (item == Item.legs[i])
    return "legs";
    }
    } ---- SAYS THIS IS MISSING THE RETURN STATEMENT.
    Last edited by Asglv; 01-13-2013 at 07:47 AM. Reason: error

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Missing return statement error

    It could be that no of your if statement matches/is true, then you don`t return anything.
    You have to add a return statement at the end of the method e.g. return null, or return a empty string, or you have to throw an exception. In both cases it would be good if the method is documented.

    btw: Your method is very strange. What happens if a new item is added? Right you have to change this method too, that`s not good. And inefficient is it too because you have to iterate n times. Is there no other way?

Similar Threads

  1. missing return statement error
    By Joshkesner in forum New To Java
    Replies: 2
    Last Post: 10-21-2012, 06:38 AM
  2. Missing return statement error.
    By Fortu in forum New To Java
    Replies: 2
    Last Post: 12-11-2010, 09:15 PM
  3. Missing Return Statement Error
    By darkblue24 in forum New To Java
    Replies: 13
    Last Post: 02-16-2010, 08:22 PM
  4. Replies: 5
    Last Post: 01-16-2010, 11:14 PM
  5. Missing Return Statement error
    By anilanar in forum New To Java
    Replies: 2
    Last Post: 08-20-2009, 01:02 AM

Tags for this Thread

Posting Permissions

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