2012-04-22 6 views
0

Web Crowler用のJavaファイルが1つあります。それは、行と複数の行番号で複数のマーカーのようなエラーを私に与える。eclipseで複数のマーカーエラーが発生する

私はちょうどパターンとマッチャーを学びました。だから私はエラーを修正することができません。

私のコードは、それが

 Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
Syntax error on token "?", new expected 
Syntax error on token ">", Type expected after this token 
Syntax error on token "Invalid Character", invalid AssignmentOperator 
Syntax error on token "Invalid Character", delete this token 
Syntax error on tokens, Expression expected instead 

at initComponents.actionPerformed(initComponents.java:115) 
at java.awt.Button.processActionEvent(Unknown Source) 
at java.awt.Button.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
at java.awt.EventQueue.access$000(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 

私を助けてくださいのようなエラーが発生します}

class MyWindowAdapter1 extends WindowAdapter{ 
initComponents mf; 
public MyWindowAdapter1(initComponents mf){ 
this.mf=mf; 
} 

public void windowClosing(WindowEvent we) 
    { 
     System.exit(0); 
} 
} 

}

import java.awt.*; 
import java.awt.event.*; 
import java.io.BufferedReader; 
import java.awt.*; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.URL; 
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 
import java.util.regex.PatternSyntaxException; 


class initComponents extends Frame implements ActionListener { 

     // TextField addt ,factorialt,concatt1,concatt2,lengtht,palindromet,comparet1,comparet2,substringt1,substringt2; 
    //Button add1,factorial1,concat1,length1,palindrome1,compare1,substring1; 
String s1=""; 
//String s3=""; 
//String s4=""; 
//String s2=""; 
Button Search,Clear; 
TextField text1; 
TextArea text2; 
Label lab,lab1,lab2; 

public initComponents() 
{ 
     MyWindowAdapter1 m=new MyWindowAdapter1(this); 
     addWindowListener(m); 

     setTitle("Web Crawler"); 
     setLayout(null); 
     setSize(1000,1000); 
     setVisible(true); 

     setBackground(Color.LIGHT_GRAY); 

     lab=new Label("Name: "); 
     text1=new TextField(20); 
     //text2=new TextArea(80,80); 
     text2=new TextArea(); 

     //lab1=new Label("Count"); 
     //lab2=new Label(); 

     Search=new Button("Search"); 
     Clear=new Button("Clear"); 

     lab.setBounds(50,50,80,20); 
     //lab1.setBounds(500,50,80,20); 
     //lab2.setBounds(590,50,250,20); 

     text1.setBounds(140,50,250,20); 
     Search.setBounds(50,100,80,20); 
     Clear.setBounds(150,100,80,20); 
     text2.setBounds(50, 200, 700, 500); 
     //text2.setBounds(200,100,80,20); 

     add(lab); 
     add(text1); 
     //add(lab1); 
     //add(lab2); 
     add(Search); 
     add(Clear); 
     add(text2); 


     setVisible(true); 
     setSize(800,800); 

     Search.addActionListener(this); 
     Clear.addActionListener(this); 



} 


public void actionPerformed(ActionEvent a) 
    { 
// TODO Auto-generated method stub 



if(a.getSource().equals(Clear)) 
{ 
    text1.setText(""); 
    text2.setText(""); 
    //text2.append(""); 
} 

    if(a.getSource().equals(Search)) 
    { 
     s1=text1.getText(); 

     text2.setText(""); 
     //text2.append(); 
     //web_crawler c=new web_crawler(); 

     //c.crawling(s1); 


     try{ 
      InputStreamReader in = new InputStreamReader(new URL(s1).openStream()); 
      StringBuilder input = new StringBuilder(); 

      int ch; 

      while ((ch = in.read()) != -1) 
       input.append((char) ch); 

      String patternString = "<a\\s+href\\s*=\\s*(\"[^\"]*\"|[^\\s>])\\s*>"; 


      String abc=((?<html>(href|src)\s*=\s*")|(?<css>url\())(?<url>.*?)(?(html)"|\)); **// here is error** 
      Pattern pattern = Pattern.compile(abc, Pattern.CASE_INSENSITIVE); 
      Matcher matcher = pattern.matcher(input); 
      int count=0; 
      String abc=""; 

      System.out.println(pattern); 
      System.out.println(matcher.toString()); 

      while (matcher.find()) 
      { 

       int start = matcher.start(); 
       int end = matcher.end(); 
       String match = input.substring(start, end); 

       //match.matches(); 
      //jTextArea1.append(match); 
      //jTextArea1.append("\n"); 

       //String[] tokens=match.split(" "); 


       //System.out.println(tokens[0].toString()); 



       text2.append(match); 
       text2.append("\n"); 
      } 




      } 
      catch (IOException e) 
      { 
      e.printStackTrace(); 
      } 
      catch (PatternSyntaxException e) 
      { 
      e.printStackTrace(); 
      } 



    } 

です。ありがとう

+0

あなたの文字列リテラルは、引用符の間ではなく、あなたは文字列abcに別の時間を宣言しますか? – MarioDS

+0

私は引用符を入れようとしましたが、それでも私にエラーが出ます。私はどこで始めるべきか、引用符を終わらせるべきではない – kanchan

答えて

3

リテラルの前後に引用符を追加し、正しいエスケープシーケンスを追加する必要があります。また、あなたが二回文字列abcを宣言:へ

String abc=((?<html>(href|src)\s*=\s*")|(?<css>url\())(?<url>.*?)(?(html)"|\)); **// here is error** 
Pattern pattern = Pattern.compile(abc, Pattern.CASE_INSENSITIVE); 
Matcher matcher = pattern.matcher(input); 
int count=0; 
String abc=""; **redeclaration here** 

が変更に:

String abc="((?<html>(href|src)\\s*=\\s*\")|(?<css>url\\())(?<url>.*?)(?(html)\"|\\))"; 
Pattern pattern = Pattern.compile(abc, Pattern.CASE_INSENSITIVE); 
Matcher matcher = pattern.matcher(input); 
int count=0; 
abc=""; 
0
String abc="((?<html>(href|src)\\s*=\\s*\")|(?<css>url\\())(?<url>.*?)(?(html)\"|\\))"; 
// **here should be no more error** 

問題あなたは引用符を忘れてしまい、文字列のバックスラッシュと引用符をエスケープする必要があります。

+0

それは私に同じエラーを与えている。 – kanchan

関連する問題