Results 1 to 7 of 7
  1. #1
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Arrow string array returning null pointer.. any hints?

    i found a work aroun but this for fun

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package nathansstring;
    
    /**
     *
     * @author Natdizzle
     */
    public class NathansString {
    String one[], tso[];
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
            new NathansString();
        }
        public NathansString(){
            one[0] = "string";
            tso[0] = one[0];
            System.out.println(tso[0]);//]
            //two[0]
        }
    }

  2. #2
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Default Re: string array returning null pointer.. any hints?

    got it working with an arraylist

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package syntaxhighlighter;
    
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.LineNumberReader;
    import java.util.ArrayList;
    
    /**
     *
     * @author Natdizzle
     */
    public class SyntaxHighlighter {
        BufferedReader reader;
    String line = null;
    String line2[];
    String line3[];
    Integer Count;
    LineNumberReader lnr;
    Integer number;
    ArrayList<String> stringsNathans;
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            new SyntaxHighlighter();
        }
        public SyntaxHighlighter(){
            Count = new Integer(0);
            number = new Integer(0);
            stringsNathans = new ArrayList<String>();
        try {
        reader = new BufferedReader(new FileReader("javaCode.txt"));
        lnr =new LineNumberReader(new FileReader("javaCode.txt"));
        //BufferedReader(//(LineNumberReader) reader;
        lnr.skip(Long.MAX_VALUE);
        //System.out.println(lnr.getLineNumber());
        //reader.s
    }
        catch (Exception e){
        System.out.println(e);
    }   
        //*
        /*8
        try{
        while (true){//reader.readLine() != null){
            reader.readLine();
            Count++;
        }
        }
        catch (Exception e){
            
        }
        * */
        for (int j = 0; j < lnr.getLineNumber(); j++){ 
            //(true){
        //}
        try{
        line = reader.readLine();
        }catch(Exception e){
        
    }
        //System.out.println(lnr.getLineNumber());
        line2 = line.split(" ");
        //System.out.println(line3);
        //.out.println(line2.length);
        for (int k = 0; k < line2.length; k++){
            //System.out.println(number);
            //System.out.println();
            //System.out.println();
            //line3[number] = line2[k];
            stringsNathans.add(line2[k]);
            number++;
        }
        //for (int l = 0; l < line3.length; l++){
           // System.out.println(line3[l]);// /
       // }
        //line.
    
        }   
        for(int i = 0; i < stringsNathans.size(); i++){
        System.out.println(stringsNathans.get(i));
        }
    }
    
        /*
        try{
    while ((line = reader.readLine()) != null) {
        // ...
        System.out.println(line);
            }
        }
        catch(Exception e){
            
        }
        }
        *//*88 88*//**\/*/
        }
    //}
    //}

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: string array returning null pointer.. any hints?

    I don't see anything remotely advanced here so I've moved the thread out of Advanced Java.

    Did you have a question, or should this belong in the Reviews section?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Default Re: string array returning null pointer.. any hints?

    wanted to see if anyone knew why null pointer was coming up

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: string array returning null pointer.. any hints?

    I don't see anywhere you initialized the arrays. And if you had taken the trouble to remove the inane IDE generated comments, the forum formatting bug wouldn't have messed up your code. We really don't need to read
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Default Re: string array returning null pointer.. any hints?

    most of the time im doing integer arrays cause i do a lot of 2d game programming

  7. #7
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Default Re: string array returning null pointer.. any hints?

    interger arrays must be initialized

Similar Threads

  1. Multidimentional array-null pointer
    By applewood13 in forum Java Applets
    Replies: 11
    Last Post: 04-30-2011, 07:15 AM
  2. Null Pointer Exception in an Array of JCheckBoxes
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 04-02-2011, 05:50 PM
  3. null pointer exception in string comparison
    By Saran185 in forum New To Java
    Replies: 7
    Last Post: 03-28-2011, 07:00 AM
  4. Replies: 1
    Last Post: 02-07-2011, 09:22 PM
  5. String returning null value
    By impact in forum New To Java
    Replies: 7
    Last Post: 08-03-2008, 08:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •