JFrames + Returning a Variable... Beginner's Logical Error

Hi,
I'm new to Java and programming in general. I'm trying to do something that seems pretty simple, but I'm making a logical error that is preventing my little program from working.
All I'm trying to do is this... I've created a little JFrame that asks a user for a university's name, address, and the number of students in the university. All of this is within a class called InputWindowSmall. I just want to be able to return those Strings, univName, univAdress, univStudents, to my main program so I can put them into a different class.
I've tried get methods, but that's silly, it doesn't work, it returns null because the program doesn't wait for the user's input.
Does anyone have any suggestions?
Also... I'm a terribly poor Object-Oriented-Thinker... If I'm doing anything that doesn't make sense in an Object-Oriented-Mindset, please point it out! I'd like to try and get better! Thanks!
CODE
InputWindowSmall
package FinalProject;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.GridLayout;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
/** Class Definition: Input Window - small input window that asks for University name and address*/
public class InputWindowSmall extends JFrame
     private JLabel nameLabel;
     private JLabel addressLabel;
     private JLabel numberStudentsLabel;
     private JLabel whiteSpace;
     private JTextField nameField;
     private JTextField addressField;
     private JTextField numberStudentsField;
     private JButton okButton;
     private String univName;
     private String univAddress;
     private String univStudents;
     /** Constructor with extra parameters     */
     public InputWindowSmall(University univ)
          //Names title bar of window
          super("Welcome!");
          //Sets layout of window
          setLayout(new GridLayout(4,2));
          //Sets text for nameLabel and adds to window
          JLabel nameLabel = new JLabel("    University Name: ");
          add(nameLabel);
          //Sets and adds nameField to window
          nameField = new JTextField(10);
          add(nameField);
          //Sets text for addressLabel and adds to window
          JLabel addressLabel = new JLabel("    University Address: ");
          add(addressLabel);
          //Sets and adds addressField to window
          addressField = new JTextField(10);
          add(addressField);
          //Sets text for numberStudentsLabel and adds to window
          JLabel numberStudentsLabel = new JLabel("    Number of Students: ");
          add(numberStudentsLabel);
          //Sets and adds numberStudentsField to window
          numberStudentsField = new JTextField(10);
          add(numberStudentsField);
          //Sets and adds white space
          JLabel whiteSpace = new JLabel("         ");
          add(whiteSpace);
          //Sets and adds button
          okButton = new JButton("OK");
          add(okButton);
          //create new ButtonHandler for button event handling
          ButtonHandlerSmall handler = new ButtonHandlerSmall();
          okButton.addActionListener(handler);
     }//end InputWindowSmall
     private class ButtonHandlerSmall implements ActionListener
          public void actionPerformed(ActionEvent event)
               String univName = nameField.getText();
               String univAddress = addressField.getText();
               String univStudents = numberStudentsField.getText();
          }//end actionPerformed
     }//end ButtonHandlerSmall
     public String getUniversityName()
          return univName;
     }//end getUniversityName
     public String getUniversityAddress()
          return univAddress;
     public String getUniversityNumberStudents()
          return univStudents;
}//ProjectTest (contains main)
/** Class Definition: ProjectTest - contains main*/
package FinalProject;
import javax.swing.JFrame;
public class ProjectTest {
     public static void main(String args[])
          //Creates a new university
          University univ = new University();
          //Instantiates and sets up the initial small window which asks for university name, address, and # students
          InputWindowSmall inputWindowSmall = new InputWindowSmall(univ);
          inputWindowSmall.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          inputWindowSmall.setSize(350, 120);
          inputWindowSmall.setVisible(true);
          inputWindowSmall.setLocationRelativeTo(null);
          String univN = inputWindowSmall.getUniversityName();
          String univA = inputWindowSmall.getUniversityAddress();
          String univS = inputWindowSmall.getUniversityNumberStudents();
          System.out.println(univN);
          System.out.println(univA);
          System.out.println(univS);
     }//end main
}Edited by: heathercmiller on Apr 28, 2008 5:57 AM
Edited by: heathercmiller on Apr 28, 2008 5:58 AM

Oh! ...Here is a somewhat important detail I forgot to mention...
There's another class called University (I've included it below). The main part of the program instantiates an object of type University, and that object is passed to the InputWindowSmall class. In the end, I want those variables I mentioned above to be placed within the University object I created. ...And I've already passed a University object to InputWindowSmall... I'm just not entirely sure how to assign values to the variables within the University object while in a different class. ...Does that make any sense?
University
package FinalProject;
import java.util.Arrays;
/** Class Definition: University*/
public class University extends ProjectTest implements TuitionGenerate 
     private String universityName;     /** refers to the name of the University     */
     private String address;               /** refers to the address of the University     */
     private Student studentList[];     /** an array of Student objects                    */
     /** Default Constructor */
     University()
          setuniversityName("University_of_Miami");
          setaddress("555_Coral_Gables_St.");               
     /** Constructor with parameters */
     University(String name,String add)
          setuniversityName(name);
          setaddress(add);
     /** Constructor with extra parameters */
     University(String name,String add, Student array[])
          setuniversityName(name);
          setaddress(add);
          setstudentList(array);
     /** method: gets universityName*/
     public String getuniversityName()
          return universityName;
     /** method: gets address*/
     public String getaddress()
          return address;
     /** method: gets studentList*/
     public Student[] getstudentList()
          return studentList;
     /** method: sets universityName*/
     public void setuniversityName(String name)
          universityName=name;
     /** method: sets address*/
     public void setaddress(String add)
          address=add;
     /** method: sets studentList*/
     public void setstudentList(Student array[])
          studentList=new Student[array.length];
          studentList=array;
     /** method: returns a string representation of universityName and address*/
     public String toString()
          String output="University Name: " + universityName + "\nAddress: " + address + "\n\n";
          return output;
     /** method: sorts the array of students alphbetically by last name*/
     public void studentSort()
          String temp[]=new String[studentList.length];
          for(int i=0;i<studentList.length;i++)
               temp=studentList[i].getlastName();
          Arrays.sort(temp);
          Student temp2[]=new Student[studentList.length];
          for(int i=0;i<temp.length;i++)
               for(int j=0;j<studentList.length;j++)
                    if(temp[i].equals(studentList[j].getlastName()))
                         temp2[i]=studentList[j];
                         break;
          studentList=temp2;               
     /** method: prints the list of students*/
     public void printStudentList()
          System.out.println("Students:\n");
          for(int i=0;i<studentList.length;i++)
               System.out.println(studentList[i].toString());
     /** method: prints tuition from interface GenerateTuition*/
     public void printTuition()
          for(int i=0;i<studentList.length;i++)
               System.out.println(studentList[i].toString());
               System.out.println(" Tuition: $" + studentList[i].calTuition() + "0");
     /** method: gets tuition from calTuition method*/
     public double getTuition(Student x)
               return x.calTuition();
