Displaying array from another method

Hello for this code I want to display the array from the first method in the second method although when I run it, it displays 6 times the whole array - well the the last iteration shows the whole array. I have only just started using different methods.
Please could someone say why this is happening.
Cheers
John
import java.util.*;
public class Lottery
     public static void main(String[] argStrings)
          int[] lotteryArray = new int[6];
          for(int count = 0; count < 6; count++)
               double randomNumber = Math.random();
               double biggerRandom = (randomNumber * 50);
               int integerNumber = (int)biggerRandom;
               lotteryArray[count] = integerNumber;
               displayNumbers(lotteryArray);
     public static void displayNumbers(int[] lotteryArray)
          System.out.println("Lottery numbers are:");
          for(int i = 0; i < lotteryArray.length; i++)
               System.out.print(lotteryArray[i] + " ");
          System.out.println();
}

Well I know your right but actualy getting this to work for my program is proving hard. This is my progress so far:
Cheers
John
public static void main(String[] argStrings)
          int[] lotteryArray = new int[6];
          int p = 0;
          boolean duplicate = false;
          while(p < 6)
               for(int count = 0; count < lotteryArray.length; count++)
                    double randomNumber = Math.random();
                    double biggerRandom = (randomNumber * 50);
                    int integerNumber = (int)biggerRandom;
                    if (lotteryArray == lotteryArray[count])
                         duplicate = true;
                    if (duplicate == false) //not a duplicate
                         lotteryArray[++count] = integerNumber;
               displayNumbers(lotteryArray);
     }

