Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: "Error cannot find symbol" "throws BadLocationException"

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default "Error cannot find symbol" "throws BadLocationException"

    I am getting the error that it is the thread title when running this code:

    void printLines (JTextArea ta) {  
            String temp = content.get(0);    
            String [] splitter = temp.replaceAll("[.,?!:;/]", "").split(" ");  
            ta.append ("O conteudo do arquivo e: ");  
            for (int k=0; k<splitter.length; k++) {   
              if (splitter[k].equals ("bonita")) {  
                //ta.append("B*O*N*I*T*A");  
                Highlighter hilit = new DefaultHighlighter();  
                Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);  
                hilit.addHighlight(0, 5, painter);  
              }    
              ta.append (splitter[k] + " ");  
            }  
            ta.append ("\n");   
          }


    The error began to show up when I added this three lines related to the Highlighter. I think it might be related to the index that I am passing to addHighlight but I am not sure.

    I made I self-contained version of the error here:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Main {
      public static void main (String [] args) throws Exception {
        JFrame jframe = new JFrame ();
        JTextArea ta = new JTextArea(20,40); 
        JScrollPane sp = new JScrollPane (ta);
        jframe.setVisible (true);  
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        jframe.setLayout(new FlowLayout()); 
        jframe.add(sp);  
        jframe.pack(); 
        String temp = "Test1 Test2 bonita Test3";    
        String [] splitter = temp.replaceAll("[.,?!:;/]", "").split(" ");  
        ta.append ("O conteudo do arquivo e: ");  
        for (int k=0; k<splitter.length; k++) {   
          if (splitter[k].equals ("bonita")) {  
            //ta.append("B*O*N*I*T*A");  
            Highlighter hilit = new DefaultHighlighter();  
            Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);  
            hilit.addHighlight(0, 5, painter);  
          }    
          ta.append (splitter[k] + " ");  
        }  
        ta.append ("\n");   
      }   
    }

    But with this code I don't get the same error.....what I am getting now it is a nullPointerException in line 24 the
    hilit.addHighlight(0, 5, painter);
    one
    The frame is created shows the two first words before generating the error.

    Anyone has an idea about what can be?

    I also would appreciate if someone can provide me a few tips, links or whatever about how I can advance in text using the keyboard. In another words, if I press right it advances until a certain occurrence of a certain word, then if I press again, it advances to the next one until I reach the last occurrence of a word.


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: "Error cannot find symbol" "throws BadLocationException"

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/79716-error-cannot-find-symbol-throws-badlocationexception.html
    http://www.coderanch.com/t/614805/GUI/java/Error-find-symbol-throws-BadLocationException

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  3. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    jps (July 1st, 2013)

Similar Threads

  1. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  2. "cannot find symbol" error when trying to use the getInt() method.
    By simpson_121919 in forum Collections and Generics
    Replies: 6
    Last Post: February 21st, 2013, 12:48 PM
  3. Replies: 3
    Last Post: January 22nd, 2013, 07:14 AM
  4. ERROR - "CANNOT FIND SYMBOL"
    By abinaya.cs in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 18th, 2013, 07:07 AM
  5. "Cannot find symbol" compilation error
    By collegejavastudent in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 12th, 2011, 05:07 PM