How to avoid NullPointerException---String array created from JTextArea

Hi,
I use the method getText() to put the contents of a JTextArea into a String object. Then I use split("\\s+") on that String object to get a String array. Before the contents of the String array are output, I get a NullPointerException. How do I avoid this exception? My code is below.
//: net/mindview/util/SwingConsole.java
package net.mindview.util;
import javax.swing.*;
public class SwingConsole {
  public static void
  run(final JFrame f, final int width, final int height) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        f.setTitle(f.getClass().getSimpleName());
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(width, height);
        f.setVisible(true);
} ///:~
//: gui/Charts.java
package gui;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import net.mindview.util.SwingConsole;
public class Charts extends JFrame {
    private int[] numbers;
    private JTextArea input = new JTextArea();
    private JScrollPane areaScrollPane = new JScrollPane(input);
    private JButton b1 = new JButton("Submit");
    private JButton b2 = new JButton("Clear");
    public Charts() {
        add(areaScrollPane);
        areaScrollPane.setPreferredSize(new Dimension(250, 250));
        b1.addActionListener(a1);
        b2.addActionListener(a2);
        add(b1);
        add(b2);
    private ActionListener a1 = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String data = input.getText();
            String[] stringArray = data.split("\\s+");
            for (String s:stringArray)
                System.out.print(s + " ");
            int i = 0;
            for (String s:stringArray)
                numbers=Integer.parseInt(s);
i++;
private ActionListener a2 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
input.setText("");
* @param args the command line arguments
public static void main(String[] args) {
// TODO code application logic here
SwingConsole.run(new Charts(), 400, 400);
Edited by: gluedtothecomputer on Feb 1, 2009 7:59 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

don't forget to init your int array:
      String[] stringArray = data.split("\\s+");
      numbers = new int[stringArray.length];

Similar Messages

  • How to use the DLLs which created from c++ in Java?

    And How to use the DLLs which created from JNI in C++?

    Huh?
    Are you asking how to do JNI - you should read the tutorial.
    Are you asking how to load it - then use System.loadLibrary()
    Are you asking what to do with the output from javah - put it in a C file and write some code, compile it into a dll.

  • Urgent, how to insert un Idoc (already created)  from outside of SAP

    Hi to all,
    I would like to know how to insert an Idoc (alresdy created) from outside of a SAP environnement into SAP.
    I know via the code we20 we could insert an Idoc into SAP, does someone have a file PDF to explique how to do it step by step plz?
    or could you reply it in details step by step?
    caz we are doing a project and we know almost nothing about it, but we need the information urgent.
    Tks in advance

    Hi,
    i think you have missed some of the some of the columns having NOT NULL constraint.ex:Who Columns..
    Please check the same in the table..
    Thanks
    Bharat

  • How many view object instances can create from Single Entity ?

    Hi All,
    JDev Ver : 11.1.1.5
    I want to How Many view objects can i create from the single entitiy ?
    Is there any limit ?
    Thanks,
    Gopinath

    No, there is no limit

  • How to import a string array from labview into DIAdem Spreadsheet/table

    How to set up a diadem template so when using labview diadem express, the values are imported into a table.
    I have values such as gain, corner frequency, and pass/fail that exist in arrays generated from collecting information from a 7 electrode EEG system.  I want to create a table/spreadsheet in DIAdem that imports the data when using the LabVIEW DIAdem express function, into a table or spread sheet?
    Any takers?
    -Regards
    eximo
    UofL Bioengineering M.S.
    Neuronetrix
    "I had rather be right than be president" -Henry Clay
    Solved!
    Go to Solution.

    Hi eximo,
    The DIAdem Report express block makes it easy to populate text boxes and 2D graphs in DIAdem from variables (wires) in LabVIEW.  Unfortunately neither 2D tables nor 3D graphs are implemented in the DIAdem Rerpot express block.  So you've got 2 options.
    Option 1:  if you don't have too many strings that you want to display, you can arrange that many text boxes into the shape of a 2D table and use the DIAdem Report express block as it was intended (sending data to it from LabVIEW wires).
    Option 2:  at some point as you continue to add elements to your report, you'll probably end up here.  The DIAdem Report express block was designed to connect LabVIEW wires with simple DIAdem reports.  But there is a hook you can use in the DIAdem Report express block to run a VBScript instead of loading a REPORT template *.TDR file.  With a DIAdem VBScript you can accomplish anything in DIAdem.  In addition to wiring up a VBScript path instead of a REPORT template path, you'll also need to send all the data you want to report on to a TDMS file and have DIAdem read the data from that file, instead of receiving the data directly from the LabVIEW wire at the express block's input terminal.  This is a little more complicated, but it will allow you to do absolutely anything you want to in DIAdem and start that report from LabVIEW.
    I'm attaching an example of Option 2, but I'd be willing to help you adapt it to your data and reporting needs if you'll post or email ([email protected]) your data set and a rough *.TDR file of what you want in REPORT.  It's pretty slow here at the office over Christmas, so I've got time....
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments
    Attachments:
    DIAdem Report File.zip ‏90 KB

  • Store data in a String array getting from access table

    Hai all,
    i an new to java.
    i have a problem regarding database connectivity, in my bean class i have written code to retrieving data from a access table. It is successfully retrieving data as System.out.println(rs.getString(rows)) is working fine but i want to store the data in String array
    My code is like follows
    String[ ] listTitle;
    rs.next();
    for(int i;i<8;i++)
         rows="F"+i;
         System.out.println(rs.getString(rows));
         listTitle=rs.getString(rows);
    when control coming to
    listTitle[i]=rs.getString(rows);
    it is giving some error like :::: No data found.
    how to solve this any one??

    Hi,
    U r trying to get the value two times. To avoid this store the value in variable, then manipulate.
    Try this,
    String[ ] listTitle;
    String temp;  
    rs.next();
    for(int i;i<8;i++)
         rows="F"+i;
        temp = rs.getString(rows);
        System.out.println(temp);
        listTitle =temp;
    Regards,
    Ram.

  • How to avoid the dialogue when converting from context menu

    This is a follow-up to http://forums.adobe.com/message/2016146#443364 which was locked due to a bug.
    i would like to know how i can avoid the 'save as' dialogue when using the context menu to convert a word file to pdf using windows XP/acrobat 8/word 2007.
    so far, it always prompts me for the filename, which is annoying as it does not allow me to batch-convert several files and let the thing run its course.
    the solution provided by Steve in the other thread does not work - even if the plugin from word does not propt for a filename, it still does when triggered from explorer/context menu.
    so back to square one: how to avoid that dialogue when not opening word at all?
    cheers, thanks for any help. michael

    For a permanent change, START>PRINTERS>right click on Adobe PDF printer and select properties>General>Printing Preferences>Adobe PDF Settings. Under the settings tab, uncheck the box related to asking for a name. Pretty sure that is the location, but it may vary with version.

  • How to avoid duplicate data while inserting from sample.dat file to table

    Hi Guys,
    We have issue with duplicate data in flat file while loading data from sample.dat file to table. How to avoid duplicate data in control file.
    Can any one help me on this.
    Thanks in advance!
    Regards,
    LKR

    No, a control file will not remove duplicate data.
    You would be better to use an external table and then remove duplicate data using SQL as you query the data to insert it to your destination table.

  • How to avoid partial files via FTP from XI to an external server?

    Hi all,
    I'm working in an interface where XI sends a big file (greater than 1MB) via FTP to the client. The client needs an empty file to be created once the file has been fully sent from XI, with format <b>.ok</b>, so that their server can trigger their interface to process the file.
    They want this procedure to ensure no partial files are processed.
    Could someone please help me out on how to do this in XI.
    Thank you.
    <b>Juan Carlos</b>

    HI rajendra
    look into this
    file.checkFileModificationInterval=<msecs>
    Use this parameter to define a length of time (default value: 0) for the file/FTP adapter to wait after the file has been read to see if the file length changes. If this is the case, the system repeats the read procedure. This is useful if the files to be imported by the adapter are generated dynamically without being locked on the operating system level (for example, files received from FTP servers). Without this workaround, the file/FTP adapter cannot recognize whether the generation of the file is complete in such applications with operating system functions.
    regadrs
    nisar

  • How to avoid ORA-3113 when selecting from XMLTYPE table

    Hi,
    If I register an XML-schema, Oracle automatically creates a table xxxxxx_tab of XMLTYPE. (I use Oracle 9.2.0.1)
    When I do a DESCRIBE or a SELECT from this table I get the error: 'ORA-03113:
    end-of-file on communication channel' and my connection is dropped.
    I opened a TAR for this and Oracle says: 'It is an internal bug so cannot be viewed in metalink. This is fixed in release 10i.' (do they mean oracle DB rel 10i, or a new version of XDK?)
    I saw an example in Oracle Magazine (Jan
    2003) "Make XML Native and Relative" about Oracle 9i Rel 2 and XML. As you can see in codeListing 7, the author also does a select from such a
    table (CD331_tab): Why doesn't he have any problems?
    Is there a workaround for this bug? What's the purpose of being able to automatically upload XML-data to a registered schema if you can't do a select of the data?
    Thank you!

    It appears that the XML Schema is not entirely valid. Specifically, the definition of element "DeviceCategory" has two definitions of element "Audio" appearing within a <choice> model i.e. something like :
    <element name="DeviceCategory">
    <choice>
    <sequence>
    <element name="Audio">
    </sequence>
    <sequence>
    <element name="Audio">
    </sequence>
    </choice>
    This is disallowed by XML Schema spec per. the Unique Particle Attribution Constraint. The general idea is that a XML Schema describes a determinstic content model i.e. schema processor can always unambiguosly determine the matching declaration when it encounters an element. However that's not the case with the declaration above. On encoutering "Audio", it could match either the first or the second declaration of the element. Hence the error.
    You will have to rework the schema to avoid this constraint. One mechanism could be to define complexType and their restrictions.
    - Ravi

  • How to build a cluster array dynamically from another cluster array?

    I'm working on a problem where I seem to be getting lost in a sea of
    possibilities, none of which strikes me as optimum. Here's what I need to do.
    I've got an input array of clusters (ARR1). Each cluster contains the
    following components: an integer (INT1), a ring variable (RING1), a boolean
    (BOOL1) and a cluster which itself is simply a bunch of ring variables
    (CLUST1) Now, I need to transform that into a set of clusters (CLUST3) each of
    which contains an array of characters (CHARARY2), a copy of the ring variable
    (RING2), a copy of the boolean variable (BOOL2) and a copy of the cluster
    (CLUST2).
    To build the CLUST3, I need to find all elements within ARR1 that have the
    same unique combination of RING1 and BOOL1, and if BOOL1 is True, then RING1
    in addition, build an array of all the INT1 values corresponding to each
    unique combination above converted to character, and then bundle this array
    plus the unique combination of the other variables into a new cluster. In
    general I could have several such clusters.
    So if I had the following array to start with:
    Index INT1 RING1 BOOL1 CLUST1
    0 3 1 F {Values1}
    1 2 1 T {Values2}
    2 4 0 F {Values1}
    3 6 0 F {Values3}
    4 1 2 T {Values2}
    5 4 2 T {Values2}
    6 3 0 T {Values3}
    7 4 2 T {Values3}
    I should end up with the following clusters:
    CHARARY2 RING2 BOOL1 CLUST1
    "3" 1 F Don't care
    "2" 1 T {Values2}
    "4","6" 0 F Don't care
    "1","4" 2 T {Values2}
    "3" 0 T {Values3}
    "4" 2 T {Values3}
    What methods would you suggest for accomplishing this easily and efficiently?
    Alex Rast
    [email protected]
    [email protected]

    Tedious but not conceptually difficult.
    ARR1 goes into a for loop, auto indexed on the FOR loop. The for loop has a
    shift register which will be used to build the output array. Nested within
    the for loop is another for loop, which the shift register array goes into,
    again auto indexed, along with the element that has been auto-indexed from
    ARR1. This for loop has a shift register, initialised with a boolean "true".
    The inner loop compares the current element of ARR1 with the output array
    and if an element in the output array is already present which matches the
    input by your criteria, then the boolean register is set false; otherwise it
    is left alone.
    After the nested FOR loop you have a case fed from the boolean shift
    register; if the boolean is true, the new element is unique and should be
    added to the array. If it is false then a previous element has been found
    making the present one redundant, and the array should be passed through
    without adding the element.
    In the true case, you simply unbundle the original element into its
    components and build the new element, using "build array".
    Notes for if the above is easy for you;
    1) if handling lots of data then pre-initialise the shift register of your
    outer loop with the same number of elements as your input array. Use
    "Replace Array Subset" instead of "Build Array" to insert the current
    element into the pre-allocated memory rather than having to create a new
    array and copy all the current data across, which is what "Build Array" is
    doing. Use "Array Subset" at the end to obtain a new array containing just
    the elements you've used, removing the unused ones at the end.
    2) Again for large datasets- the use of a while loop instead of the inner
    for loop is more efficient since you can halt the while loop as soon as a
    duplicate is found. With the described approach you have to go through the
    whole array even if the first element turns out to be a duplicate- much
    wasted computer time.
    Alex Rast wrote in message
    news:[email protected]...
    > I'm working on a problem where I seem to be getting lost in a sea of
    > possibilities, none of which strikes me as optimum. Here's what I need to
    do.
    >
    > I've got an input array of clusters (ARR1). Each cluster contains the
    > following components: an integer (INT1), a ring variable (RING1), a
    boolean
    > (BOOL1) and a cluster which itself is simply a bunch of ring variables
    > (CLUST1) Now, I need to transform that into a set of clusters (CLUST3)
    each of
    > which contains an array of characters (CHARARY2), a copy of the ring
    variable
    > (RING2), a copy of the boolean variable (BOOL2) and a copy of the cluster
    > (CLUST2).
    >
    > To build the CLUST3, I need to find all elements within ARR1 that have the
    > same unique combination of RING1 and BOOL1, and if BOOL1 is True, then
    RING1
    > in addition, build an array of all the INT1 values corresponding to each
    > unique combination above converted to character, and then bundle this
    array
    > plus the unique combination of the other variables into a new cluster. In
    > general I could have several such clusters.
    >
    > So if I had the following array to start with:
    >
    > Index INT1 RING1 BOOL1 CLUST1
    > ---------------------------------------------------
    > 0 3 1 F {Values1}
    > 1 2 1 T {Values2}
    > 2 4 0 F {Values1}
    > 3 6 0 F {Values3}
    > 4 1 2 T {Values2}
    > 5 4 2 T {Values2}
    > 6 3 0 T {Values3}
    > 7 4 2 T {Values3}
    >
    > I should end up with the following clusters:
    >
    > CHARARY2 RING2 BOOL1 CLUST1
    > -----------------------------------------------------
    > "3" 1 F Don't care
    > "2" 1 T {Values2}
    > "4","6" 0 F Don't care
    > "1","4" 2 T {Values2}
    > "3" 0 T {Values3}
    > "4" 2 T {Values3}
    >
    > What methods would you suggest for accomplishing this easily and
    efficiently?
    >
    > Alex Rast
    > [email protected]
    > [email protected]