Edited by: heathercmiller on Apr 28, 2008 6:07 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Newbie - JSP & bean shopping cart logic error?

    Hello,
    I am attempting to bulid a shopping cart facility on a JSP site that I am building.
    I am having difficulties adding an item to the basket.
    The page below (bookDetail.jsp) displays items for sale from a database. At the foot of the page, I have set up a hyperlink to add an item to a basket bean instance created in this page.
    What happens is the page will load correctly, when i hover the mouse over the hyperlink to add the item to the basket, the status bar shows the URL of the current page with the details of the book appended. This is what I want. But when I click the link, the page will only reload showing 20% of the content.
    Netbeans throws up no errors, neither does Tomcat, so I am assuming I have made a logical error somewhere.
    I have enclosed the Book class, and the ShoppingCart class for your reference.
    Any help would be really appreciated as I am at a loss here.
    Cheers.
    Edited highlights from bookDetail.jsp
    //page header importing 2 classes - Book and ShoppingCart
    <%@ page import="java.util.*, java.sql.*, com.shopengine.Book, com.shopengine.ShoppingCart" errorPage="errorpage.jsp" %>
    //declare variables to store data retrieved from database
    String rs_BookDetail_bookRef = null;
    String rs_BookDetail_bookTitle = null;
    String rs_BookDetail_author = null;
    String rs_BookDetail_price = null;
    //code that retrieves recordset data, displays it, and places it in variables shown above
    <%=(((rs_BookDetail_bookRef = rs_BookDetail.getString("book_ref"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_bookRef)%>
    <%=(((rs_BookDetail_author = rs_BookDetail.getString("author"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_author)%>
    <%=(((rs_BookDetail_bookTitle = rs_BookDetail.getString("book_title"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_bookTitle)%>
    <%=(((rs_BookDetail_price = rs_BookDetail.getString("price"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_price)%>
    //this link is to THIS PAGE to send data to server as request parameters in Key/Value pairs
    // this facilitates the add to basket function
    <a href="<%= response.encodeURL(bookDetail.jsp?title=
    "+rs_BookDetail_bookTitle+"
    &item_id=
    "+rs_BookDetail_bookRef +"
    &author="+rs_BookDetail_author +"
    &price=
    "+rs_BookDetail_price) %> ">
    <img src="images\addtobasket.gif" border="0" alt="Add To Basket"></a></td>
    // use a bean instance to store basket items
    <jsp:useBean id="basket" class="ShoppingCart" scope="session"/>
    <% String title = request.getParameter("title");
    if(title!=null)
    String item_id = request.getParameter("item_id");
    double price = Double.parseDouble(request.getParameter("price"));
    Book item = new Book(item_id, title, author, price);
    basket.addToBasket( item );
    %>
    ShoppingCart class that is used as a bean in bookDetail.jsp shown above
    package com.shopengine;
    //import packages
    import java.util.*;
    //does not declare explicit constructor which automatically creates a zero argument constructor
    //as this class will be instantiated as a bean
    public class ShoppingCart
    //using private instance variables as per JavaBean api
         private Vector basket;
         public ShoppingCart()
              basket = new Vector();
         }//close constructor
    //add object to vector
         public void addToBasket (Book book)
              basket.addElement(book);
         }//close addToBasket method
    //if strings are equal, delete object from vector
         public void deleteFromBasket (String foo)
    for(Enumeration enum = getBasketContents();
    enum.hasMoreElements();)
    //enumerate elements in vector
    Book item = (Book)enum.nextElement();
    //if BookRef is equal to Ref of item for deletion
    //then delete object from vector.
    if (item.getBookRef().equals(foo))
    basket.removeElement(item);
    break;
    }//close if statement
    }//close for loop
         }//close deleteFromBasket method
    //overwrite vector with new empty vector for next customer
         public void emptyBasket()
    basket = new Vector();
         }//close emptyBasket method
         //return size of vector to show how many items it contains
    public int getSizeOfBasket()
    return basket.size();
         }//close getSizeOfBasket method
    //return objects stored in Vector
         public Enumeration getBasketContents()
    return basket.elements();
         }//close getBasketContents method
         public double getTotalPrice()
    //collect book objects using getBasketContents method
    Enumeration enum = getBasketContents();
    //instantiate variable to accrue billng total for each enummeration
    double totalBillAmount;
    //instantiate object to store data for each enummeration
    Book item;
    //create a loop to add up the total cost of items in basket
    for (totalBillAmount=0.0D; enum.hasMoreElements(); totalBillAmount += item.getPrice())
    item = (Book)enum.nextElement();
    }//close for loop
    return totalBillAmount;
         }//close getTotalPrice method
    }//close shopping cart class
    Book Class that is used as an object model for items stored in basket
    package com.shopengine;
    import java.util.*;
    public class Book{
         //define variables
    private String bookRef, bookTitle, author;
         private double price;
    //define class
    public Book(String bookRef, String bookTitle, String author, double price)
    this.bookRef= bookRef;
    this.bookTitle=bookTitle;
    this.author=author;
    this.price=price;
    //create accessor methods
         public String getBookRef()
              return this.bookRef;
         public String getBookTitle()
              return this.bookTitle;
         public String getAuthor()
              return this.author;
         public double getPrice()
              return this.price;
    }//close class

    page will only reload showing 20% of the content.Im building some carts too and I had a similiar problem getting null values from the mysql database. Are you getting null values or are they just not showing up or what?
    On one of the carts I'm building I have a similiar class to yours called products that I cast onto a hashmap works alot better. Mine looks like this, maybe this is no help I don't know.......
    public class Product {
        /**An Item that is for sale.*/
          private String productID = "Missing";
          private String categoryID = "Missing";
          private String modelNumber = "Missing";
          private String modelName = "Missing";
          private String productImage = "Missing";
          private double unitCost;
          private String description = "Missing";
          public Product( 
                           String productID,
                           String categoryID,
                           String modelNumber,
                           String modelName,
                           String productImage,
                           double unitCost,
                           String description) {
                           setProductID(productID);
                           setCategoryID(categoryID);
                           setModelNumber(modelNumber);
                           setModelName(modelName);
                           setProductImage(productImage);
                           setUnitCost(unitCost);
                           setDescription(description);        
          public String getProductID(){
             return(productID);
          private void setProductID(String productID){
             this.productID = productID;
          public String getCategoryID(){
             return(categoryID);
          private void setCategoryID(String categoryID){
             this.categoryID = categoryID;
          public String getModelNumber(){
             return(modelNumber);
          private void setModelNumber(String modelNumber){
             this.modelNumber = modelNumber;
          public String getModelName(){
             return(modelName);
          private void setModelName(String modelName){
             this.modelName = modelName;
          public String getProductImage(){
             return(productImage);
          private void setProductImage(String productImage){
             this.productImage = productImage;
          public double getUnitCost(){
              return(unitCost);
          private void setUnitCost(double unitCost){
              this.unitCost = unitCost;
          public String getDescription(){
              return(description);
          private void setDescription(String description){
              this.description = description;

  • Weird one..  i can't return a variable from the extended to the super class

    Hey everyone, i hope i'm not annoying you guys :)
    So today's problem is to return a variable (int) from a method of the extended class and print it ont the super class.
    I'm just testing the super class , if it works fine.
    So the extended class ( FileIO) just read the file txt and return the integer or string ( from the txt file)
    I already did a main method to that class and tested it, it works fine.
    So now the problem is to print the integer ( that the extended class gets from the txt. ) inside the Super class. I mean , is the same thing but now im testing the Super class , just have to do the same thing, a super class method calls the extended class method and receive the integer from the txt file.
    i think the problem is when i create the instance of the FileIO object , maybe its constructor ...i don't know.
    The name of the txt file is passed from the super class to the extended class, but i think the error is not from there.
    this.aero_le = new BufferedReader(new FileReader(super.ficheiroleitura_aero()));  //  super calls ficheiroleitura_aero()  and receive the name of the txt file ( e.g "temp.txt")  so i think that is correct.
    here's the code of the Super class public class Aeroporto {
         private String filereader_voo = "temporary.txt";
         private String filereader_aero = "temp.txt";
         private String siglaAero = "";
         public FileIO file;
         public Aeroporto(){};
         public Aeroporto(String filereader_voo, String filereader_aero) throws IOException{
              this.filereader_voo = filereader_voo;
              this.filereader_aero =filereader_aero;     
              file = new FileIO();
         public String siglaAero() {
              return siglaAero; }
         public String filereader_aero(){
              return filereader_aero;
    public int nrLines() throws IOException{   // it was supose to retunr the number of lines ( integer) from the txt file .
              return Integer.parseInt(file.lerLinhaN(1,1));
    // main() {
    Aeroporto a = new Aeroporto();
              int v = a.nrLines();
              System.out.print(v);
    // ***********************************************************+
    // Extended Class
    public class FileIO extends Aeroporto{
         private String ficheiroescrita;
         private PrintWriter vooescreve, aeroescreve ;
         private BufferedReader voo_le, aero_read;
         public FileIO(){}
         public FileIO(String filereader_voo, String filereader_aero, String ficheiroescrita) throws IOException {
              super(filereader_voo, filereader_aero);
              this.ficheiroescrita = ficheiroescrita;
              //If file does not exists , create one.
              try{
                   this.aero_read = new BufferedReader(new FileReader(super.filereader_aero()));
                   aero_read.close();
              catch(IOException ex){
                   this.aeroescreve = new PrintWriter(new FileWriter(ficheiroescrita));
                   aeroescreve.close();
    public String lerLinhaN(int line, int column) throws IOException{  // this method works fine , i already tested this class.
              this.aero_read = new BufferedReader(new FileReader(super.filereader_aero()));
              for(int i = 0; i != line-1; ++i) aero_read.readLine();
              String linha = aero_read.readLine();
              String [] words = linha.split(" ");
              return words[column-1];
    Maybe the error is that i use to test the Super class a default contructor on both classes... i don't know where the error is, i also did two small classes ( super and another that extends ) and get the string "Hello" from the super and print it inside the extended..and it works, that's why i think the error is when i call the extended class .. need help.
    thanks.

    Ok,
    This one might actually work... atleast it compiles.import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.File;
    import java.io.PrintWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    public abstract class FileIO {
         public static boolean CreateOutputFileIfNotExists(
              String outputFilename //the name of the file to ensure exists.
         ) throws IOException
              final String functionName = "FileIO.CreateOutputFileIfNotExists";
              boolean retVal = false;
              //If the output file does does not exist then create it.
              //post condition: output file exists or an IOException has been thrown.
              BufferedReader infile = null;
              try{
                   infile = new BufferedReader(new FileReader(outputFilename));
                   retVal = true;
              } catch(IOException ex) {
                   PrintWriter outfile = null;
                   try {
                        outfile = new PrintWriter(new FileWriter(outputFilename));
                        retVal = true;
                   } catch(IOException ex2){
                        throw new IOException(functionName + ": cannot create output file " + outputFilename, ex2);
                   } finally {
                        outfile.close();
                        if (outfile.checkError()) {
                             throw new IOException(functionName + ": error on output stream " + outputFilename);
              } finally {
                   try {
                        infile.close();
                   } catch(IOException ex){
                        throw new IOException(functionName + ": cannot close output file " + outputFilename, ex);
              return(retVal);
         public static String readLine(
                   String  inputFilename //the name of the file to read.
              , int     lineNumber    //1 based number of the line to read from.
         ) throws IOException
              final String functionName = "FileIO.readLine";
              String outputLine = null;
              // reads the numbered "lineNumber" from "inputFilename".
              BufferedReader infile = null;
              try {
                   infile = new BufferedReader(new FileReader(new File(inputFilename)));
                   for(int i=1; i<lineNumber; ++i) infile.readLine();
                   outputLine = infile.readLine();
              } catch(IOException ex){
                   throw new IOException(functionName + ": cannot read input file " + inputFilename, ex);
              } finally {
                   try {
                        infile.close();
                   } catch(IOException ex){
                        throw new IOException(functionName + ": cannot close input file " + inputFilename, ex);
              return(outputLine);
         public static String readWord(
                   String inputFilename  //the name of the file to read.
              , int lineNumber        //1 based number of the line to read from.
              , int wordNumber        //0 based number of the word to read.
         ) throws IOException
              final String functionName = "FileIO.readWord";
              String outputWord = null;
              // reads the numbered space-seperated "wordNumber" from the numbered "lineNumber" of "inputFilename"
              try {
                   String[] words = FileIO.readLine(inputFilename, lineNumber).split(" ");
                   if (wordNumber>0 && wordNumber<words.length) outputWord = words[wordNumber-1];
              } catch(IOException ex){
                   throw new IOException(functionName + ": cannot read input file " + inputFilename, ex);
              return(outputWord);
    }Design notes... FileIO is a generic helper class... there is nothing specific to Airports, flights, or any other "domain" specific stuff in it... so it's re-usable... you can keep it and reuse it on other projects, or even share it with your friends.
    So... The airport class will just call the static methods on FileIO like this    ....
        int lineNumber=1;
        int wordNumber=1;
        String airportCode = FileIO.readWord(airportsFilename, lineNumber, wordNumber);
        ....How's that?
    corlettk: my now mandatory edit.

  • Logic error in a class I wrote...help

    I wrote this class to filter a simplified version of Military time; basically it
    returns a true or false statement to whether a specified string contains
    the appropriate character sequence. My problem is that it seems to
    report false even if my time format is correct.
    example:
    correct time: "0700"
    incorrect time: "700" or invlalid characters "asdf "
    maybe you all could catch me logic error...my head is bust
    class SimpleMilitaryTime
         //Verify that their are only 4 characters in the string
         public boolean verifyLength(String time)
              int textFieldLength;
              boolean flag = true;
              textFieldLength = time.length();
              if (textFieldLength == 4)
                   flag = true;
              else
                   flag = false;
              return flag;
         }//end verify length
         //Method for comparing characters that can be used
         public boolean verifyNumerals( String time )
              boolean flag = true;
              int flagCounter = 0;
              char theChar;
    //testing characters to see if they match or dont
    //match the below lists of char numerals
    //If they don't, the flagcounter is increased by 
    //one and the flag is returned as false
    //because the flagcounter is greater than 0 
    //indicating that they are not all numerals but
    //some other sort of character
              for (int i = 0; i <= time.length(); i++)
                     theChar = (char)time.indexOf(i);
                   switch (theChar)
                        case '0':
                             break;
                        case '1':
                             break;
                        case '2':
                             break;
                        case '3':
                             break;
                        case '4':
                             break;
                        case '5':
                             break;
                        case '6':
                             break;
                        case '7':
                             break;
                        case '8':
                             break;
                        case '9':
                             break;
                        default:
                              flagCounter = flagCounter + 1;
                   }//end of switch
              }//end of for loop
              if (flagCounter < 0 )
                   flag = true;
              else
                   flag = false;
              return flag;
         }//End of Method
         //Method to determine numeral format
         public boolean verifyFormat( String time )
              boolean flag = true;
              boolean hrFlag = true;
              boolean minFlag = true;
              String hr, min;
              hr = time.substring(0, 1);
              min = time.substring(2, 3);
              hrFlag = verifyHrRange( hr );
              //return true if its in the hour range of 0 to 23
              minFlag = verifyMinRange( min );     
                                              //return true if its in the minutes range of 0 to 59
              //If hrFlag or minFlag is false then format does
                                               //not meet the Military Time Format
              if (hrFlag == false || minFlag == false)
                   flag = false;
              else
                   flag = true;
         return flag;
         }//end of Method
         //Verify the Range of Hr  between 0 and 23
         public boolean verifyHrRange( String hr )
              int hrTime;
              boolean flag = true;
              hrTime = Integer.parseInt( hr );
              if ( hrTime >= 0 && hrTime <= 23 )
                   flag = true;
              else
                   flag = false;
         return flag;
         }//End of Method
         //Verify the Range of Minutes  between 0 and 59
         public boolean verifyMinRange( String min )
              int minTime;
              boolean flag = true;
              minTime = Integer.parseInt( min );
              if ( minTime >= 0 && minTime <= 59 )
                   flag = true;
              else
                   flag = false;
         return flag;
         }//End of Method
         //Method validates total time content
         public boolean validateTime( String time )
              boolean flag = true;
              boolean flagLength = true;
              boolean flagNumerals = true;          
              boolean flagFormat = true;          
              flagLength = verifyLength( time );                         //Is the length  == to 4 characters long
              if( flagLength == true )
                   flagNumerals = verifyNumerals( time );               //Is the content made up of numerals
                   if( flagNumerals == true )
                        flagFormat = verifyFormat( time );               //Is the format within MilitaryTime Specs
                        if( flagFormat == true )
                             flag = true;
                        else
                             flag = false;                                             //IF one or all are FALSE then FLAG is set to false
                   else
                        flag = false;
              else
                   flag = false;
              //return status of test run
              return flag;               
         }//End of Method
    }//End of Class

    Interestingly enough, although both examples simplify the logic, I still
    recieve a "false" when testing it. Here is some more code that I use
    when a text field has lost focus. Right now the code is set to just test
    the input.
    The field is inialized to "1234". Once the field gains focus, it immediately sets to "false"...not sure why.?.? Even after resetting field
    to another 4 digit numeral sequence I still get a "false" return instead of
    verifying it as "true. " any ideas?
    here is the code for testing the MilitaryTime class:
    private class TextFieldListener extends FocusAdapter
         //method that listens losing focus of textfield
         public void focusLost( FocusEvent ev )
              boolean flag;
              String indFALSE, indTRUE;
              indFALSE = "FALSE";
              indTRUE = "TRUE";
              int strLength;
              flag = mt.isValidTime(sunMornStartTime_str); //mt is for MilitaryTime
              if (flag == false)
              sunMornStartTime.setText(new String(indFALSE));
              if (flag == true)
              sunMornStartTime.setText(new String(indTRUE));
         }//End of Method
    }//End of private class TextFieldAction

  • If the result from the stored procedure returns 0 rows I get this error returned:

    If the result from the following stored procedure returns 0
    rows I get this error returned:
    faultCode:Server.Processing faultString:'Variable transfers
    is undefined.' faultDetail:''
    How can I get round this?

    Well if I try this in a cfm page:
    <cfstoredproc procedure="GetTransfers"
    datasource="datasource" returncode="true">
    <cfprocparam type="in" cfsqltype="CF_SQL_VARCHAR"
    value="4">
    <cfprocparam type="in" cfsqltype="cf_sql_date"
    value="12/09/2006 08:42:00">
    <cfprocparam type="in" cfsqltype="cf_sql_date"
    value="12/09/2008 08:42:00">
    <cfprocresult name="transfers">
    I get an error like:
    [Macromedia][SQLServer JDBC Driver][SQLServer]Procedure or
    function 'GetTransfers' expects parameter '@fromdate', which was
    not supplied.
    But this procedure only accepts 3 parameters.

  • Reg:"No result returned or xml returned in the result contains an Error

    Dear All,
    After adding a query to VC storyboard and than trying to use the option define/test query for this query element, I am facing the below error on pressing the execute button.
    "No result returned or xml returned in the result contains an error"
    Query is working fine and giving the desired output in BW system.
    How can i resolve my problem?
    Regards,
    Hemalatha J
    Edited by: hema latha on Nov 19, 2009 3:21 PM

    Hi Hemalatha,
    this can have several reasons, usually there are variables in the query that aren't filled correctly in the "specify filter" box.
    One thing you could do is to personalize all variables in the query and then try to fill one after another in the "specify filter" box.
    If you don't get values after you have filled a specific one of them, then this one is passed incorrectly.
    Best wishes
    Markus

  • How to return 4 variables by one return statement

    Hello Experts
    I’m trying to develop & run a function which will collect data from 2 difference tables. I accomplished it and stores all the information which I need in 4 variables. Now as we all know that function must has to return but I don’t know how to return all these 4 variable using 1 return. Can please somebody show me how I can return 4 variables.
    For reference here is my code
    create or replace function TOT_PURCH_SF (id_shopper in bb_basket.idshopper%type)
    return VARCHAR2
    as
    cursor cur_bb_basket is
    select idshopper, total
    from bb_basket;
    cursor cur_bb_shopper is
    select firstname, lastname
    from bb_shopper
    where idshopper = id_shopper;
    v_idshopper VARCHAR2(4);
    v_total bb_basket.total%type;
    v_gtotal bb_basket.total%type := 0;
    v_fname bb_shopper.firstname%type;
    v_lname bb_shopper.lastname%type;
    v_result VARCHAR2(200);
    begin
    if not (cur_bb_basket%isopen) then
    open cur_bb_basket;
    end if;
    loop
    fetch cur_bb_basket into v_idshopper, v_total;
    if (v_idshopper = id_shopper) then
    v_gtotal := v_gtotal + v_total;
    dbms_output.put_line('Shopper Info: '|| v_idshopper ||', '|| v_total);
    --exit;   
    end if;
    exit when cur_bb_basket%NOTFOUND;
    end loop;
    -- dbms_output.put_line('Shopper ID:'|| v_idshopper || ', TOTAL:' || v_gtotal);
    close cur_bb_basket;
    open cur_bb_shopper;
    fetch cur_bb_shopper into v_fname, v_lname;
    close cur_bb_shopper;
    dbms_output.put_line('Shopper ID:'|| v_idshopper || ', TOTAL:' || v_gtotal);
    dbms_output.put_line('FIRST NAME: '|| v_fname ||' LAST NAME: '|| v_lname);
    -- return (dbms_output.put_line('Shopper ID:'|| v_idshopper || ', TOTAL:' || v_gtotal));
    return 'test';
    end;
    Thanks a lot in advance

    Hi,
    If you want more than one variable returned by something, used a procedure with this variables declared as output variables. You only need to declare the procedure and keep the internal logic (with minimal changes).
    Your code modified (please remove dead code):
    CREATE OR REPLACE PROCEDURE TOT_PURCH_SF(id_shopper  IN bb_basket.idshopper%TYPE,
                                             p_idshopper OUT VARCHAR2,
                                             p_gtotal    OUT bb_basket.total%TYPE,
                                             p_fname     OUT bb_shopper.firstname%TYPE,
                                             p_lname     OUT bb_shopper.lastname%TYPE) AS
       CURSOR cur_bb_basket IS
          SELECT idshopper,
                 total
            FROM bb_basket;
       CURSOR cur_bb_shopper IS
          SELECT firstname,
                 lastname
            FROM bb_shopper
           WHERE idshopper = id_shopper;
       v_idshopper VARCHAR2(4);
       v_total     bb_basket.total%TYPE;
       v_gtotal    bb_basket.total%TYPE := 0;
       v_fname     bb_shopper.firstname%TYPE;
       v_lname     bb_shopper.lastname%TYPE;
       v_result    VARCHAR2(200);
    BEGIN
       IF NOT (cur_bb_basket%ISOPEN) THEN
          OPEN cur_bb_basket;
       END IF;
       LOOP
          FETCH cur_bb_basket
             INTO v_idshopper, v_total;
          IF (v_idshopper = id_shopper) THEN
             v_gtotal := v_gtotal + v_total;
             dbms_output.put_line('Shopper Info: ' || v_idshopper || ', ' || v_total);
             --exit;
          END IF;
          EXIT WHEN cur_bb_basket%NOTFOUND;
       END LOOP;
       -- dbms_output.put_line('Shopper ID:'|| v_idshopper || ', TOTAL:' || v_gtotal);
       CLOSE cur_bb_basket;
       OPEN cur_bb_shopper;
       FETCH cur_bb_shopper
          INTO v_fname, v_lname;
       CLOSE cur_bb_shopper;
       --dbms_output.put_line('Shopper ID:' || v_idshopper || ', TOTAL:' || v_gtotal);
       --dbms_output.put_line('FIRST NAME: ' || v_fname || ' LAST NAME: ' || v_lname);
       -- return (dbms_output.put_line('Shopper ID:'|| v_idshopper || ', TOTAL:' || v_gtotal));
       --RETURN 'test';
       p_idshopper := v_idshopper;
       p_gtotal    := v_gtotal;
       p_fname     := v_fname;
       p_lname     := v_lname;
    END;Regards,
    Tip: to post formatted code, please enclose it between {noformat}{noformat} tags (start and end tags are the same) :)
    Edited by: Walter Fernández on Mar 3, 2009 8:19 PM - Adding procedure (not tested)...
    Edited by: Walter Fernández on Mar 3, 2009 8:20 PM - Adding useful tip...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SOME LOGICAL ERROR

    sir i write code for finding freuent pattern but it give some logical error plz see that and correct that
    i send the complete information to u my input file my project code my output file and my actual output that i need ......plz sir chek it where is he logical mistak in code i completely chek lots of time i m not able to find where is the logical mistak plz sir help me
    input file "transactions.xml"
    <?xml version="1.0" standalone="yes"?>
    <transactions>
    <transaction id="1">
    <items>
    <item>a</item>
    <item>d</item>
    <item>e</item>
    </items>
    </transaction>
    <transaction id="2">
    <items>
    <item>b</item>
    <item>c</item>
    <item>d</item>
    </items>
    </transaction>
    <transaction id="3">
    <items>
    <item>a</item>
    <item>c</item>
    <item>e</item>
    </items>
    </transaction>
    <transaction id="4">
    <items>
    <item>b</item>
    <item>c</item>
    <item>d</item>
    </items>
    </transaction>
    <transaction id="5">
    <items>
    <item>a</item>
    <item>b</item>
    </items>
    </transaction>
    </transactions>
    coding :=
    xquery version "1.0";
    declare namespace local = "http://www.w3.org/2003/11/xpath-local-functions";
    declare function local:join($X as element()*, $Y as element()*) as element()* {
    let $items := (for $item in $Y
    where every $i in $X satisfies
    $i != $item
    return $item)
    return $X union $items
    declare function local:commonIts($X as element()*, $Y as element()*) as element()* {
    for $item in $X
    where some $i in $Y satisfies $i = $item
    return $item
    declare function local:removeIts($X as element()*, $Y as element()*) as element()* {
    for $item in $X
    where every $i in $Y satisfies $i != $item
    return $item
    declare function local:candidateGen($l as element()*) as element()* {
    for $freqSet1 in $l
    let $items1 := $freqSet1//items/*
    for $freqSet2 in $l
    let $items2 := $freqSet2//items/*
    where $freqSet2 >> $freqSet1 and
    count($items1)+1 = count($items1 union $items2)
    and local:prune(local:join($items1,$items2), $l)
    return
    <items>{local:join($items1,$items2)}</items>
    declare function local:prune($X as element()*, $Y as element()*) as xs:boolean
    every $item in $X satisfies
    some $items in $Y//items satisfies
    count(local:commonIts(local:removeIts($X,$item),$items/*))
    = count($X) - 1
    declare function local:removeDuplicate($C as element()*) as element()*
    for $itemset1 in $C
    let $items1 := $itemset1/*
    let $items :=(for $itemset2 in $C
    let $items2 := $itemset2/*
    where $itemset2>>$itemset1 and
    count($items1) =
    count(local:commonIts($items1, $items2))
    return $items2)
    where count($items) = 0
    return $itemset1
    declare function local:getLargeItemsets($C as element()*, $minsup as xs:decimal, $total as xs:decimal, $src as element()*) as element()*
    for $items in $C
    let $trans := (for $tran in $src
    where every $item1 in $items/* satisfies
    some $item2 in $tran/*
    satisfies $item1 = $item2
    return $tran)
    let $sup := (count($trans) * 1.00) div $total
    where $sup >= $minsup
    return <largeItemset> {$items}
    <support> {$sup} </support>
    </largeItemset>
    declare function local:fp-growth($l as element()*, $L as element()*, $minsup as xs:decimal, $total as xs:decimal, $src as element()*) as element()*
    let $C := local:removeDuplicate(local:candidateGen($l))
    let $l := local:getLargeItemsets($C, $minsup, $total, $src)
    let $L := $l union $L
    return if (empty($l)) then
    $L
    else
    local:fp-growth($l, $L, $minsup, $total, $src)
    let $src := doc("transactions.xml")//items
    let $minsup := 0.5
    let $total := count($src) * 1.00
    let $C := distinct-values($src/*)
    let $l :=(for $itemset in $C
    let $items := (for $item in $src/*
    where $itemset = $item
    return $item)
    let $sup := (count($items) * 1.00) div $total
    where $sup >= $minsup
    return <largeItemset>
    <items> {$itemset} </items>
    <support> {$sup} </support>
    </largeItemset>)
    let $L := $l
    return <largeItemsets> { local:fp-growth($l, $L,$minsup, $total, $src) }
    </largeItemsets>
    output that is get for running the query:=
    <?xml version="1.0" encoding="UTF-8"?>
    <largeItemsets>
    <largeItemset>
    <items>a</items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <items>d</items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <items>b</items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <items>c</items>
    <support>0.6</support>
    </largeItemset>
    </largeItemsets>
    but sir i want my output like that:=
    <?xml version="1.0" standalone="yes"?>
    <largeItemsets>
    <largeItemset>
    <Items>
    <item>a</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>d</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>b</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>c</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>d</item>
    <item>b</item>
    </Items>
    <support>0.4</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>b</item>
    <item>c</item>
    </Items>
    <support>0.4</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>d</item>
    <item>c</item>
    <item>b</item>
    </Items>
    <support>0.4</support>
    </largeItemset>
    </largeItemsets>
    sir i want that output which i shown last help me sir how i sort out this problem
    thank i advance
    SIR PLZ HELP ME WHAT I DO HOW I SOLVE THAT PROBLEM PLZ ANY ONE HELP ME
    Edited by: MAXIMUM on Apr 9, 2012 10:43 PM

    The code is unreadable. It would be great if you can explain the problem statement.

  • Logical error in the query

    create table my_employee
    (id number(4)primary key,
    last_name varchar2(25),
    first_name varchar2(25),
    userid varchar2(8),
    salary number(9,2)
    I want to write an INSERT statement to MY_EMPLOYEE table . Concatenate the first letter of the first name and first seven characters of the last name to produce user ID using a single sql statement
    I wrote the query like this and i am getting logical error
    insert into my_employee
    values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SQL> insert into my_employee
    2 values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&sal
    ary);
    Enter value for id: 20
    Enter value for last_name: popopopp
    Enter value for last_name: qwertyyuu
    Enter value for salary: 300000
    old 2: values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),
    new 2: values(20,'popopopp','o',substr('o',1,1)||substr('qwertyyuu',1,7),300000)
    1 row created.
    it is asking the last_name two times

    you can do it with a .sql script
    c:\my_emp.sql
    PROMPT
    PROMPT instering my_employees
    PROMPT
    ACCEPT ID NUMBER PROMPT 'ID ? : '
    ACCEPT FIRST_NAME CHAR PROMPT 'FIRST_NAME ?: '
    ACCEPT LAST_NAME CHAR PROMPT 'LAST_NAME ?: '
    ACCEPT SALARY NUMBER PROMPT 'SALARY ? : '
    insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SELECT * FROM my_employee where id=&&id;
    and then from sqlplus @c:\my_emp.sql
    scott@ORCL> @C:\MY_EMP
    instering my_employees
    ID ? : 20
    FIRST_NAME ?: john
    LAST_NAME ?: papas
    SALARY ? : 1000
    old 1: insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary)
    new 1: insert into my_employee values( 20,'papas','john',substr('john',1,1)||substr('papas',1,7), 1000)
    1 row created.
    old 1: SELECT * FROM my_employee where id=&&id
    new 1: SELECT * FROM my_employee where id= 20
    ID LAST_NAME FIRST_NAME USERID SALARY
    20 papas john jpapas 1000
    scott@ORCL>

  • ABAP LOGICAL ERRORS

    Expalin about ABAP Logical errors?
    Help me sending appropriate link to understand more.
    Moderator Message: Read the Rules of Engagement of this forum.
    Edited by: kishan P on Dec 27, 2011 9:50 PM

    Hi Vinay,
         You can't delete the ABAP Runtime errors. But  you can catch the errors using catch exception Statement.
    For Example,
    Class-based exceptions are handled in the following control structure:
    TRY.
      ...                       " TRY block (application coding)
    CATCH cx_... cx_... ...
        ...                     " CATCH block (exception handler)
    CATCH cx_... cx_... ...
        ...                     " CATCH block (exception handler)
      CLEANUP.
        ...                     " CLEANUP block (cleanup context)
    ENDTRY.
    Try This Sample Code,
    *--EXAMPLE FOR RUNTIME ERROR--
    *DATA : VALUE1 TYPE I.
    *VALUE1 = 1 / 0.        -
    >>>>>> IT MAKES RUN TIME ERROR.
    *WRITE : VALUE1.
    *-EXAMPLE FOR HOW TO CATCH THE ARITHMETIC ERROR AT THE RUN TIME USING SUBRC----
    DATA : VALUE1 TYPE I.
    CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 1.
    VALUE1 = 1 / 0.
    WRITE : VALUE1.
    ENDCATCH.
    IF SY-SUBRC = 1.
    WRITE : ' IT MAKES ERROR'.
    ELSE.
    WRITE : VALUE1.
    ENDIF.
    Thanks,
    Reward If Helpful.

  • Logical Error in Script Logic

    Hello Experts,
    Please provide your guidance for the following scenario.
    I need to calculate the 'Accumulated Depreciation' for every month, based on the amounts in the 'AccumDep' and the 'Depreciation' accounts.
    In other words, the value of the Accumulated Depreciation for the month of Feb should be equal to (Accumulated Depreciation in Jan + Depreciation in Jan), and so on.
    To accomplish this, I have written the following script logic.
    *WHEN ACCOUNT
    *IS AccumDep, Depreciation
         *FOR %MON% = 2009.FEB,2009.MAR,2009.APR
              *REC(FACTOR=1, ACCOUNT=AccumDep, TIME=%MON%)
         *NEXT
    *ENDWHEN
    *COMMIT
    The above logic was validated without any 'syntax' errors.  However, I do not see the desired results, as the Accumulated Depreciation is not getting updated every month.  The amount from FEB appears for MAR & APR also.
    Therefore, could you please review the above script and let me know if there are any 'logical' errors?
    All your guidance is greatly appreciated.  Thanks...

    Hi,
    You are not getting the desired result because you are trying to aggregate the depreciation and the accumulated depreciation of the same month and post the result again in the same month. Lets say the code is working for 2009.MAR. You are trying to add the depreciation and accumulated depreciation of 2009.MAR. However, you still dont have the acc depreciation of 2009.MAR. You basically need to take the acc depreciation of the previous month.
    You can try something like:
    *WHEN ACCOUNT
    *IS Depreciation
         *FOR %MON% = 2009.FEB,2009.MAR,2009.APR
              *REC(EXPRESSION = %VALUE% + ([ACCOUNT].[AccumDep],[TIME].Previous), ACCOUNT=AccumDep)
         *NEXT
    *ENDWHEN
    *COMMIT
    You can have a property called Previous to store the previous month of each period in the time dimension.
    Hope you got the idea.

  • Returns status code '500' (Internal Server Error) in response

    Hi,
    I got error like
    HTTP connection to http://XXX.com:50600/sap/xi/cache?sap-client=001 returns status code '500' (Internal Server Error) in response
    I did check this Discussion HTTP returns status is 500(Internal Server Error)
    But I don't understand can someone help me in detail.
    Thanks
    Kamal

    Hi All,
    When I check RFC destination configuration with following information.
    RFC Destination as "INTEGRATION_DIRECTORY_HMI"
    Connection Type: H
    Under Technical Setting TAB
    Target Host: write the host name
    Path Prefix: /dir/CacheRefresh
    Service No: enter J2ee port no (e.g. 50000)
    Under Logon/Security TAB
    select Basic Authontication radio button
    SSL select inactive
    Under Logon:
    Lang: EN
    Client: enter client
    User: XIISUSER
    Password: *******
    Under Special Option TAB
    HTTP Setting:
    HTTP Ver: HTTP 1.0
    Compression: inactive
    Compressed response: NO
    HTTP Cookies: Yes (All)
    This is the test result.
    Status HTTP response : 403
    Status text : Forbidden
    Duration test call : 163 ms
    Please help me.
    Thanks,
    Kamal

  • Identifying syntax and logical errors

    Hey guys,
    I'm new to java and I can't figure out this problem as I can't make JDK work with comand prompt for some reason and when trying to write the java in a web page it won't work.
    Can anyone tell me what the three syntax errors and one logical error in the following code is?
    public class Add
    public static void main(String[] args)
    double weight1 = 85.5
    double weight2 = 92.3
    double averWeight = weight1 + weight2 / 2;
    System.out.println("Average is " + aver);
    Any help would be very much appreciated.

    Ok. I'm new to Java. Thanks to the both of you for your help.You're welcome of course; here's a tip: type in these little exercises
    and try to compile them; carefully read what the compiler has to say
    about the possible errors. Note that the compiler is totally blind to
    most "logical errors".
    kind regards,
    Jos

  • Too many logical errors (in terms of business processes); maximum was 100

    hi friends !
    I'm using the direct input program RMDATIND for uploading the material master data. and i'm facing the error:
    "Too many logical errors (in terms of business processes); maximum was 100"
    thanks and regards,
    sachin soni

    Hi,
    If you checked in standard program,problem is occuring in the function module
    'MATERIAL_MAINTAIN_DARK'.

  • Logical error iExpenses

    There is a way to follow the details of each paguina Web within iExpenses, I have a logical error where I erased information already captured by pressing the button "Save" someone could mencionarme something.
    Thanks

    you can do it with a .sql script
    c:\my_emp.sql
    PROMPT
    PROMPT instering my_employees
    PROMPT
    ACCEPT ID NUMBER PROMPT 'ID ? : '
    ACCEPT FIRST_NAME CHAR PROMPT 'FIRST_NAME ?: '
    ACCEPT LAST_NAME CHAR PROMPT 'LAST_NAME ?: '
    ACCEPT SALARY NUMBER PROMPT 'SALARY ? : '
    insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SELECT * FROM my_employee where id=&&id;
    and then from sqlplus @c:\my_emp.sql
    scott@ORCL> @C:\MY_EMP
    instering my_employees
    ID ? : 20
    FIRST_NAME ?: john
    LAST_NAME ?: papas
    SALARY ? : 1000
    old 1: insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary)
    new 1: insert into my_employee values( 20,'papas','john',substr('john',1,1)||substr('papas',1,7), 1000)
    1 row created.
    old 1: SELECT * FROM my_employee where id=&&id
    new 1: SELECT * FROM my_employee where id= 20
    ID LAST_NAME FIRST_NAME USERID SALARY
    20 papas john jpapas 1000
    scott@ORCL>

Maybe you are looking for