Return statement error

package processmsg;
import java.util.*;
public class PhoneMessage
extends java.lang.Object
implements java.lang.Comparable<processmsg.PhoneMessage> {
     private String Sender;
     private String Receiver;
     private String PhoneNumber;
     private String Date;
     private String Time;
     private String Status;
     private String Message;
     public PhoneMessage(String sender, String receiver, String phoneNumber, String date, String time, String status, String message) {
          setSender(Sender);
          setReceiver(Receiver);
          setPhoneNumber(PhoneNumber);
          setDate(Date);
          setTime(Time);
          setStatus(Status);
          setMessage(Message);
     public int compareTo(PhoneMessage pm) {
          Scanner par = new Scanner(getDate()).useDelimiter("/");
          int day = par.nextInt();
          int month = par.nextInt();
          int year = par.nextInt();
          Scanner t = new Scanner(getTime()).useDelimiter(":");
          int hour = t.nextInt();
          int minute = t.nextInt();
          int second = t.nextInt();
          Scanner u = new Scanner(pm.getDate()).useDelimiter("/");
          int otherday = u.nextInt();
          int othermonth = u.nextInt();
          int otheryear = u.nextInt();
          Scanner v = new Scanner(pm.getTime()).useDelimiter(":");
          int otherhour = v.nextInt();
          int otherminute = v.nextInt();
          int othersecond = v.nextInt();
          System.out.println(day);
          System.out.println(month);
          if(otheryear < year) {
               return -1;
          else if (otheryear > year) {
               return 1;
          else
               if(othermonth < month) {
                    return -1;
               else if(othermonth > month) {
                    return 1;
               else
                    if(otherday < day) {
                         return -1;
                    else if(otherday > day) {
                         return 1;
                    else
                         if(otherhour < hour) {
                              return -1;
                         else if(otherhour > hour) {
                              return 1;
                         else
                              if(otherminute < minute) {
                                   return -1;
                              else if(otherminute > minute) {
                                   return 1;
                              else
                                   if(othersecond < second) {
                                        return -1;
                                   else if(othersecond > second) {
                                        return 1;
                                   else
                                        return 0;
public void setSender(String sender) {
     Sender = sender;
public String getSender() {
     return Sender;
public String getReceiver() {
     return Receiver;
public String getPhoneNumber() {
     return PhoneNumber;
public String getDate() {
     return Date;
public String getTime() {
     return Time;
public String getStatus() {
     return Status;
public String getMessage() {
     return Message;
public void setReceiver(String receiver) {
     Receiver = receiver;
public void setPhoneNumber(String phoneNumber) {
     PhoneNumber = phoneNumber;
public void setDate(String date) {
     Date = date;
public void setTime(String time) {
     Time = time;
public void setStatus(String status) {
     Status = status;
public void setMessage(String message) {
     Message = message;
Exception in thread "main" java.lang.NullPointerException
     at java.io.StringReader.<init>(Unknown Source)
     at java.util.Scanner.<init>(Unknown Source)
     at processmsg.PhoneMessage.compareTo(PhoneMessage.java:33)
     at processmsg.MessageList.add(MessageList.java:23)
     at processmsg.ProcessMessages.main(ProcessMessages.java:68)
Those are the errors I am getting and I have no idea why. Any help is appreciated

package processmsg;
import java.io.*;
import java.util.*;
public class ProcessMessages {
     public static void main(String[] args)     {
          int choice;
          String sender;
          String receiver;
          String phonenumber;
          String date;
          String time;
          String status;
          String message;
          String blank;
          MessageList list = new MessageList();
          do {
          //Print out the menu with options
          System.out.println("1. Add a message file");
          System.out.println("2. Output the current list of phone messages ordered by time stamps");
          System.out.println("3. Output phone messages related to a specific name");
          System.out.println("4. Terminate");
          //Set up scanner to input choice
          Scanner stdin = new Scanner(System.in);
          //Get the choice           
          choice = stdin.nextInt();
               //Determine which choice was entered
               switch (choice) {
                         //handle individual cases
                         case 1:
                              Scanner filename = new Scanner(System.in);
                              System.out.println("Enter name of file:");
                              String s = filename.nextLine();
                              Scanner fileIn = null;
                              try {
                                   File file = new File(s);
                                   fileIn= new Scanner(file);
                              catch (FileNotFoundException e) {
                                   System.err.println(s + ": cannot be opened for reading");
                                   System.exit(0);
                              while(fileIn.hasNext()) {
                              // read in info from text file
                              sender = fileIn.nextLine();
                              receiver = fileIn.nextLine();
                              phonenumber = fileIn.nextLine();
                              date = fileIn.nextLine();
                              time = fileIn.nextLine();
                              status = fileIn.nextLine();
                              message = fileIn.nextLine();
                              PhoneMessage msg = new PhoneMessage(sender, receiver, phonenumber, date, time, status, message);
                              list.add(msg);
                              if(fileIn.hasNext())
                                   blank = fileIn.nextLine();
                              break;
                         case 2:
                         System.out.print("this works");     
                         break;
                         case 3:
                         System.out.print("this works");
                         break;
          } while (choice != 4);
          System.out.println("Good Bye");
}

Similar Messages

  • "missing return statement" error code

    well... i feel like such a n00b... I can't seem to figure out what the problem is with my code, if someone could help me, that would be great. I get an error saying 'missing return statement'. I know that I have some things in here that I don't need but I will need them as I go on making this program.
    with this code:
    import java.io.*;
    import java.math.*;
    public class Tester
         public static int time = 0;
         public static void main(String[] args) throws IOException
              System.out.println("Welcome to the 2008 Java Games!!!");
              time=1000;
              delay(100);
              //Method Name: delay
              //Method Arguments: used to wait for a given time
              //Goal of Method: Delay for a given time
         public static int delay(int time)
              try {
                   Thread.sleep(time);
              catch(InterruptedException ex) {}
              time++;
    }

    What does the error say? "Missing return statement"? Then I'm going to venture a guess and say that you're missing a return statement. If you don't know what a return statement is, then you have some learning to do:
    http://java.sun.com/docs/books/tutorial/java/javaOO/returnvalue.html
    Read that, then look at your delay() method and how you call it. And notice that you've made delay() of type "int".
    Edit: Or just have someone else give you the answer :P
    Edited by: newark on Feb 27, 2008 3:20 PM

  • Missing return statement error! HOW?

    Why would the following code complain that it's missing a return statement, yet there are more than 4 return statements. All the possibilities are captured on the if statements and there are no more possibilities.
    public static double power(double b, int e)
            if(e == 0 || b == 1)
                return 1;
            else if(e > 0)
                if (b > 0)
                    return b * power(b, e - 1);
                else if (b % 2 == -1)
                    return -(power(b, -e));
            else if(e < 0)
                if(b > 0)
                    return 1 / power(b, -e);
                else if (b % 2 == 1)
                    return -(1 / power(b, -e));
        }Edited by: deyiengz on Jul 30, 2009 8:34 PM

    ejp,
    Thanks for the rapid response
    I thought there could only be these possibilities:
    1. e = 0 and b = 1
    captured in the 1st if statement
    2. e > 0 and either (b > 0 or b < 0)
    captured in the second if
    3. e < 0 and either (b > 0 or b < 0)
    captured in the Third if
    and else nothing else+
    What's remaining? This was meant to be easy, what the hell am I not seeing?
    flounder Thanks too for your response.
    I tried to remove the if on the last else if (below) but still got the error
    else
                if(b > 0)
                    return 1 / power(b, -e);
                else if (b % 2 == 1)
                    return -(1 / power(b, -e));
            }Edited by: deyiengz on Jul 30, 2009 9:14 PM

  • Missing return statement error

    public class Member
             public int Member(String memberid, String memberpw)
         String cs = "jdbc:oracle:thin:@255.255.255.255:1000:a123stud";
             String user = "123456";
             String pass = "123456";
              String member = "member_id";
             try
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                   //Connection conn = DriverManager.getConnection("jdbc:odbc:myOracle");
                   Connection conn = DriverManager.getConnection(cs,user,pass);
                   Statement stmt = conn.createStatement();
                   String query = "SELECT * FROM members";
                   ResultSet rs = stmt.executeQuery(query);
                 // ResultSet rs = stmt.executeQuery("SELECT * FROM members WHERE member_id = 'M0001'");
                        int counter = 0;
                        while(rs.next())
                             member = rs.getString("member_id");
                             counter++;
                             if (counter == 0)
                             return 0;
                             else
                             return 1;
                        //System.out.println("\nOracle10g at 255.255.255.255 is working!");
              catch(SQLException e)
                   System.out.println("\n\nException Occured " +
                             "(Incorrect IP address, Server may be down, or SQL Exception)");
                   e.printStackTrace();
              catch(ClassNotFoundException e)
                   System.out.println("\n\nException Occured (CLASSNOTFOUND Exception)");
    }It says i am missing the return statement,but i do have set return something,whats the error? thx for helping

    For example, what happens if the SQL query doesn't
    return any rows, and rs.next() is never true?The while() loop will be skipped and the if statement
    will execute, which has two branches, one of which is
    guaranteed to return?Oops. My bad.
    I thought the ifs were inside the while.
    Okay, the problem here is with the exception handling. Catching and logging and doing nothing else is usually almost as bad as just smothering them. In this case it's especially true because the method then just continues after the catch blocks, in which case there's no return.
    You have to actually handle the exceptions if you're not going to propagate them. In this case, that would mean returning some reasonable default value. I'd say that's not a good idea here, and you're better off to just let the exceptions be thrown, or wrap and rethrow in your own exception.

  • Cannot resolve "missing return statement error"

    Hi,
    I have a small code where the following message is received when I am trying to compile it:
    61: missing return statement
    ^
    1 error
    I cannot figure out what is the source of the error. I appreciate any help in advance. Thanks
    THE FULL CODE:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BuildSquare extends JApplet
    implements ActionListener {
    JLabel number1Label, resultLabel;
    JTextField number1Field, resultField;
    public void init()
    Container container = getContentPane();
    container.setLayout( new FlowLayout() );
    number1Label = new JLabel("Enter an integer to represent the side of square" );
    container.add(number1Label);
    number1Field = new JTextField( 10 );
    container.add( number1Field );
    number1Field.addActionListener( this );
    resultLabel = new JLabel ("The final square is: ");
    container.add( resultLabel );
    resultField = new JTextField( 15);
    resultField.setEditable( false );
    container.add( resultField);
    public void actionPerformed( ActionEvent e )
         int a;
    String Result;
         a = Integer.parseInt(number1Field.getText());
         showStatus("Calculating...");
         Result = DisplaySquare( a );
         showStatus( "Done");
         resultField.setText( Result );
    public String DisplaySquare( int a )
    String output = "";
    for (int row = 1; row <= a; row ++) {
    for (int column = 1; column <= a; column++ ) {
    output += output + "* ";
    output += "\n";
    return output;
    }

      public String DisplaySquare( int a )
       String output = "";
        for (int row = 1; row <= a; row ++)
           for (int column = 1; column <= a; column++ )
               output += output + "* ";
            } // end of "for  clumn"  
            output += "\n";
            return output;
        }  //end of "for   row"
        //mising return...............
      }  //end of public String DisplaySquare
    } //end of public class BuildSquare

  • Return statement error and java.lang.noclassDefFoundError?

    public class Calculation
         public static void main (String[] args)
              int a[]=new int [12];
              int iNum=0;
              MainPrompt();
         static public int MyInput()
         return MyInput.readInt();
         public static boolean MainPrompt()
              System.out.println("\n This program will show you the times table [1-12] of any number between 1 & 100 inclusive.");
              int a[]=new int [12];
              int iNum = 0;
              do
                   do
                        System.out.print("\n Enter your number [1-100] or 999 to exit: ");
                        iNum = MyInput();
                        while ((iNum>=1)&&(iNum<=100));
                             if (iNum==999)
                                  System.out.println("\n Goodbye \n");
                        while (!(((iNum>=1)&&(iNum<=100))||(iNum==999)));
                             if ((iNum>=1)&&(iNum<=100))
                                  Calculation(a,iNum);
                                  TimesTable(a,iNum);
         public static void Calculation(int a[], int iNum)
              for(int j=0;j<a.length;j++)
              a[j]=iNum*(j+1);
         public static void TimesTable(int a[], int iNum)
              for(int i=0;i<a.length;i++)
              System.out.println((i+1)+"     *"+iNum+"     ="+a);
    In build output it says missing return statement line 42 "}"
    and also when I try to execute the program it gives me the Exception in thread "main" java.lang.NoClassDefFoundError: calculation
    In the folder I have placed the myinput.java and myinput.class file where my calculation.java is, but still no go.
    can anyone here help me out here?
    thanks in advance

    public class Calculation
         public static void main (String[] args)
              int a[]=new int [12];
              int iNum=0;
              MainPrompt();
         static public int MyInput()
         return MyInput.readInt();
         public static void MainPrompt()
              System.out.println("\n This program will show you the times table [1-12] of any number between 1 & 100 inclusive.");
              int a[]=new int [12];
              int iNum = 0;
              do
                   do
                        System.out.print("\n Enter your number [1-100] or 999 to exit: ");
                        iNum = MyInput();
                        while ((iNum>=1)&&(iNum<=100));
                             if (iNum==999)
                                  System.out.println("\n Goodbye \n");
                        while (!(((iNum>=1)&&(iNum<=100))||(iNum==999)));
                             if ((iNum>=1)&&(iNum<=100))
                                  Calculation(a,iNum);
                                  TimesTable(a,iNum);
         public static void Calculation(int a[], int iNum) //This part doesn't execute
              for(int j=0;j<a.length;j++)
              a[j]=iNum*(j+1);
         public static void TimesTable(int a[], int iNum)
              for(int i=0;i<a.length;i++)
              System.out.println((i+1)+"     *"+iNum+"     ="+a);

  • Missing return statement

    Can anyone tell me why I'm getting a missing return statement error in this code?
    import java.awt.*;
    * Write a description of class Flower here.
    * @author (your name)
    * @version (a version number or a date)
    public class Flower
        protected FilledOval dot;
        protected FilledRect stem;
        protected FilledOval petal1;
        protected FilledOval petal2;
        protected static final int boundary = 100;
        protected RandomIntGenerator colorGen =
                new RandomIntGenerator(0,255);
        protected Color petalColor;
        protected Boolean flowerContains=false;
        private DrawingCanvas canvas;
        public void changeColor(Location point){
        dot = new FilledOval(point,15,15, canvas);
        dot.setColor(Color.YELLOW);
        petalColor = new Color(colorGen.nextValue(),
                                    colorGen.nextValue(),
                                    colorGen.nextValue());
        petal1.setColor(petalColor);
        petal2.setColor(petalColor);
        public void grow(Location point){
        stem = new FilledRect (dot.getX()+3, dot.getY()+10, 10, 10, canvas);
        stem.setColor(Color.GREEN);
        if (dot.getY()>boundary){
            dot.move(0,-4);
        else{
         petal1 = new FilledOval(dot.getX()-12, dot.getY()-25, 40,70,canvas);
         petal2 = new FilledOval(dot.getX()-25, dot.getY()-10, 70,40,canvas);
         dot.sendToFront();
         stem.sendToBack();
         petal1.setColor(petalColor);
         petal2.setColor(petalColor);
        public Boolean flowerContains(Location point){
            if (petal1.contains(point)){
                return true;
            else if (petal2.contains(point)){
                return true;
            else if (dot.contains(point)){
                return true;
    }

    public Boolean flowerContains(Location point){
            if (petal1.contains(point)){
                return true;
            else if (petal2.contains(point)){
                return true;
            else if (dot.contains(point)){
                return true;
        }That method returns a Boolean value. But if none of the condition gets satisfied then what is it going to return?

  • Missing Return Statement, where do I put it?

    Hi am using some code from the Sun website, it is called the KnockKnockProtocol, and I have edited it a bit and I get a "missing return statement" error. When I put one in the server does not run at all?
    import java.net.*;
    import java.io.*;
    public class KnockKnockProtocol {
        private static final int WAITING = 0;
        private static final int SENTKNOCKKNOCK = 1;
        private static final int SENTFILE = 2;
        private static final int ANOTHER = 3;
        private static final int NUMJOKES = 5;
        private int state = WAITING;
        private int resource = 0;
        private String[] file = {"1. iTune 2. ZoneAlarm 3. WinRar 4. Audacity (Select a resource for downloading)"};
        private String[] download1 = {"You are downloading iTune.zip."};
        private String[] download2 = {"You are downloading ZoneAlarm.zip."};
        private String[] download3 = {"You are downloading WinRar.zip."};
        private String[] download4 = {"You are downloading Audacity.zip."};
        public String processInput(String theInput) {
            String theOutput = null;
            if (state == WAITING) {
                theOutput = "Here are the terms of reference. Do you accept?";
                state = SENTKNOCKKNOCK;
            } else if (state == SENTKNOCKKNOCK) {
                if (theInput.equalsIgnoreCase("Yes")) {
                    theOutput = file[resource];
                    state = SENTFILE;
                } else {
                    theOutput = "Please accept the terms of reference to continue. Do you accept?";
            } else if (state == SENTFILE) {
                if (theInput.equalsIgnoreCase("1")) {
                    theOutput = download1[resource] + " Do you want to download another?";
                    state = ANOTHER;
                } else if (state == SENTFILE) {
                    if (theInput.equalsIgnoreCase("2")) {
                        theOutput = download2[resource] + " Do you want to download another?";
                        state = ANOTHER;
                    } else if (state == SENTFILE) {
                        if (theInput.equalsIgnoreCase("3")) {
                            theOutput = download3[resource] + " Do you want to download another?";
                            state = ANOTHER;
                        } else if (state == SENTFILE) {
                            if (theInput.equalsIgnoreCase("4")) {
                                theOutput = download4[resource] + " Do you want to download another?";
                                state = ANOTHER;
                        } else {
                            theOutput = "You're supposed to select \"" +
                                    file[resource] +
                                    "\"" +
                                    " Please try again!";
                            state = SENTKNOCKKNOCK;
                    } else if (state == ANOTHER) {
                        if (theInput.equalsIgnoreCase("Yes")) {
                            theOutput = file[resource];
                        if (resource == (NUMJOKES - 1)) {
                            resource = 0;
                        } else {
                            resource++;
                        state = SENTKNOCKKNOCK;
                    } else {
                        theOutput = "Bye.";
                        state = WAITING;
                return theOutput;
    }Any ideas how to solve would be nice. Thanks.

    private String[] file = {"1. iTune 2. ZoneAlarm 3. WinRar 4. Audacity (Select a resource for downloading)"};
        private String[] download1 = {"You are downloading iTune.zip."};
        private String[] download2 = {"You are downloading ZoneAlarm.zip."};
        private String[] download3 = {"You are downloading WinRar.zip."};
        private String[] download4 = {"You are downloading Audacity.zip."};<nitpick>
    Do you understand what arrays are for?
    </nitpick>

  • Missing return statement question

    I got a missing return statement error when i compile in this code but however i dont get any missing return statement errors in the second code that i pasted here.. What is the difference i didn't get it ? Thank you.
    public class primechecker {
        static double remainder = 0;
        public static boolean primecheck(int number){
             for(int i=2; i<number; i++){
                  remainder = number % i;
                  if (remainder == 0){
                       return false;
             if (remainder !=0){
                  return true;
        public static void main(String[] args) {
             System.out.print(primecheck(10));
    }That is the second code which gives no error.
    public class positiveornegative {
       public static boolean numbercheck (int number){
           boolean booleann = true;
           if(number > 0){
             return true;
           else if (number < 0){
             return false;
           else {
                return false;
        public static void main(String[] args) {
             System.out.println(numbercheck(-2));
    }

    In your first snippet, the compiler has no guarantee that the for loop will be executed at all. That leaves only one return inside an if condition which again it has no guarantee that it will ever be reached(the if test may fail). This leads the compiler to the conclusion that your method may never return anything at all. Yet it's definition says that it must return a value.

  • Missing Return Statement Hell!!

    public class EventSite
    private int siteNumber;
    public EventSite()
    siteNumber = 999;
    public int getSiteNumber()
    return siteNumber;
    public Void setSiteNumber(int n)
    siteNumber = n;
    I'm taking a java class and this won't compile...Whats wrong??
    Why the Missing return statement error?

    flounder wrote:
    NewProgramGirl wrote:
    no need it is now compiled, think it was the big "V'...thank you....soooo much!!Well that contradicts what you said in reply 4.I'm guessing we forgot the all important "Save" step of the development lifecycle.
    Speaking of development lifecycle my version control system at my new job consists of zipping my project to the main fileserver each night before I leave. Apparently the SVN will be set up any day now...

  • Missing return statement?  News to me!

    Before I ask anything let be begin by saying thanks to all you people that help others on these boards, I've never posted a question before but I have often found the answers to my problems somewhere here. I'm currently working on one of my last java assignments ever and I am completely stumped as to whats going on. All I want out of this code is for it to read a txt file for a bunch of phone book entries, load them into some arrays, then sort them by first name, last name, then phone# then return the array so I can use it later on. I've got the entries loaded, I've got em sorted, but I can;t return it. When I try I get a missing return statement error. I dont know why its not returning the array, so I thought I'd ask the pros. I can get it to work fine if I dont return anything but what good is that eh?
    Please forgive my terrible coding, I am in no way a real programmer, I just want to pass my classs and never think about it again 8) any help would be appreciated. Tis is built to work with an "Entry" file, if you guys need it to proceed lemme know and I will post it. Thanks.
    the code....
        public class CSCD210PhoneBook {
           public static void main(String[] args)throws IOException
          {//Opening main          
             Scanner kb = new Scanner(System.in);
               int entryCount=0;
                   Scanner fileScanner=null;
                   Entry[] array=null;
         array=populateEntry(entryCount, fileScanner, kb);
          }//end main array=
                 public static  Entry[] populateEntry(int entryCount, Scanner fileScanner,Scanner kb)throws IOException
                    int lineCount=0;
                   String fileName;
                   File fileHandle;     
                   System.out.println("Which file would you like your entries pulled from?");
                   fileName= kb.nextLine();
                               fileHandle = new File(fileName);
                   fileScanner = new Scanner(fileHandle);
                   while(fileScanner.hasNext())
                         fileScanner.nextLine();
                         lineCount++;
                   entryCount= lineCount/8;
                   Entry[] array=new Entry[entryCount];
                   fileScanner.close();
                   fileHandle = new File(fileName);
                   fileScanner = new Scanner(fileHandle);
                        for(int i =0; i<array.length;i++)
                             array=new Entry(fileScanner);
                   fileScanner.close();
                   int curPos, indexSmallest, start;
    Entry temp;
    for (start = 0; start < array.length - 1; start++)
    indexSmallest = start;
    for (curPos = start + 1; curPos < array.length; curPos++)
    if (array[indexSmallest].compareTo(array[curPos]) > 0)
    indexSmallest = curPos;
    } // end for
    temp = array[start];
    array[start] = array[indexSmallest];
    array[indexSmallest] = temp;
                   return array;
    Any help would be most appreciated.

    The code you posted has mismatched braces: it needs another } at the end.
    Linked with this is how - or rather when - you return array from the populateEntry()
    method. You have a couple of nested for-loops and you return array inside (at the
    end of) the outer loop.
    The compiler is really fussy about making sure that an Entry[] is returned from this
    method. If you outer for-loop never gets executed for some reason, then the return
    statement will never be reached. The compiler won't accept this.
    Either
    (1) move the return statement outside both loops so it is always executed. This
    appears to be the most logical thing - but I haven't read your code that closely. It's
    just that having return at the end of a for-loop (with no "continue" in sight), doesn't
    make a lot of sense.
    or
    (2) add another return after both loops have finished.

  • Doubt on Return statement

    Hi,
    IN the code below,
    I need to return a Double value. That Double value is declared and calculated with in IF condition.
    But, If i keep return statement with in if condition, i get "MIssing return statement error". IF i keep Return statement outside if(), I get "symbol c not found error".
    How do i fix this?
    private Double calculate(Double a, BigDecimal b) {  
            if(!((null == a)&&(null == b))){  
            //do some calculation  
            Double c = Double.valueOf(b.doubleValue());  
            return c; ---> Getting error right here.  (Can't find symbol c error.)  
       }  please help

    gimbal2 wrote:
    900637 wrote:
    Is there any solution for this?Perhaps you need two return statements.This depends whether <tt>a</tt> and <tt>b</tt> can be null because of business rules or programming errors.
    If the latter I'd not care for the NPE or just throw my own NPE from the else path telling which parameter has been null .
    If business rules forcs you to handle null values these rules must provide a solution for that case to be implemented in the else path.
    bye
    TPD

  • UDF  missing return statement }

    Hi,
    I'm wondering how the missing return statement  error can be avoided in this code, I've tried all sorts of syntaxes but it just won't work:
    public String DetermineCostCenter(String KTOS,String KTOH,String FNR,String KST,Container container){
    int KTOHNR = 0;
    int KTOSNR  = 0;
    KTOHNR = new Integer(KTOH).intValue();
    KTOSNR = new Integer(KTOS).intValue();
    if (KTOSNR > 6999999 || KTOHNR > 6999999) {
                         if  (FNR.equals( "1"))
                                  return "1008590";
                        else if (FNR.equals("2"))
                                 return "5008090";
                        else
                                return " ";
    if (KTOSNR > 6999999 || KTOHNR > 6999999)
         return KST;
    if (KTOSNR < 3000000 && KTOHNR < 3000000)
         return " ";
    Thanks
    Tom

    Try this...
    int KTOHNR = 0;
    int KTOSNR = 0;
    String tmpktosnr = "";
    KTOHNR = new Integer(KTOH).intValue();
    KTOSNR = new Integer(KTOS).intValue();
    if (KTOSNR > 6999999 || KTOHNR > 6999999) {
    if (FNR.equals( "1"))
    tmpktosnr =  "1008590";
    else if (FNR.equals("2"))
    tmpktosnr =  "5008090";
    if (KTOSNR > 6999999 || KTOHNR > 6999999)
    tmpktosnr = KST;
    if (KTOSNR < 3000000 && KTOHNR < 3000000)
    tmpktosnr =  " ";
    return tmpktosnr;
    Hope this will help.
    Nilesh

  • Unreachable statement error occured while using return statement.

    Consider this code
    class q25{
         public static void main(String args[]){
              amethod(args);
         public static void amethod(String args[]){
              String str;
              try{
                   str = "Hello "+args[0];
                   System.out.println(str);
                   System.out.println("Returning to caller");
                   System.exit(0);
              catch(Exception e){
                   System.out.println("Exception ocured");
                   System.exit(0);          
              finally{
                   System.out.println("In finally");
              System.out.println("At the end of method");     
    }Above code compiles and runs successfully without any errors.
    Now consider below code which is same as above one except "System.exit(0)" statements were replace by "return" statements. Below code when compiled gives error as
    "q25.java:22: unreachable statement
    System.out.println("At the end of method");
    ^
    1 error"
    One thing i didn't understood in this context that, the above code when compiled should get same error as stated above. But not. It is obvious that presence of System.exit(0) must generate unreachable statement same as when it is replaced by "return" statement. What is the difference in getting the error for above but not for below code. Pls anyone help.
    class q25{
         public static void main(String args[]){
              amethod(args);
         public static void amethod(String args[]){
              String str;
              try{
                   str = "Hello "+args[0];
                   System.out.println(str);
                   System.out.println("Returning to caller");
                   return;
              catch(Exception e){
                   System.out.println("Exception ocured");
                   return;     
              finally{
                   System.out.println("In finally");
              System.out.println("At the end of method");     
    }

    warnerja wrote:
    masijade. wrote:
    Since you have a "return" in both the try and the catch portions of the try/catch block *(the second of which you should never do)* , anything thing that comes after the try/catch/finally blocks will be unreachable.That is not true. There are plenty of reasons to return from a catch block. If you handle the exception instead of rethrowing it or another exception, then you'll need a return somehow, either there or after the catch block. What you should never do is "return" in a finally block, because that will mask any exception in flight about to be thrown to the caller.Perhaps masijade's use of never is too strong, but I too prefer/tend to avoid using return anywhere in try/catch/finally to avoid potential gotchas. Consider:
    public class TryCatchFinally
      public Data process(String s)
        Data returnData = new Data();
        try
          returnData.value = Integer.parseInt(s);
          returnData.message = "Success";
          return returnData;
        catch (Exception ex)
          returnData.value = -1;
          returnData.message = "Fail";
          return returnData;
        finally
          returnData.value = 42;
          returnData.message = "?";
      public static void main(String[] args)
        TryCatchFinally demo = new TryCatchFinally();
        Data d = demo.process("2");
        System.out.println(d.message + ": " + d.value);
        d = demo.process("2.1");
        System.out.println(d.message + ": " + d.value);
      class Data
        int value = 0;
        String message = "";
    }

  • This should work? error missing return statement.

    Why do I get this error?
    missing return statement
    To me the code seems good?
    public SortAbstractProduct createSorter(String whichAlgorithm) {
    if (whichAlgorithm.equalsIgnoreCase("BubbleSortProduct") )
    System.out.println("from scf buublesort check");
    return new BubbleSortProduct();
    if (whichAlgorithm.equalsIgnoreCase("OptimsedBubbleSortProduct") )
    System.out.println("from scf optimesed buublesort check");
    return new OptimisedBubbleSortProduct();
    if (whichAlgorithm.equalsIgnoreCase("QuickSortProduct") )
    System.out.println("from scf Quicksort check");
    return new QuickSortProduct();
    }

    You need to retrun an object of SortAbstractProduct, yet your are trying to return 3 different types(BubbleSortProduct, OptimisedBubbleSortProduct, QuickSortProduct). These need to be subclasses of SortAbstractProduct, then you will be able to cast them it.

Maybe you are looking for

  • Account  requires an assignment to a CO object  T Code ABAVN

    Dear All While processing the Asset Retirement through Srapping im getting the following message Account 68120 requires an assignment to a CO object Now i have maintained the GL account in T Code OKB9 and against Valuation Area i have maintained the

  • How do I render a PDF stored in interMedia object?

    I have a pdf stored in an interMedia object and would like to simply render it to the browser. If I drop an <adf:render> tag for it, it creates a hyperlink for it. I'd like it to simply display it. That is, say I call my page like this: ShowMeThePDF?

  • OSB 10.3.1 WS-Policy encrypting an optional WSDL element

    Hi everyone I want to encrypt a certain element of a request message for a proxy service. This is the policy portion embedded in the WSDL: <wssp:Confidentiality> <wssp:KeyWrappingAlgorithm URI="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/> <!-- Require

  • Error message 1056 and image on top of image problem

    I am trying to place a button on the screen and make it spin when mouse_over (which will be one of mutiple buttons with different instance names. ) The code I wrote is putting  2 colorwheels on the screen, one on top of the other, I can see the botto

  • Getting a black screen when publishing in html or preview in browser

    Hi, Can anyone help. I am trying to publish a file that I converted from a captivate 4 file. It si a basic file with click boxes, captions and failure boxes. i also have 2 introductory slides with a slide BG, and animated text. (I need to go back and