  • How to switch DB string storage format from/to UTF-8 to/from ISO 8859-1 ?

    As far as I understand strings in tables are stored by default in an Oracle DB in ISO 8859-1 format.
    How can I switch the storage to UTF-8 format?
    Do I have to change just a parameter (which ?) or do I have to setup/install the whole DB again?
    If just a parameter switching is necessary:
    How can I change already existing strings from one format to another?
    Does it take place automatically or do I have to issue and explicite convert command (which ?).
    Peter

    Please refer to
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch2charset.htm#sthref157
    And
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch11charsetmig.htm#sthref1476
    Sybrand Bakker
    Senior Oracle DBA

  • How to avoid dialog in Open/Create/Replace File? (yes, I set 'no adv.dialog')

    I would like to avoid the dialog box which seems to
    appear whenever I can successfully open a file:
    I tried both 'advisory dialog' FALSE and TRUE for the following, as well as all file modes (open,create,etc):
    path:"C:\labview" file:"test.txt" ERROR 8
    path:nothing file:"C:\labview\test.txt" dialog box!
    path:"C:\labview\test.txt" file:nothing ERROR 8
    path:"C:\labview\test.txt" file:"C:\labview\test.txt"
    ERROR 8
    as well as other less sensical combinations.

    I'm guessing that you put the filename into the 'default filename' input.
    Instead you need to put the path (including filename) into the 'file path'
    input. The 'default filename' input is for when you want to allow the user
    to input the filename but give him a suggestion of what would be
    appropriate.
    "Grover" wrote in message
    news:[email protected]..
    > I am having the same problem when trying to programmatically create a
    > file. I have made sure I have a legitimate file path/name, no other
    > app/vi is denying access, I have 2k, but I am admin plus the folder
    > where I try creating the file has permissions for everyone set to full
    > control. Any ideas??