Similar Messages

  • How do I access array elements in one method from another method?

    Hi all!
    How do I access the array's elements from another method so that method 2 can have access to method 1's array elements? Thanks for any help!
    I am trying to create a simply program that will use a method to create an array and a SEPARATE method that will sort the array's elements (without using java's built in array features). I can create the program by simply having one method and sorting the array within that same method, BUT I want to sort the array from another method.
    Here's my code so far:
    public class ArraySort {
       public static void createArray(int size){
           double myArray[] = new double[size];    //create my new array
           for(int j=0; j < myArray.length; j++)
              myArray[j] = (200.0 * Math.random() + 1.0);   //fill the array with random numbers
       public static void sortArray(){
           // I WANT THIS METHOD TO ACCESS THE ARRAY ELEMENTS IN THE METHOD ABOVE, BUT DON'T KNOW
          //  HOW???? Please help!
        public static void main(String[] args) {
            createArray(4);    //call to create the array
    }Thanks again!
    - Johnny

    Thanks for the help all! I ve managed to get the program working, using java's built in array sort, but when i try to call on the array sort method from WITHIN my main method, nothing happens!
    Can somebody please tell me why I am not able to call on the sort method from within my main class???? Thanks!
    public class ArraySort {
       public void createArray(double[] arrayName, int size){
           double myArray[] = new double[size];  //create new array
           for(int j=0; j < myArray.length; j++)
              myArray[j] = (200.0 * Math.random() + 1.0);    //populate array with
           }                                                 //random Numbers
           sortArray(myArray); 
       } //Sort array(if I delete this & try to use it in Main method --> doesn't work???
       public void sortArray(double[] arrayName){
           DecimalFormat time = new DecimalFormat("0.00");
           Arrays.sort(arrayName);      //sort array using Java's built in array method
           for(int i = 0; i <arrayName.length; i++)
               System.out.println(time.format(arrayName)); //print arary elements
    public static void main(String[] args) {
    ArraySort newArray = new ArraySort(); //create a new instance
    double myArray[] = new double[0]; //create a new double array
    newArray.createArray(myArray,4); //build the array of indicated size
    //newArray.sortArray(myArray); //This will not work???? WHY?????//

  • How can I use my array in another method.... Or better yet, what's wrong?

    I guess I'll show you what I am trying to do rather and then explain it
    public class arraycalc
    int[] dog;
    public void arraycalc()
    dog = new int[2];
    public void setSize(int size)
    dog[1] = size;
    public int getSize()
    return dog[1];
    This gives me a null pointer exception...
    How can I use my array from other methods?

    You have to make the array static. :)
    Although I must admit, this is rather bad usage. What you want to do is use an object constructor to make this class an object type, and then create the array in your main class using this type, and then call the methods from this class to modify your array. Creating the array inside the other method leads to a whole bunch of other stuff that's ... well, bad. :)
    Another thing: Because you're creating your array inside this class and you want to call your array from another class, you need to make the array static; to make it static, you must make your methods static. And according to my most ingenious computer science teacher, STATIC METHODS SUCK. :D
    So, if you want to stick with your layout, it would look like:
    public class arraycalc
         static int[] dog;
         public static void arraycalc()
              dog = new int[2];
         public static void setSize(int size)
              dog[1] = size;
         public static int getSize()
              return dog[1];
    }But I must warn you, that is absolutely horrible code, and you shouldn't use it. In fact, I don't even know why I posted it.
    You should definitely read up on OOP, as this problem would be better solved by creating a new object type.

  • Passing Array to Another Method

    Hello, I created a program with an array in one of the methods. I have been trying to figure out how to correctly pass the array to another method in the same class. I know my problem is in my method delcaration statements. Could someone please show me what I am doing wrong? Please let me know if you have any questions. Thanks for your help.
    import javax.swing.*;
    import java.util.*;
    class Bank1 {
         public static void main(String[] args) {
              Bank1 bank = new Bank1();
              bank.menu();
         //Main Menu that initializes other methods
         public void menu( ) {
              Scanner scanner = new Scanner(System.in);
              System.out.println("Welcome to the bank.  Please choose from the following options:");
              System.out.println("O - Open new account");
              System.out.println("T - Perform transaction on an account");
              System.out.println("Q - Quit program");
              String initial = scanner.next();
              char uInitial = initial.toUpperCase().charAt(0);
              while (uInitial != 'O' && uInitial != 'T' && uInitial != 'Q') {
                   System.out.println("That was an invalid input. Please try again.");
                   System.out.println();
                   initial = scanner.next();
                   uInitial = initial.toUpperCase().charAt(0);
              if (uInitial == 'O') newAccount();
              if (uInitial == 'T') transaction();
         //Method that creates new bank account
         public Person[] newAccount( ) {
              Person[] userData = new Person[1];
              for (int i = 0; i < userData.length; i++) {
                   Scanner scanner1 = new Scanner(System.in);
                   System.out.println("Enter your first and last name:");
                   String name = scanner1.next();
                   Scanner scanner2 = new Scanner(System.in);
                   System.out.println("Enter your address:");
                   String address = scanner2.next();
                   Scanner scanner3 = new Scanner(System.in);
                   System.out.println("Enter your telephone number:");
                   int telephone = scanner3.nextInt();
                   Scanner scanner4 = new Scanner(System.in);
                   System.out.println("Enter an initial balance:");
                   int balance = scanner4.nextInt();
                   int account = i + 578;
                   userData[i] = new Person( );
                   userData.setName               ( name );
                   userData[i].setAddress          ( address );
                   userData[i].setTelephone     ( telephone );
                   userData[i].setBalance          ( balance     );
                   userData[i].setAccount          ( account     );
                   System.out.println();
                   System.out.println("Your bank account number is: " + userData[i].getAccount());
              return userData;
              menu();
         //Method that gives transaction options
         public void transaction(Person userData[] ) {
              System.out.println(userData[0].getBalance());

    Thank you jverd, I was able to get that to work for me.
    I have another basic question about arrarys now. In all of the arrary examples I have seen, the array is populated all at once using a for statement like in my program.
    userData = new Person[50];
    for (int i = 0; i < userData.length; i++) In my program though, I want it to only fill the first array parameter and then go up to the main menu. If the user chooses to add another account, the next spot in the array will be used. Can someone point me in the right direction for doing this?

  • Call String from another method

    hey,
    Im pretty new to java and Im having problems with calling a String from another method
    I have two public voids, in one of them I have a String which I wanna use in another method.
    Thanks

    here is some of my code:
    public void getOrder() {
            try {
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                Document doc = docBuilder.parse(new File("c:/orders.xml"));
                // normalize text representation
                doc.getDocumentElement().normalize();
                System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
                // lees orders
                NodeList orderlijst = doc.getElementsByTagName("order_naam");
                System.out.println("totale aantal orders : " + orderlijst.getLength());
             //    Element orderitem = (Element) orderlijst.item(0);
    System.out.println("name=" + doc.getElementsByTagName("order_naam").item(0).getFirstChild().getNodeValue());
              String st =doc.getElementsByTagName("order_naam").item(0).getFirstChild().getNodeValue();
      public void createGUI () {
            this.removeAll();
            lbltest = new JLabel();
            lbltest.setBounds(20, 40, 150, 20);
            lbltest.setFont(new Font("Verdana", Font.BOLD, 12));
            this.add(lbltest);
        i want to use the String st in the jLabel in createGUI

  • Passing an array from one method to another

    I am passing an array from my "load" method and passing it to be displayed in my "display" method in an applet .
    I made the array a class variable (to be able to pass it to the "display" method).
    The applet runs, but nothing seems to be in the array.The screen says applet started, but nothing else. There does not seem to be any CPU activity.
    Trying to debug this, I have tried to paint the screen during the array build. I never figured out how to do this. So I made this a non applet class, put it in debug, and the array seems to load okay.
    Any help is appreciated.
    This is the applet code:
    import java.applet.Applet;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    public class urla extends java.applet.Applet
    int par1;
    int i = 1;
    int j = 20;
    int m = 0;
    int k = 0;
    String arr[] = new String[1000];
    String inputLine;
        public void load() throws Exception
          try
            URL mysite = new URL("http://www.xxxxxxxxxxxxxx.html");
           URLConnection ms = mysite.openConnection();
           BufferedReader in = new BufferedReader(
           new InputStreamReader(
           ms.getInputStream()));
             while ((inputLine = in.readLine()) != null)
               arr[m] = inputLine;
               m++;
           in.close();
          catch (MalformedURLException e)
            k++;
        public void display(Graphics screen)
          screen.drawString("THE FOLLOWING HAVE ADDED THEIR BIOS:",5 ,5);
          for (int i = 0; i < 20; i++);
            j = j + 20;
            screen.drawString("output - "
            + arr, 5, j);
            repaint() ;
    }

    String arr[] = new String[1000];is this typing mistake????? because if u did it in
    program as well i don think it will work.. the tag is
    innnside array lenght... hope iam saying this right!!no, he had the bold form tags (b and /b inside square brackets) in his previous non-code tagged post. He carried it over to this post and they caused an error. I highly doubt that they were in his actual program. Just delete them.
    Message was edited by:
    petes1234

  • Using a variable from another method within another method

    I have a couple methods. In the beginning of the class I declared the double variables. Then I have a method1 that in that class that changes those double variables. Then the last method2 runs, and is suppose to print information to the screen with the changed variable information all being called from another class. How do I get those changed double variables to be read in method2?

    Sorry about all that, when I paste it in from the compiler it's skews it some, but hopefully this should be more readable
    * Project Filename: Lab1s2
    * Program Filename: Lab1s2.java
    * I/O Files used:
    * Fuction:          This program will use interactive input to ask cost of a
    *                   product in dollars and cents (eg. 17.50).  If the product
    *                   is not less than $100.00, an error message will be displayed
    *                   and input will be requested again.  Once a valid value is
    *                   given, the program will calculate the fewest bills and change
    *                   to be returned if the customer gives a $100.00 bill.
    * Formulas:         (100 - amount = change)
    * Algorithm:
    * Purpose:          The main method calls other methods found in the MoneyXX class
    *                   that will accomplish the function of the project.
    public class Lab2sl
         public static void main( String[] args ) // main method begins program execution
         Money2sl myMoney2sl = new Money2sl(); // create myMoney2sl object and assign it to Money2sl
            myMoney2sl.inputSL();// calls input method and pass argument
            myMoney2sl.changeSL(); // calls change method
            System.out.println(); // output a blank line
         myMoney2sl.outputSL(); //calls outputSL to show results
    * Project Filename: Money2SL.java
    import java.util.Scanner;
    import java.util.Calendar;
    public class Money2sl
         Scanner input = new Scanner( System.in ); // create Scanner to obtain input from command window
        private double change,
                       amount; // instant variable, stores amount
        private double twentyD = 20.00;
        private double tenD = 10.0;
        private double fiveD = 5.0;
         private double dollar = 1.0;
         private double quarter = 0.25;
         private double dime = 0.10;
         private double nickel = 0.05;
         private double penny = 0.01;
         private double numTwentyD;
         private double numTenD;
         private double numFiveD;
         private double numDollar;
         private double numQuarter;
         private double numDime;
         private double numNickel;
         private double numPenny;
        // inputSL() method gets amount, checks to see if it is under $100, stores amount into variable
        public void inputSL() //input method
             Calendar dateTime = Calendar.getInstance(); // get current date and time
            //print date and time
            System.out.printf( "%s\n", "nothing" );
            System.out.printf( "%1$ta, %1$tB. %1$te, %1$tY %1$tr\n\n", dateTime );
             //print output
                System.out.println( "Please enter the amount of money (less than $100) that you will spend: ");  // prompt
              amount = input.nextDouble();
              while ( amount > 100 )
                  System.out.println( "error - enter amount less than $100");
                System.out.println( "Please enter the amount of money (less than $100) that you will spend: ");  // prompt
                  amount = input.nextDouble();
             } // end inputSL method
        // changeSL() calculates change from amount entered out of $100
         public void changeSL()
              change = 100 - amount; // calculate change
              while(change > 0)
            if ( change - fiveD >= 0 )
                        numFiveD ++;
                       change -= fiveD;
              if ( change - fiveD >= 0 )
                        numFiveD ++;
                       change -= fiveD;
              if ( change - dollar >= 0 )
                        numDollar++;
                       change -= dollar;
              if ( change - quarter >= 0 )
                        numQuarter ++;
                       change -= quarter;
              if ( change - dime >= 0 )
                        numDime ++;
                       change -= dime;
              if ( change - nickel >= 0 )
                       numNickel ++;
                       change -= nickel;
              if ( change - penny >= 0 )
                        numPenny ++;
                       change -= penny;
         } // end changeSL method
        //outputSL() displays original amount, change dollar amount, and change in individual bills and coins
        public void outputSL()
             System.out.printf( "$%.2f dollars will return $%.2f, which is: ",
                                 amount, change );
            System.out.println(); // blank line
             System.out.println(); // blank line
            if ( numTwentyD > 0 )
                 if ( numTwentyD > 1)
                      System.out.println( numTwentyD + " twenty dollar bills" );
                 System.out.println( numTwentyD + " twenty dollar bill" );
            if ( numTenD > 0)
                 if ( numTenD > 1 )
                      System.out.println( numTwentyD + " ten dollar bills" );
                 System.out.println( numTwentyD + " ten dollar bill" );
            if ( numFiveD > 0)
                 if ( numFiveD > 1 )
                      System.out.println( numFiveD + " five dollar bills" );
                 System.out.println( numFiveD + " five dollar bill" );
            if ( numDollar > 0)
                 if ( numDollar > 1 )
                      System.out.println( numDollar + " one dollar bills" );
                 System.out.println( numDollar + " one dollar bill" );
              if ( numQuarter > 0)
                 if ( numQuarter > 1 )
                      System.out.println( numQuarter + " quarters" );
                 System.out.println( numDollar + " quarter" );
              if ( numDime > 0)
                 if ( numDime > 1 )
                      System.out.println( numDime + " dimes" );
                 System.out.println( numDime + " dime" );
              if ( numNickel > 0)
                 if ( numNickel > 1 )
                      System.out.println( numNickel + " nickels" );
                 System.out.println( numNickel + " nickel" );
              if (numPenny > 0)
                 if ( numPenny > 1 )
                      System.out.println( numPenny + " pennies" );
                 System.out.println( numPenny + " penny" );
    }

  • Calling an array from another class

    Ok I have this little program that I created to display values stored in an array. Well, I want my array to automatically be populated with the same values that are in another array that resides in a different class. Here is my code for the class that I want the values to be displayed:
    import javax.swing.*;
    import java.awt.*;
    public class GUIRead extends JFrame
         double[] interest = new double[3];
         MemicCSVReader[] interestObjectArray = new MemicCSVReader[3];
         interestObjectArray[0] = new MemicCSVReader();
         interestObjectArray[1] = new MemicCSVReader();
         interestObjectArray[2] = new MemicCSVReader():
         for(int x = 0; x < 3; x++)
         JPanel display = new JPanel();
         JTextField interestText = new JTextField(10);
         JPanel display2 = new JPanel();
         JTextField interestText2 = new JTextField(10);
         JPanel display3 = new JPanel();
         JTextField interestText3 = new JTextField(10);
         public GUIRead()
              super("Test");
              setSize(160,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              GridLayout config = new GridLayout(3,1);
              FlowLayout config2 = new FlowLayout(FlowLayout.LEFT,10,10);
              Container pane = getContentPane();
              pane.setLayout(config2);
              display.setLayout(config2);
              display.add(interestText);
              interestText.setText(interest[0]);
              interestText.setEditable(false);
              pane.add(display);
              display2.setLayout(config2);
              display2.add(interestText2);
              interestText2.setText(interest[1]);
              interestText2.setEditable(false);
              pane.add(display2);
              display3.setLayout(config2);
              display3.add(interestText3);
              interestText3.setText(interest[2]);
              interestText3.setEditable(false);
              pane.add(display3);
              setContentPane(pane);
         public static void main(String[] args)
              GUIRead run = new GUIRead();
    Here is my code that I want the double[] interest array to pull it's data from:
    public class MemicCSVReader
         double interestArray[];
         MemicCSVReader()
              String[] interestString = {"5.5","5.35","5.75"};
              for(int x = 0; x < 3; x++)
                   interestArray[x] = Double.parseDouble(interestString[x]);
    }

    Ok, thanks for your help. Now I have another problem. I can't get the values to display. Here is my code:
    This is the program that runs the application:
    import javax.swing.*;
    import java.awt.*;
    public class GUIRead extends JFrame
         MemicCSVReader readCSV = new MemicCSVReader();
         double[] interestDouble = readCSV.getInterestArray();
         String[] interest;
         JPanel display = new JPanel();
         JTextField interestText = new JTextField(10);
         JPanel display2 = new JPanel();
         JTextField interestText2 = new JTextField(10);
         JPanel display3 = new JPanel();
         JTextField interestText3 = new JTextField(10);
         public GUIRead()
              super("Test");
              setSize(160,200);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
              GridLayout config = new GridLayout(3,1);
              FlowLayout config2 = new FlowLayout(FlowLayout.LEFT,10,10);
              Container pane = getContentPane();
              pane.setLayout(config2);
              display.setLayout(config2);
              display.add(interestText);
              interestText.setEditable(false);
              pane.add(display);
              display2.setLayout(config2);
              display2.add(interestText2);
              interestText2.setEditable(false);
              pane.add(display2);
              display3.setLayout(config2);
              display3.add(interestText3);
              interestText3.setEditable(false);
              pane.add(display3);
              setContentPane(pane);
         public void actionPerformed()
              for(int x = 0; x < 3; x++)
                   interest[x] = Double.toString(interestDouble[x]);
              interestText.setText(interest[0]);
              interestText2.setText(interest[1]);
              interestText3.setText(interest[2]);
         public static void main(String[] args)
              GUIRead run = new GUIRead();
    This is the file that it pulls the array from:
    public class MemicCSVReader
         private double[] InterestArray = new double[3];
         MemicCSVReader()
              double[] InterestArray = {5.5,5.35,5.75};
         public double[] getInterestArray()
              return InterestArray;
    }

  • If Number = than then display text from another cell

    Hi
    I'd appreciate it if anyone can help me with this please.
    I am putting together a gradebook type spreadsheet. I would like to display the text from another cell if the number entered in another cell is greater than or less than a certain number.
    So - if the number in cell A is equal to or greater than 70 then the text displayed in cell B equals the text contained in cell C
    Hope this makes sense.
    Many thanks in advance.
    regards,

    Hello Lee,
    The Numbers User Guide PDF available from the Numbers Help menu as a download is good reading for beginners. As a reference document, the iWork Formulas and Functions User Guide is also valuable.
    The function you need is called "IF", and the syntax is: IF "logic-expression" is true, then do this, else do this. As a calculation in a cell, that would have the form: =IF("Cell A" is equal to or greater than 70, then display the content of cell C, else display "something else") You need to provide the "something else", which can be a null string, "", if you wish.
    As you will find when you read the guide, the cells all have row and column address components where the column is identified by a letter of the alphabet and the row by a number. So If your data is in A1, your text string in B1 and your expression is in C1, you would write in C1:
    =IF(A1>=70, B1, "")
    Does this help?
    Jerry

  • Recieve value from another method

    hello,
    I have a method like this
    public String loadUser(String x){    //Init in = new Init();    String abc = x;         currentUser = currentUser+abc;         System.out.println("Currentuser "+currentUser);        return currentUser;    }I have another method
    public void prepareSession(Session session) {        //System.out.println("Reached   b value "+user);        super.prepareSession(session);}How can I recieve value of first method loadUser in my second method?
    I do not want to add another parameter to prepareSession method because it is over riding.
    How can I achieve this?
    Thanks

    The problem is:
    public class AppModuleImpl extends ApplicationModuleImpl {
        String user = null;
        String bn;                            //This is empty and has nothing to do with
        String h = null;                           //        |
        String ops = null;                         //        |    
                                                   //         |                   
        public String loadUser(String x){               //   |
        String bn = x;                                   // this. They are two different varaiables.
            System.out.println("Currentuser "+bn);
            return x;
        public void prepareSession(Session session) {
            super.prepareSession(session);
             String tg = loadUser(bn);
            AppModuleImpl appl =  new AppModuleImpl();
             System.out.println("currentUser ??? "+tg);
    }That's why bn at the end is empty
    BTW I didn't notice You put anything into bn
    Message was edited by:
    hellbinder

  • Reaching a variable from another method

    I want to "reach" the String variable 'a' from the method 'aMethod()'.
    What am I doing wrong when writing:
    String newVariable = aMethod().a;
    /Cullum

    You can't reach local variables.
    Kaj

  • Is there an easy way to replace individual elements in one string array from another striing array?

    I have a string array with elements as follows:
       00 00 00 00 00 00 00 00
       00 00 00 00 00 00 00 00
       00 00 00 00 5E 00 00 00
       00 00 50 00 30 00 33 00
       34 00 39 00 00 00 00 00
       00 00 00 00 00 00 00 00
       00 00 00 00 00 00 00 00
    The array I want to use to replace values with is:
    43 4E 31 30 30 33 30 30 31 41
    Where 43 goes in the 3rd row fifth position
    Where 4E goes in the 3rd row seventh position
    Where 31 goes in the 4th row  first position
    Where 30 goes in the 4th row third position
    Where 30 goes in the 4th row fifth position
    Where 33 goes in the 4th row seventh position
    Where 30 goes in the 5th row  first position
    Where 30 goes in the 5th row third position
    Where 31 goes in the 5th row fifth position
    Where 41 goes in the 5th row seventh position
    So the final array looks as follows:
       00 00 00 00 00 00 00 00
       00 00 00 00 00 00 00 00
       00 00 00 00 43 00 4E 00
       31 00 30 00 30 00 33 00
       30 00 30 00 31 00 41 00
       00 00 00 00 00 00 00 00
       00 00 00 00 00 00 00 00
    Is there an easy way to replace an element of a string within an array with another element of a string within a different array?
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    CMM_Add_SCAN_SN_2_PAT_DATA (temp).vi ‏13 KB

    Try this
    Omar
    Message Edited by Omar II on 03-24-2010 03:25 PM
    Omar
    Attachments:
    CMM_Add_SCAN_SN_2_PAT_DATA%20(temp)[1].vi ‏17 KB

  • Problem displaying recordset from another page

    I have a form on a page and when I click submit, the values
    get passed to another page for processing. All looked well until I
    attempted to put the Record Navigation on the page. I was
    displaying two records at a time while designing the page. Now that
    the design is complete, my search resulted in three records. The
    first two display properly however when i click on the NEXT button,
    it is blank. It appears that my values that were passed are not
    being retained.
    Can someone help me out on this?
    thx

    Ok...i kinda of have this figured out but would really like
    someone to explain to me or point me in the right direction
    regarding variables. I recoded everything (Form action to GET and
    change from form variable to url parameter). This works. however,
    is this the proper way of doing it?

  • Returned array from a method don't work properly over my Servlet

    Hi folks,
    I show you my code and then explain ;).
            double particle_sys[] = new double[100*5];
         double particle[];
      try {
             for(i = 0; i < 10; i++)
              particle_sys[i*5] = 1;
              particle_sys[i*5 + 1] = 0;
              particle_sys[i*5 + 2] = 1;
              particle_sys[i*5 + 3] = 0;
              particle_sys[i*5 + 4] = 0;     
         class call = new class();
         particle = call.MyFailingMethod(particle_sys);Now the code for the class which owns the method I call
    public class Jfjni
         static
                 System.loadLibrary("nativelibrary");
         public native void .........
         public double[] MyFailingMethod(double particle_sys[])
               double particle[] = new double[100*5];
               .... A call to a the native library to recibe the new data of particle_sys ....
             for(int i = 0; i < 10; i++)
              particle[i*5] = particle_sys[i*5];
              particle[i*5 + 1] = particle_sys[i*5 + 1];
              particle[i*5 + 2] = particle_sys[i*5 + 2];
              particle[i*5 + 3] = particle_sys[i*5 + 3];
              particle[i*5 + 4] = particle_sys[i*5 + 4];     
              return particle; 
    }A function in the native code changes the "particle_sys" array, but the returning value stills the same as the original passed to the function.
    Because of this, I have tested returning the array, dont works. I have tested also returning a copy of the array in "particle", dont works.
    Over standalone app and applet it runs correctly in all different ways, when I try it over a servlet the values of the array stand the same as before the method call.
    Please suggestions!
    Edited by: bifiado on Jan 15, 2008 10:27 AM
    Edited by: bifiado on Jan 15, 2008 10:28 AM

    I have partially solutioned this mistake but I have collateral ones. Looks like I forgot to put in web.xml the definition of the class I was calling from the principal servlet class. In other words, I have two classes, one is the extension of Httpservlet and the other (the class that make mistakes) is a class I call to do the JNI work.
    Now, I added in web.xml the definition of the JNI class (before I forgot) and looks the mistakes with arrays works, but know the there's a new problem and get an IOexception on the applet that call the servlet. When I coment the JNI calls the exception dissapears and all works ok, but I am not getting any exception report on the tomcat ".out".
    Please suggestions.

  • Calling servlet from another method

    Hi,
    I am writing a program which requires executing another servlet from within
    thie main program. I do not care to return the information from the servlet
    request.
    http://usx500.crn.st.com:7000/TPMCenter_V2/insertAutomationValue.do?reqCode=confirmed
    Thanks for the help.

    The reason I continue posting this question, is because I cannot find a solution.
    I have looked through the link provided, as well as many other solutions on the web,
    none which have been successful. Following are two solutions which I have tried, and
    niether have worked. I still am in need of some help in resolving this. If you would like
    to assist me in this it would be greatly appreciated.
    Dr Clap--
    If you do not have a suggested solution, simply do not reply.
    Solution 1 ---
        try {
            // Construct data
            String data = URLEncoder.encode( "reqCode", "UTF-8") + "=" + URLEncoder.encode( "show", "UTF-8" ) ;
            // Create a socket to the host
            String hostname = "usx500.crn.st.com" ;
            int port = 7000 ;
            InetAddress addr = InetAddress.getByName( hostname );
            Socket socket = new Socket( addr, port );
            // Send header
            String path = "/TPMCenter_V2/insertAutomationValue.do";
            BufferedWriter wr = new BufferedWriter( new OutputStreamWriter( socket.getOutputStream(), "UTF8" ) ) ;
            wr.write( "POST " + path + " HTTP/1.0\r\n" );
            wr.write( "Content-Length: " + data.length() + "\r\n" ) ;
            wr.write( "Content-Type: application/x-www-form-urlencoded\r\n" ) ;
            wr.write("\r\n");
            // Send data
            wr.write(data);
            wr.flush();
            wr.close();
        } catch (Exception e) {
            e.printStackTrace() ;
        }Solution 2 ---
    try{
        URLConnection c = new URL("http://usx500.crn.st.com:7000/TPMCenter_V2/insertAutomationValue.do?reqCode=show").openConnection();
        c.connect();
    }catch(MalformedURLException murle){
        System.out.println(murle);
    }catch(IOException ioe){
        System.out.println(ioe);
    }

Maybe you are looking for

  • How can I fix my page numbering problem?

    I am creating a catalog in InDesign. Master pages were set up so the left and right pages had the page numbers in the lower outside corners. Today I moved some pages around, and as a result the left side pages are now right side, and vice versa. The

  • JTree - Trying to make selection a parent select all children

    I have a jtree with checkboxes and titles. This is my first semester working with java, I started out in cpp so I'm pretty new to GUIs. I found an example of a Jtree with checkboxes on the leaf nodes online and was able to modify it to have checkboxe

  • Exporting from CS4 doesn't work.

    I edited together some footage, exported using Media Encoder as h.264. The progress bar reaches the end and then nothing. The status remains as "Encoding". In my export folder there is a .m4v file that is 2.68 GB, and .aac file that is 172 MB and a .

  • Upgrade Error when starting the DB   ora-00201 control file version

    Hi Experts, While Upgrading R12.1.1 Vision database version from 11.1.0.7 to 11gR2on RHEL 6 64bit Plateform the following patches 've been applied successfully on apps tier According to note ID: 1058763.1 Patch 7303030 , 9062910 , 8919489 - Oracle E-

  • Copy custom package between local IPS repositories

    I seem to be having a problem copying a custom package from one local IPS repository to another. Both repositories are on the same server, but are set with different publisher names. I used the pkgrecv command like so, to copy the package: pkgrecv -s