Loading into String array?

I made a method that loads 2 strings from a text file, and adds them into an array, but it won't work, heres the code.
public static void loadFile() {
     for(int i = 0; i < 2; i++) {
          try {
     final Properties testCheck = new Properties();
final FileInputStream fis = new FileInputStream("myfile.txt");
testCheck.load(fis);
fis.close();
toTest[i] = testCheck.getProperty("test","Nothing Found");
} catch (IOException ioexception) {
           System.err.println ("Error reading");
} Thats the method, I make it print out the array, and it shows up Nothing Found, which means it didn't find what the value in the text file? Any help is greatly appreaciated.

Whatever your problem is, you haven't described it completely.
Please excuse any typos in the following; my development environment and my internet are on different machines tonight,and I cannot copy-and-paste this over.
package rc.test;
import java.io.*;
import java.util.*;
public class TestLP
  static String[] toTest = new String[2];
  public static void main (String[] arguments)
  { loadFile();
    for (int i=0; i<toTest.length; i++)
    { System.out.println(toTest);
public static void loadFile()
for (int i=0; i<2; i++)
try
final Properties testCheck = new Properties();
final FileInputStream fis = new FileInputStream("myfile.txt");
testCheck.load(fis);
fis.close();
toTest[i] = testCheck.getProperty("test", "Nothing Found");
catch (IOException ioexception)
{ System.err.println("Error reading");
With the file "myfile.txt" in the directory in which the program is run, and containing the single line "test TESTING", this program prints:
TESTING
TESTING
All of your code is here, reformatted but otherwise intact; I've added what I surmised to be reasonable drivers to show us whether this code works as expected, and it does.
Possibilities:
The array you think you're loading the data into is in a different scope than the one loaded.  You do not give us the declaration of that array, so we cannot tell.
The printout of the information is somehow flawed.  You don't show us how you output it, so we cannot tell.
myfile.txt doesn't contain what you expect, or there is more than one copy.  Perhaps "test" is capitalized, which would give the result you indicate.  So would a file that doesn't actually contain "test" as a key.
Part of the point here is that complete information would cost very little compared to what you've already done, and would allow us to help you better.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • From JTextField into string array

    hello,
    Me and my friend are currently doing a cryptography project for UNI. We are required to read in a word from the JTextField into an array. the problem is the whole word seems to be going into the array as one element. Is there any way to read in each letter in the word into a seperate element of the array??

    Well you can always read the value in the textfield, convert it to a character array and then as you transfer each character to your string array you add a blank string to it, so then it becomes a string.
    Example:
    String sentence = "hello, I am a really loooooooooong string";
    String[] stringArray = new String[sentence.length()];
    char[] charArray = sentence.toCharArray();
    for (int count = 0; count < sentence.length(); count++)
         stringArray[count] = charArray[count] + "";I hope this helps.

  • SET into string array using toArray()

    I have a object java.util.Set collection and I want to convert all the elements
    into a string array but i don't know why it is not working in my JSP page...
    as i am trying to use toArray() method
    i have tried this          
    String[]  arr = collection.toArray();this
    String[]  arr = (String []) collection.toArray();could you please tell me the right way to aplly it...
    thanks in advance....:)

    I am using session listener which map sessions and it stores sessionid which i hope is a string
    when i directly print this set object it shows
    [ED0EF456BD1EE956A069340633C8DB87,UT0EF456BD1EE956A069340633C8DB34,RD0EF456BD1EE956A069340633C8DB98]
    Message was edited by:
    hunterzz

  • Splitting html ul tags and their content into string arrays using regular expression

    <ul data-role="listview" data-filter="true" data-inset="true">
    <li data-role="list-divider"></li><li><a href="#"><h3>
    my title
    </h3><p><strong></strong></p></a></li>
    </ul>
    <ul data-role="listview" data-filter="true" data-inset="true">
    <li data-role="list-divider"></li><li>test.</li>
    </ul>
    I need to be able to slip this html into two arrays hold the entire <ul></ul> tag. Please help.
    Thanks.

    Hi friend.
    This forum is to discuss problems of C# development. Your question is not related to the topic of this forum.
    You'll need to post it in the dedicated Archived Forums N-R  > Regular Expressions
     for better support. Thanks for understanding.
    Best Regards,
    Kristin

  • Flash player 10.3.181.14 broke my site, loading multiple swfs into an array

    I load multiple swfs into an array, I add and remove the objects on the stage, this is for a rotating carousel.
    All the items locations are established in xml. If I only have one item loaded into the array it works fine, if I have more then one it will not a) play the swf, or b) show the swf.
    The swfs themselves contain code that fire events in the main container. Which cause other items to play or load.
    Is anyone else having this issue?

    Hi howet,
    EDIT:
    I've opened a flash bug in their bug system as I found I could reproduce the issue: https://bugs.adobe.com/jira/browse/FP-7071
    There are some workarounds I found on there.
    ORIGINAL MESSAGE:
    I was having a similar issue using a loading component which i've been using for several years with no issues. As with you the issue arose when loading multiple swfs (or even one swf and then a jpg) on 10.3 and above. It works fine on 10.2 and below still.
    I found a workaround whilst I look for a proper answer and that is to delay subsequent loads using a hacky setTimeout.
    For example:
    protected function manageLoaded (p_event : Event) : void {
    setTimeout(loadNext, 1);
    // following line breaks the gotoAndStop of loaded swfs.
    // loadNext();
    I hope this helps you too, let me know.
    Cheers,
    Dan.
    Message was edited by: Dan Wilkinson, 01/06/2011 11:37am BST (GMT + 1)

  • Adding pictures into an Array?

    The following is a BlackJack Program my group and I made. So far, it seems to work and would likely net us a 100% when we hand it in. However, we wish to go that extra mile and add pictures, cards in particular, something that should obviously be in any card game! I've been fiddling around with ImageIcon and Image but I don't have a clue how to implement these or how to get them working correctly. Also, it would be best if the pictures could be loaded into an array, which would allow the program to function basically the same way with little editing.
    //Import various Java utilites critical to program function
    import java.awt.* ;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Random;
    import java.lang.String;
    public class BlackJackExtreme extends JFrame {  
      Random r = new Random();  //Assigning "r" to randomize
      int valueA;  //Numerical Value of player Cards
      int valueB;
      int valueC;
      int valueD;
      int valueE;
      int valueAC;  //Numerical Value of computer Cards
      int valueBC;
      int valueCC;
      int valueDC;
      int valueEC;
      int playerVal;  //Numerical total value of player cards
      int playerVal2;
      int playerValT;
      int compVal;  //Numerical total value of computer cards
      int compVal2;
      int compValT;
      int counter;  //A counter
      String playVal; //String value for Numerical total value of player cards
      String cVal;   //String value for Numerical total value of computer cards
      private JLabel YourCard;   //Initializing a title label
      private JLabel CCard;  //Initializing a title label
      private JLabel Total;   //Initializing a title label
      private JLabel CTotal;  //Initializing a title label
      private JLabel Win;   //Initializing a Win label
      private JLabel Lose;  //Initializing a Lose label
      private JLabel Bust;  //Initializing a Bust label
      private JButton Deal;   //Initializing a button
      private JButton Hit;   //Initializing a button
      private JButton Stand;   //Initializing a button
      private JButton Exit;   //Initializing a button
      private JTextArea TCompVal;     //Initializing textbox for computer values
      private JTextArea TotalVal;
      private JLabel CardOne;  //Initializing a label for player card 1
      private JLabel CardTwo;  //Initializing a label for player card 2
      private JLabel CardThree;  //Initializing a label for player card 3
      private JLabel CardFour;   //Initializing a label for player card 4
      private JLabel CardFive;   //Initializing a label for player card 5
      private JLabel CCardOne;   //Initializing a label for computer card 1
      private JLabel CCardTwo;   //Initializing a label for computer card 1
      private JLabel CCardThree;   //Initializing a label for computer card 1
      private JLabel CCardFour;   //Initializing a label for computer card 1
      private JLabel CCardFive;   //Initializing a label for computer card 1
      private JPanel contentPane;
      public BlackJackExtreme() {
        super();
        initializeComponent();     
        this.setVisible(true);
      private void initializeComponent() {   
        YourCard = new JLabel("These are your cards");
        CCard = new JLabel("These are the computers cards");
        Total = new JLabel("Your total is: ");
        CTotal = new JLabel("Computer total is: ");
        TCompVal = new JTextArea();  //Box for computer values
        TotalVal = new JTextArea();  //Box for player values
        Win = new JLabel("You win!");  //Label for a Win
        Lose = new JLabel("You lose!");  //Label for a Loss
        Bust = new JLabel("You both Bust!");  //Label for a Bust
        Deal = new JButton();  //Button
        Hit = new JButton();  //Button
        Stand = new JButton();  //Button
        Exit = new JButton();  //Button
        CardOne = new JLabel("");  //Label for Player Card 1
        CardTwo  = new JLabel("");  //Label for Player Card 2
        CardThree = new JLabel("");  //Label for Player Card 3
        CardFour = new JLabel("");  //Label for Player Card 4
        CardFive = new JLabel("");  //Label for Player Card 5
        CCardOne = new JLabel("");   //Label for Computer Card 1
        CCardTwo  = new JLabel("");  //Label for Computer Card 2
        CCardThree = new JLabel("");  //Label for Computer Card 3
        CCardFour = new JLabel("");  //Label for Computer Card 4
        CCardFive = new JLabel("");  //Label for Computer Card 5
        contentPane = (JPanel)this.getContentPane();
        //Assigns function and ability to the various buttons
        Deal.setText("Deal");
        Deal.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Deal_actionPerformed(e);
         Stand.setText("Stand");
        Stand.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Stand_actionPerformed(e);
            Exit.setText("Exit");
        Exit.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Exit_actionPerformed(e);
         Hit.setText("Hit");
        Hit.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Hit_actionPerformed(e);
        //Determines the arrangement of the various buttons, labels, and other GUI objects
        contentPane.setLayout(null);
        addComponent(contentPane, YourCard, 15,1,150,50);
        addComponent(contentPane, CCard, 325,1,200,50);
        addComponent(contentPane, Deal, 15,415,100,35);
        addComponent(contentPane, Hit, 125,415,100,35);
        addComponent(contentPane, Stand, 235 ,415,100,35);
        addComponent(contentPane, Exit, 435 ,415,100,35);
        addComponent(contentPane, CardOne, 25,35,50,50);
        addComponent(contentPane, CardTwo, 110,35,50,50);
        addComponent(contentPane, CardThree, 25,120,50,50);
        addComponent(contentPane, CardFour, 110,120,50,50);
        addComponent(contentPane, CardFive, 65,200,50,50);
        addComponent(contentPane, CCardOne, 350,35,50,50);
        addComponent(contentPane, CCardTwo, 450,35,50,50);
        addComponent(contentPane, CCardThree, 350,120,50,50);
        addComponent(contentPane, CCardFour, 450,120,50,50);
        addComponent(contentPane, CCardFive, 400,200,50,50);
        addComponent(contentPane, Win, 300,300,70,50);
        addComponent(contentPane, Lose, 300,300,70,50);
        addComponent(contentPane, Bust, 300,300,100,50);
        addComponent(contentPane, Total, 100,350,150,50);
        addComponent(contentPane, TotalVal, 200,365,25,25);
        addComponent(contentPane, CTotal, 300,365,150,25);
        addComponent(contentPane, TCompVal, 425,365,25,25);
        //Sets the "outcome" labels invisible on program execution
        Win.setVisible(false);
        Lose.setVisible(false);
        Bust.setVisible(false);
        //Determines size of program window
        this.setTitle("BlackJack");
        this.setLocation(new Point(220,185));
        this.setSize(new Dimension(555,500));
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      private void addComponent(Container container, Component c, int x, int y, int width, int height){
        c.setBounds(x,y,width,height);
        container.add(c);
      //The DEAL button
      public void Deal_actionPerformed(ActionEvent e) {
        //Correctly resets the display after first round of use
        Hit.setVisible(true);
        Stand.setVisible(true);
        Win.setVisible(false);
        Lose.setVisible(false);
        Bust.setVisible(false);
        CardThree.setVisible(false);
        CardFour.setVisible(false);
        CardFive.setVisible(false);
        TotalVal.setText("");
        TCompVal.setText("");
        //Card Array - Values assigned to cards
        String[] cardnames = new String[15];
        cardnames[0] = "Error";
        cardnames[1] = "Error";
        cardnames[2] = "Two";
        cardnames[3] = "Three";
        cardnames[4] = "Four";
        cardnames[5] = "Five";
        cardnames[6] = "Six";
        cardnames[7] = "Seven";
        cardnames[8] = "Eight";
        cardnames[9] = "Nine";
        cardnames[10] = "Ten";
        cardnames[11] = "Jack";
        cardnames[12] = "Queen";
        cardnames[13] = "King";
        cardnames[14] = "Ace";
        //Randomize Card Values
        valueA = r.nextInt(13)+2;
        valueB = r.nextInt(13)+2;
        valueAC = r.nextInt(13)+2;
        valueBC = r.nextInt(13)+2;
        //Displays Card
        CardOne.setText(cardnames[valueA]);
        CardTwo.setText(cardnames[valueB]);
        CCardOne.setText(cardnames[valueAC]);
        CCardTwo.setText(cardnames[valueBC]);
        //Value Correction for Player Cards
        if (valueA == 11 || valueA == 12 || valueA == 13) {
          valueA = 10;  }
        if (valueA ==14){
          valueA = 11;    }
        if (valueB == 11 || valueB == 12 || valueB == 13) {
          valueB = 10;    }
        if (valueB ==14){
          valueB = 11;    }
        //Value Correction for Computer Cards
        if (valueAC == 11 || valueAC == 12 || valueAC == 13) {
          valueAC = 10;  }
        if (valueAC ==14){
          valueAC = 11;    }
        if (valueBC == 11 || valueBC == 12 || valueBC == 13) {
          valueBC = 10;    }
        if (valueBC ==14){
          valueBC = 11;    }
        //Computer Hand Value Calculations
        compVal = valueAC + valueBC;
        //Assigns addition cards to computer
        if (compVal <= 15) {
          valueCC = r.nextInt(13)+2;
          CCardThree.setText(cardnames[valueCC]);
          if (valueCC == 11 || valueCC == 12 || valueCC == 13) {
           valueCC = 10;    }
          if (valueCC ==14){
            valueCC = 11;    }
          compVal += valueCC;    }
        //Changes the Integer value of player and computer hands into a String value
        cVal = Integer.toString(compVal);  
        playerVal = valueA + valueB;
        playVal =  Integer.toString(playerVal);
        TotalVal.setText(playVal);
        Deal.setVisible(false);
        CCardOne.setVisible(false);
      //The HIT button
      public void Hit_actionPerformed(ActionEvent e) {
        //A counter that changes the specific function of the HIT button when it is pressed at different times
        counter++;
          if (counter ==3){
          Hit.setVisible(false);
        //Card Array - Values assigned to cards
        String[] cardnames = new String[15];
        cardnames[0] = "Error";
        cardnames[1] = "Error";
        cardnames[2] = "Two";
        cardnames[3] = "Three";
        cardnames[4] = "Four";
        cardnames[5] = "Five";
        cardnames[6] = "Six";
        cardnames[7] = "Seven";
        cardnames[8] = "Eight";
        cardnames[9] = "Nine";
        cardnames[10] = "Ten";
        cardnames[11] = "Jack";
        cardnames[12] = "Queen";
        cardnames[13] = "King";
        cardnames[14] = "Ace";
        //Randomize Card Values
        valueC = r.nextInt(13)+2;
        valueD= r.nextInt(13)+2;
        valueE = r.nextInt(13)+2;
        //Determines which card is being hit, as well as randomizing a value to that location
        if (counter == 1) {
          CardThree.setText(cardnames[valueC]);
          playerVal2 = 0 + (valueC);      
          CardThree.setVisible(true);    }
        if (counter == 2) {
          CardFour.setText(cardnames[valueD]);  
          playerVal2 += (valueD) ; 
          CardFour.setVisible(true);    }
        if (counter == 3) {
          CardFive.setText(cardnames[valueE]);
          playerVal2 += (valueE);
          CardFive.setVisible(true);    }
        //Value corrections for player cards
        if (valueC == 11 || valueC == 12 || valueC == 13) {
          valueC = 10;    }
        if (valueC ==14){
          valueC = 11;    }
        if (valueD == 11 || valueD == 12 || valueD == 13) {
          valueD = 10;    }
        if (valueD ==14){
          valueD = 11;    }
        if (valueE == 11 || valueE == 12 || valueE == 13) {
          valueE = 10;    }
        if (valueE ==14){
          valueE = 11;
        //Changes the Integer value of player and computer hands into a String value
        playerValT = playerVal + playerVal2;
        playVal =  Integer.toString(playerValT);
        TotalVal.setText(playVal);
        //The STAND button
        private void Stand_actionPerformed(ActionEvent e) {
          //Correctly assigns player value if HIT button is never pressed
          if (counter == 0){
            playerValT = playerVal; }    
          //Reveals the unknown computer card
          CCardOne.setVisible(true);
          //Determines the winner and loser
          if (playerValT <= 21 && compVal < playerValT) {
            Win.setVisible(true); }
          else if (playerValT <= 21 && compVal > 21) {
            Win.setVisible(true); }
          else if (playerValT >21 && compVal > 21) {
            Bust.setVisible(true); }
          else if (compVal <= 21 && playerValT < compVal){
            Lose.setVisible(true);}
          else if (compVal <= 21 && playerValT > 21) {
            Lose.setVisible(true); }
          else if (compVal == playerValT){
            Lose.setVisible(true); }
          //Configures program and display for next use
          Deal.setVisible(true);
          Stand.setVisible(false);
          Hit.setVisible(false);
          counter = 0;
          TCompVal.setText(cVal);
        //The EXIT button
          private void Exit_actionPerformed(ActionEvent e) {
            System.exit ( 0 );
      public static void main(String[]args) {   
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);   
        new BlackJackExtreme();
      Instead of having a JLabel with "Ace", "Eight", etc appear, how would one make pictures appear? How does one do this with an array?
    Edited by: Funkdmonkey on Jan 1, 2008 7:45 PM

    I guess an array or perhaps better a hashmap where the image is the value and the card (a great place for an enum!) is the key would work nicely. Oh, and you can find a great public domain set of card images here:
    http://www.eludication.org/playingcards.html
    Finally, your code appears to be suffering from the God-class anti-pattern. You would do well to refactor that beast.
    Edited by: Encephalopathic on Jan 1, 2008 8:09 PM

  • XML into an Array

    I have an XML file that I want to be able to load into an array and then be able to call on potions of the array to fill text boxes etc as needed through the flash movie.  My question is this.  Does the folowing code do it or do I need to load it into the array a different way?    So example, I would query the array for TestTrack 2  and if it exists in the array I want to use all parts of it.  (title, band, and file). Thanks for the help.
    XML CODE
    <?xml version="1.0" encoding="utf-8"?>
    <playlist>
              <track>
                        <title>TestTrack 1</title>
                        <band>Band1</band>
                        <file>test1.mp3</file>
              </track>
              <track>
                        <title>TestTrack 2</title>
                        <band>Band2</band>
                        <file>test2.mp3</file>
              </track>
              <track>
                        <title>TestTrack 3</title>
                        <band>Band3</band>
                        <file>test3.mp3</file>
              </track>
              <track>
                        <title>TestTrack 4</title>
                        <band>Band4</band>
                        <file>test4.mp3</file>
              </track>
    </playlist>
    AS3 CODE:
    var playlistArray:Array = new Array();
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, showXML);
    xmlLoader.load(new URLRequest("playlistAS3.xml"));
    function showXML(e:Event):void
              XML.ignoreWhitespace = true;
              var songs:XML = new XML(e.target.data);
              trace(songs.track.length());
              var i:Number;
              for (i=0; i < songs.track.length(); i++)
                        playlistArray[i]= songs.children()[i];
                        /*trace(" Name of the song: "+ songs.track[i].title.text());
                        trace(" Name of the Band: "+ songs.track[i].band.text());
                        trace(" File Location of the song: "+ songs.track[i].file.text());*/
              trace(playlistArray[0]);

    While Ned's answer is spot on, there's no need for an array - it actually makes it more work than necessary.
    AS3 has the XMLList object made just for this.
    In your showXML function you have:
      var songs:XML = new XML(e.target.data);
    After that you can just make an XMLList object with all the tracks:
    var tracks:XMLList = songs.track;
    trace(tracks.length()); //4
    To get the third title:
    trace(tracks[2].title);

  • Loading a map + variables "drawn" in a txt file into an array

    hey guys, somewhat new to java, i have an assignment for school that requires me to create an "AI" that can solve a maze, easy enough. I used a 2 dimensional array for the maze, where 1 = wall, 0 = path, 3 = visited. etc, as far as the navigating goes, it's all done. The problem: i need to be able to load a maze from a file, the file looks like this:
    7 20 <-- rows/columns
    0 10 <------ start
    6 5 <---- finish
    xxxxxxxxxx  xxxxxxxxxx
    x        x            xxx      x
    x   xxxxxx      xxx     xxx
    x  xxxxxxx  xxxx  xxxxxx
    x  x            xx           xxx
    x xx     xxxxxxx  xx       x
    xxxxxoxxxxxxxxxxxxxxxSo basically i need to store the first numbers in variables so i know what size array to create and where to start solving the maze and then i somehow need to figure out a way to transofrm that drawing into an array. Was looking into parsing the text and trying to use tokens to separate it, but i honestly can't figure out how. If someone can drop a few hints or some functions i can use, i'd much appreciate it!

    Read the Java Doc API for
    FileReader
    BufferedReader
    String.split
    String.toCharArray

  • The file just won't load into array...Please Help!

    hi i need some help in loading a binary file into an array so that i can edit the data that was saved from previous run..
    i could save the file but after that when i try to load it back to memory...i can't...ie. all the information keyed in were lost...please help
    this is the Code for the loading process...
         public static void loadAircraft (ArrayList aircraft) {
              try {
                   FileInputStream filein = new FileInputStream(".\\Data\\Aircraft.bin");
                   ObjectInputStream objectin = new ObjectInputStream(filein);
                   Aircraft craft = (Aircraft) objectin.readObject();
                   aircraft.add(craft);
                   objectin.close();
                   filein.close();
              catch (Exception e) {}
         }the above code won't load anything into memory...is there a way for overcoming this?
    inside the Aircraft class there are four different data of which they contain two differen data types.
    one of which is String and the other three are in int.
    Awaiting for reply...thanks

    yes...its some objects of an array that i am trying to load back...
    erm...i'll show you the whole code maybe...
    //to reference the swing library
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class SetupAircraft {
         static ArrayList aircraft;
         public static void init () {
              aircraft = new ArrayList(5);
              loadAircraft(aircraft);
         //opens up another sub group while the user
         //entered 1 as his/her option in the SetupSystem
         //menu
         public static void Setup () {
              //this will create a string that is going to be displayed
              //in the input dialog box
              String menu = "  Please select an option:  \n"
                              +"----------------------------\n"
                              +"1) Add New Aircraft\n"
                              +"2) Edit Existing Aircraft\n"
                              +"3) List Aircraft\n"
                              +"4) Delete Existing Aircraft\n"
                              +"5) Save\n"
                              +"6) Return to Main Menu\n\n"
                              +"   Enter a number between 1-6\n";
              //declare a field named option for selection through menu
              int option = 0;
              //continue the loop until the user inputs the number 6
              do {
                   //error handling for the input from the menu
                   //if the input is not integer the error is caught and
                   //reassigning option to be 0
                   try {
                        option = Integer.parseInt(JOptionPane.showInputDialog(null, menu,
                                   "Setup Aircraft", JOptionPane.QUESTION_MESSAGE));
                   catch (NumberFormatException e) {
                        option = 0;
                   //determine which option the user has chosen
                   //and enters the respective section
                   switch (option) {
                        case 1: add(aircraft);
                                  break;
                        case 2: edit(aircraft);
                                  break;
                        case 3: list(aircraft);
                                  break;
                        case 4: //delete(aircraft);
                                  break;
                        case 5: save(aircraft);
                                  break;
                        case 6:     return;
                        default: JOptionPane.showMessageDialog(null, "Please enter a number between 1-6",
                                   "Alert", JOptionPane.ERROR_MESSAGE);
                                   option = 0;
              while (true);
         public static void add (ArrayList aircraft) {
              String type = "";
              int first = 0;
              int business = 0;
              int economy = 0;
              do {
                   try {
                        type = JOptionPane.showInputDialog(null,"Enter Aircraft Type", "Prompt for Type",
                        JOptionPane.QUESTION_MESSAGE);
                        try {
                             if(aircraft.contains(type)) {
                                  JOptionPane.showMessageDialog(null, type + " already exist!",
                                  "Error", JOptionPane.ERROR_MESSAGE);
                                  type = "-100";
                        catch (Exception e) {}
                        if (type=="-100");
                        else if (type.length()==0) {
                             JOptionPane.showMessageDialog(null, "Please enter an aircraft type",
                             "Error", JOptionPane.ERROR_MESSAGE);
                        else if (!(type.startsWith("-",3))) {
                             JOptionPane.showMessageDialog(null, "Please enter the aircraft type with XXX-XXX format where X is integer.",
                             "Error", JOptionPane.ERROR_MESSAGE);
                             type = "0";
                   //catch the input error that the user has produces.
                   catch (Exception e) {
                        return;
              while (!(type.startsWith("-",3)));
              //try to ask the user for the passenger's name and if the name field contains
              //no characters at all repeat the prompt for name field until the user presses
              //Cancel.
              try {
                   first = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter First Class Capacity",
                   "Prompt for Capacity", JOptionPane.QUESTION_MESSAGE));
              catch (Exception e) {
                   String error = "For input string:";
                   if (e.getMessage() == "null") {
                        return;
                   else if (e.getMessage().startsWith(error)) {
                        JOptionPane.showMessageDialog(null, "Please enter only numbers",
                        "Error", JOptionPane.ERROR_MESSAGE);
              try {
                   business = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Business Class Capacity",
                   "Prompt for Capacity", JOptionPane.QUESTION_MESSAGE));
              catch (Exception e) {
                   String error = "For input string:";
                   if (e.getMessage() == "null") {
                        return;
                   else if (e.getMessage().startsWith(error)) {
                        JOptionPane.showMessageDialog(null, "Please enter only numbers",
                        "Error", JOptionPane.ERROR_MESSAGE);
              try {
                   economy = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Economy Class Capacity",
                   "Prompt for Capacity", JOptionPane.QUESTION_MESSAGE));
              catch (Exception e) {
                   String error = "For input string:";
                   if (e.getMessage() == "null") {
                        return;
                   else if (e.getMessage().startsWith(error)) {
                        JOptionPane.showMessageDialog(null, "Please enter only numbers",
                        "Error", JOptionPane.ERROR_MESSAGE);
              Aircraft newAircraft = new Aircraft (type, first, business, economy);
              aircraft.add(newAircraft);
              JOptionPane.showMessageDialog(null, "Aircraft Sucessfully Added",
              "Successful", JOptionPane.INFORMATION_MESSAGE);
         public static void edit (ArrayList aircraft) {
              String type = "";
              int first = 0;
              int business = 0;
              int economy = 0;
              do {
                   try {
                        type = JOptionPane.showInputDialog(null, "Enter Aircraft Type to Edit",
                        "Prompt for Type", JOptionPane.QUESTION_MESSAGE);
                        if (type.length()==0) {
                             JOptionPane.showMessageDialog(null,"Please enter an aircraft type",
                             "Error",JOptionPane.ERROR_MESSAGE);
                        else if (!(type.startsWith("-",3))) {
                             JOptionPane.showMessageDialog(null, "Please enter the aircraft type with XXX-XXX format where X is integer.",
                             "Error", JOptionPane.ERROR_MESSAGE);
                             type = "0";
                   catch (Exception e) {
                        return;
              while (!(type.startsWith("-",3)));
              try {
                   int edited = aircraft.indexOf(new UniqueAircraft(type));
                   Aircraft craft = (Aircraft)aircraft.get(edited);
                   try {
                        first = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter First Class Capacity",
                        "Prompt for Capacity", JOptionPane.QUESTION_MESSAGE));
                   catch (Exception e) {
                        String error = "For input string:";
                        if (e.getMessage() == "null") {
                             return;
                        else if (e.getMessage().startsWith(error)) {
                             JOptionPane.showMessageDialog(null, "Please enter only numbers",
                             "Error", JOptionPane.ERROR_MESSAGE);
                   try {
                        business = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Business Class Capacity",
                        "Prompt for Capacity", JOptionPane.QUESTION_MESSAGE));
                   catch (Exception e) {
                        String error = "For input string:";
                        if (e.getMessage() == "null") {
                             return;
                        else if (e.getMessage().startsWith(error)) {
                             JOptionPane.showMessageDialog(null, "Please enter only numbers",
                             "Error", JOptionPane.ERROR_MESSAGE);
                   try {
                        economy = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Economy Class Capacity",
                        "Prompt for Capacity", JOptionPane.QUESTION_MESSAGE));
                   catch (Exception e) {
                        String error = "For input string:";
                        if (e.getMessage() == "null") {
                             return;
                        else if (e.getMessage().startsWith(error)) {
                             JOptionPane.showMessageDialog(null, "Please enter only numbers",
                             "Error", JOptionPane.ERROR_MESSAGE);
                   Aircraft newAircraft = new Aircraft (type, first, business, economy);
                   aircraft.add(newAircraft);
                   aircraft.add(newAircraft);
                   JOptionPane.showMessageDialog(null, "Successfully edited aircraft\n"+type+" to capacities\n"
                   +"First: "+first+"\n"+"Business: "+business+"\n"+"Economy: "+economy,
                   "Successful", JOptionPane.INFORMATION_MESSAGE);
              catch (Exception e) {
                   JOptionPane.showMessageDialog(null,e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
         public static void list (ArrayList aircraft) {
              JOptionPane.showMessageDialog(null, aircraft.size()+" aircraft found", "Found",JOptionPane.INFORMATION_MESSAGE);
              Object[] aircrafts;
              aircrafts = aircraft.toArray();
              for (int i=0;i<aircraft.size();i++) {
                   Aircraft a = (Aircraft) aircrafts;
                   JOptionPane.showMessageDialog(null, a, "Aircrafts" + (i+1), JOptionPane.INFORMATION_MESSAGE);
         public static void save (ArrayList aircraft) {
              try {
                   FileOutputStream fileout = new FileOutputStream(".\\Data\\Aircraft.bin");
                   ObjectOutputStream objectout = new ObjectOutputStream(fileout);
                   Object[] aircrafts;
                   aircrafts = aircraft.toArray();
                   objectout.writeObject(aircrafts);
                   objectout.close();
                   fileout.close();
                   JOptionPane.showMessageDialog(null,aircraft.size()+" aircrafts saved", "Sucessful", JOptionPane.INFORMATION_MESSAGE);
              catch (IOException e) {
                   JOptionPane.showMessageDialog(null,e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
         public static void loadAircraft (ArrayList aircraft) {
              try {
                   FileInputStream filein = new FileInputStream(".\\Data\\Aircraft.bin");
                   ObjectInputStream objectin = new ObjectInputStream(filein);
                   Aircraft craft = null;
                   while ((craft=(Aircraft)objectin.readObject())!=null) {
                        aircraft.add(craft);
                   objectin.close();
                   filein.close();
              catch (Exception e) {
                   JOptionPane.showMessageDialog(null,e.toString());
                   e.printStackTrace();
    i think thats a bit too long..but it would explain what i am trying to save...its linking to the class Aircraft tho...
    thanks...i appreciate your help...

  • How to add elements into java string array?

    I open a file and want to put the contents in a string array. I tried as below.
    String[] names;
    s = new Scanner(new BufferedReader(new FileReader("outfile.txt")));
    while (s.hasNext()) {
                    String item = s.next();
                    item.trim();
                    email = item;
                    names = email;
                }But I know that this is a wrong way of adding elements into my string array names []. How do I do it? Thanks.

    Actually you cannot increase the size of a String array. But you can create a temp array with the lengt = lengthofarray+1 and use arraycopy method to copy all elements to new array, then you can assign the value of string at the end of the temp array
    I would use this one:
    String [] sArray = null;
    s = new Scanner(new BufferedReader(new FileReader("outfile.txt")));
    while (s.hasNext()) {
        String item = s.next();
        item.trim();
        email = item;
        sArray = addToStringArray(sArray, email);
    * Method for increasing the size of a String Array with the given string.
    * Given string will be added at the end of the String array.
    * @param sArray String array to be increased. If null, an array will be returned with one element: String s
    * @param s String to be added to the end of the array. If null, sArray will be returned.(No change)
    * @return sArray increased with String s
    public String[] addToStringArray (String[] sArray, String s){
         if (sArray == null){
              if (s!= null){
                   String[] temp = {s};
                   return temp;
              }else{
                   return null;
         }else{
              if (s!= null){
                   String[] temp = new String[sArray.length+1];
                   System.arraycopy(sArray,0,temp,0,sArray.length);
                   temp[temp.length-1] = s;
                   return temp;
              }else{
                   return sArray;
    }Edited by: mimdalli on May 4, 2009 8:22 AM
    Edited by: mimdalli on May 4, 2009 8:26 AM
    Edited by: mimdalli on May 4, 2009 8:27 AM

  • String array into formula node

    Hello,
    I am taking data from SQL, I am getting multiple rows of data for many different devices. I would like to wire the data into a formula node so I can sepearate and sort via script. However, I am getting an error for "Polymorphic terminal cannot accept this data type". Is there a work around? Can I not wire in a string array to a formula node.
    /r
    Travo

    There are lots of basic string VIs that you can use to parse the string and separate out the individual fields. I would recommend "programming" your application using script nodes. Use the native language. LabVIEW is a fully functional and capable programming language.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Help! Inserting a 1-D comment array into a 2-D string array at specified row AND column

    Hello everyone,
    I am writing a 2-D string array to excel and i need a way to add comments to my file like this:  
    SLAM    NAME    G Level    Comments
    1              RALF         26               
    1              RALF         26
    1              RALF         26
    1              RALF         26
    For some reason, i cannot specify a row AND column to write because: 
    When i use replace array subset it only replaces 1 element at my index. 
    When i use replace array subset with a loop, it creates empty spaces until it reaches the end of the array it is replacing.
    When i use Insert into array: i cannot wire 2 inputs for row and column.  
    In my complete VI i will need to write from row 1-1001, a different comment from 2-2002, a different comment from 3-3003, etc until a stop condition is met so i need to figure out how to do this programatically and not have it replace any elements outside of the range or it will override previous commetns. 
    I am at a loss of what to do. Any and all suggestions are greatly appreciated. 
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    array.vi ‏13 KB

    Hi proph,
    I made a small subtile change to yur VI and now it replaces all values of the 4th column…
    THINK DATAFLOW!
    Use shift registers when you need to propagate values from one loop iteration to the next!
    USE/LEARN DEBUGGING TECHNIQUES!
    There are tools like probes and highlight to understand your VI execution and to find problems…
    Go through all those free online courses offered by NI!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    array.vit ‏12 KB

  • Combining string array elements into one string

    Right, I have an string array called str which stores 1 character in each of its 16 elements. It gets this character from another array, strArray. Now, what I want to be able to do is to take all 16 elements and combine them into one string called keyString. Using the code below keyString only prints out the last character. The code is shown below:
    for (x=0; x<16; x++) {
         str = new String[16];
         str[x] = "";
         str[x] += (strArray[(index+x)%16].charAt(strChar[x]));
         keyString = str[x];
           System.out.print(keyString);
    }Any help would be very much appreciated.
    Edited by: Paragon96 on May 20, 2008 7:32 AM

    your logic is wrong ; if you want to concatenate the content of the array, you have to loop (what you did), and concatenate keyString for each index, meaning:
    keyString += str[x];you can also use a StringBuilder for such kind of operations

  • Load CF varibales into javascript array without outputing to source code

    I have a javascript array for dynamic dropdowns - Automobile, makes,models, etc.
    The javascript arrays are populated by by cf queries
    Everythign works and functions fine - but it also loads the entire array (hundreds of lines of code) into the browser source code.
    I would like to have the javascript arrays hidden from the browser source code by calling it:
    <script language="JavaScript" type='text/javascript' src='../js/super.js'></script>
    But when I code like this, the js file 'super.js' does not run the cf variables.
    The only way I can get it to function right now is to save a cf file called 'super.cfm' and have it run the cf query, then list the javascript code under the query on this cf template.
    THis works - but again, it causes the entire javascript code to be visible to the browser source code...
    any ideas? - I am on cf 7
    thanks in advance

    thanks for your idea
    I ended up rethinking the whole process and realized that I only update my vehicle make/model list about once a week
    So what I ended up doing was creating the the dynamic javascript arrays through cf - and rendered them in a browser, then took the browser source code (the fully rendered javascript arrays) and saved them as a static js file
    My website uses this js file on every page, so I no longer need to call queries on every single page to populate the javascript arrays - they are already built and I am guessing cached by the browser  (browsers cache js files right?)
    SO this runs more efficiently.
    The only draw back is that when I add a new vehicle to the list in my database, I will need to manually do the same process of rendering the new js code, then cutting and pasting it into my static js file that gets called by all pages.
    So it loses the realtime updates - but this only happened once a week anyway - and it only takes me five minutes to create the new file.
    We'll see if I get sick of manually creating a new js file each week - probably, but this seems better than making the server re-render the code on each page.
    Does this make sense? - would this be less overhead on the server than implimenting your concept?
    thanks.

  • Converting a string of numbers into an array of booleans

    For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

    billko wrote:
    Hooovahh wrote:
    billko wrote:
    Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
    I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
    LOL maybe that was one of the objectives of the homework. 
    To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
    It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

Maybe you are looking for