日食中的多个标记错误 [英] Multiple markers error in eclipse

查看:55
本文介绍了日食中的多个标记错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Web Crowler提供了一个Java文件.这给了我错误,例如在行和行号上有多个标记.

I have one java file for web Crowler. That gives me error like multiple markers at line and some line number .

我刚刚学会了模式和匹配器.所以我无法纠正错误.

I am just learned the pattern and matcher. so i am unable to correct the error.

我的代码是

 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(); 
            }



    }

}

}

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

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

它会显示类似错误

     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)

请帮助我.谢谢

推荐答案

您需要在文字周围加上引号,并添加正确的转义序列.另外,您还两次声明了字符串abc:

You need to add quotation marks around your literal and add the correct escape sequences. Also you declare String abc twice:

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="";

这篇关于日食中的多个标记错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