0

What I need have happen: Take a list of names from a multiline TextArea, put them into an array, modify them a bit, and then print them out in a list.

What I'm having problems with: Actually getting the input from the TextArea and sticking it in an array -- I have the rest down. I read someone's similar question, but the solution for that question isn't working for me; I keep getting a NullPointerException when I reference it, meaning that there's nothing there, and that the input wasn't put into the array.

The coding: The TextArea is called "taClient" and is all activated by a mouse click on a button called "btnProcess"

    private void btnProcessMouseClicked(java.awt.event.MouseEvent evt)
    {
        String[] names = taClient.getText().split("\\n");

        Account[] account = new Account[names.length];


            for(int x = 0; x<names.length; x++)
            {
                account[x].Name = names[x];
            }

      //All the modifications and other code and printout.

    }

As far as I'm aware, this should work, but I don't have much experience with textareas or the String.split() method, so I could just be way off. (Plus, as I said before, this design was based off of someone else's question on here, and they said this answer solved their problem...but not mine.)

Thanks in advance!

C-Love511
  • 358
  • 1
  • 7
  • 24

2 Answers2

0

Did you try to split the string with just one backslash, likes this: .split("\n").

luiscosta
  • 855
  • 1
  • 10
  • 16
  • Yeah, I tried it both ways(since I'm new to the split) and get the same result. – C-Love511 Apr 14 '14 at 08:46
  • 1
    Did you try to print it without your "Account" array? The thing is, even if you have multiple lines if you didn't press enter it won't "split". You should try to get the text to a string first like this: String name = taClient.getText(); Print it and then split if that's the case. – luiscosta Apr 14 '14 at 08:52
0

You are probably on Windows and want to read Split Java String by New Line

Also using Guava's new LineReader(new StringReader(taClient.getText())) can do the trick (http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/io/LineReader.html)

Community
  • 1
  • 1
Radim
  • 4,721
  • 1
  • 22
  • 25