  • How to fix FO picture files created from interexchange

    Hi,
    I am working on a catalog from a client. There are 645 picture links which were not sent with the job (3GB worth). I did the job in CS4 and saved as .inx so my client could open it in CS3. In CS3, all the picture files are gray boxes marked FO and all the links are missing from the link palette. Is there an easy fix for this?
    Thanks

    Stephanie sent me the problem file last night and I've done a bit of playing.
    It opened after around five minutes (maybe more) in CS3 with the expected missing links and missing fonts warnings and the gray boxes. Many of the gray frames have tags associated with them (FPO - which means "For Position Only" - on page 1) which are separate text frames added to tell whoever is working on the file that these are not the final images. That cleared up one qustion I had.
    More importanly though, there were supposed to be 695 links. I looked in the links panel and all of the links were listed as foo.jpg, with a path of C:\foo.jpg, clearly not correct (I didn't count to see if there were 695). So I took a look at the .inx file as text.
    .inx is basically XML, I think, but not really intended for human parsing. You can, however read it (and if you know what you're doing, which I don't, edit it) in a text editor, and it's pretty easy to recognize things like link paths. The correct paths seemed to be in place, so foo.jpg is clearly garbage and I have no idea where it came from.
    I opened the same .inx in CS4. It opened more quickly, and showed the links as expected, just as Stephanie reported above, so I saved the file as a new .indd and then exportd a new .inx.
    The new .inx was also slow to open in CS3, but this time the links were correctly imported and shown in the links panel, though of course they are still missing. This is the correct and expected behavior. My conclusion from this is that there is something odd about the first .inx file.
    The first difference I noticed is that my file is smaller by about 100,000 bytes (both are over 17 MB). They are too large to do a complete comparison, but there are some differences in the beginnings of the files which I am not able to interpret, some differnces in swatch listings for Pantone spot colors which I would guess are a settings difference in Ink Manager for using LAB values for convrting spot to process.
    I also noticed what appears to be some additional information included in the link listings of the first file which is not present in the second. I don't know how to read the tags or interpret the hex codes included, so I don't kow if this is significant, but I suspect that's the problem.
    In any case, I'd like to know if Stepahnie did a plain Save or a Save AS before doing the initial export. My instinct is that a long series of regular saves left a lot of useless change information in the file that found its way into the .inx. Doing a Save As removes all of that garbage data from previous sessions and reduces the size of the .indd file and makes for cleaner export.
    The bottom line, I think, is that the original .inx is defective, but that it could be regenerated successfully. If you have the time, can you do a Save As on the ID file, then make a new .inx and send that to me to see how it opens in CS3? I'm going to send you the one I made from the .inx you sent last night which appears to be usable, but it doesn't really solve the problem of WHY the first file was bad.
    Peter

  • How to avoid Freight condition gettign copied from F2 to supplemetary OR

    Hello Expertes..
    I am having copy control between the F2 & the supplemetay sales order. ( debit memo request)
    In invoice I am putting freight condtion mannually which I do not want to get copied in the supplemetary order.
    I have changed the pricing type from D to H ( H- redetermine freight condition) but this is allowing condition to get copied.
    Kindly advice ASAP.

    hello JP
    thanks for prompt reply..well about 1 option) client does not want that
    option 2 option)  yes...we are able to delect the condition in supplement order but client does not want to this to be happen by the user.
    option 3) I will check with the client.
    Can we achieve this by changing H from D - item level in the copy control. could you plz expalin how does this H works?
    Thanks & Regards
    RaviRaj0308
    Edited by: RaviRaj0308 on Apr 26, 2011 2:39 PM

Maybe you are looking for

  • Deleting the latest request from info cube.

    Hi All, In our project, we have data from May 2012 to till date. Data is freezed and there is no change of data till May 2014. And there is change in data for current month only ie) June 2014. So i have pulled the full load from May 2012 to May 2014

  • Travel Advance

    Dear All I have a requirement. In SAP Travel Management, the standard setting for travel advance is that the amount is an offset to the receipts. For example lets assume that an employee takes an advance of 5000 before travelling. After travelling, w

  • Handling timeout issues

    I saw in a previous post that it was recommended to use a try/catch block when a timeout is expected to occur. I have 2 issues with that approach: 1) Does now allow accurate timing of how long a certain step takes. 2) If there's a dependency that tha

  • Lightroom 5 Video: any way to import w/out audio or remove audio during export?

    I 'd like to use some lightroom presets on my video files but need to drop the audio. Any way to do this when either importing or exporting? Can't find a way - thanks!

  • FMS2 core dies after a number of connections

    Howdy folks My company developed a flash video chat (adult related) application. We have intensively tested the application without problems on the developer edition of FMS and afterwards we decided to buy a license. We have configured the license on