Advertisement
enissay

Enissay

Sep 26th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. /////////////////
  2. // Main class  //
  3. /////////////////
  4.  
  5. package views;
  6.  
  7. // imports...
  8.  
  9. public class Main extends JFrame {
  10.     // Main class with all variables and methods...
  11.     //..........
  12.     //..........
  13.  
  14.     public Main() {
  15.         initComponents();
  16.         createEvents(); // A method from the other class is called here like this:  Helpers.checkDataLine(line.trim());
  17.                 // Error: Cannot make a static reference to the non-static method checkDataLine(String) from the type Helpers
  18.     }
  19.    
  20.  
  21.     // Getters n Setters
  22.     public JTextArea getTextAreaOuput() {
  23.         return textAreaOuput;
  24.     }
  25.  
  26.     public void setTextAreaOuput(JTextArea textAreaOuput) {
  27.         this.textAreaOuput = textAreaOuput;
  28.     }
  29. }
  30.  
  31. //////////////////
  32. // Helper class //
  33. //////////////////
  34. package views;
  35.  
  36. // imports...
  37.  
  38. public class Helpers {
  39.    
  40.     public void checkDataLine(String line) {
  41.         try {   // it is a URL
  42.  
  43.             URL url = new URL(line);
  44.            
  45.         } catch (MalformedURLException e) { // it's not a URL
  46.            
  47.             // ERROR: Cannot make a static reference to the non-static method getTextAreaOuput() from the type Main
  48.             Main.getTextAreaOuput().append("~~ [" + line + "] ~~ is NO URL ~~\n");
  49.             searchText(line);
  50.            
  51.         }
  52.     }
  53.  
  54.     public void searchText(String line) {
  55.         Document doc;
  56.         StringBuilder rootUrl = new StringBuilder("http://blah/");
  57.        
  58.         try {
  59.             // Download the page
  60.             doc = Jsoup.connect(rootUrl.append(line).toString()).get();
  61.            
  62.             Elements results = doc.select("a.match");
  63.            
  64.             for (Element element : results) {
  65.                 // ERROR: Cannot make a static reference to the non-static method getTextAreaOuput() from the type Main
  66.                 Main.getTextAreaOuput().append(element.text() + "\n");
  67.             }
  68.            
  69.            
  70.         } catch (IOException e) {
  71.             // TODO: handle exception
  72.         }
  73.        
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement