2011-10-27 3 views
-4

나는 간단한 정규식 프로그램을 개발하려고 노력하고있다. 그러나 이클립스에서이 오류가 계속 발생하고있다.코드에서 무엇이 잘못 되었습니까?

오류가 아닌 대문자 URL에,이 라인에

의 CharSequence getURLContent (URL URL이) {

구문 오류 삽입, IOException가 발생합니다 ";" 완료하려면 LocalVariableDeclarationStatement

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.URL; 
import java.net.URLConnection; 
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 
import android.R.string; 
import android.app.Activity; 
import android.os.Bundle; 

public class VisualizaActivity extends Activity { 
@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.visualiza); 


    String expr = "<td><span\\s+class=\"flagicon\"[^>]*>"; 

    CharSequence getURLContent(URL url) throws IOException{ 
     URLConnection conn = url.openConnection(); 
     String enconding = conn.getContentEncoding(); 
     if (enconding == null){ 
      enconding = "ISO-8859-1"; 
     } 
     BufferedReader br = new BufferredReader(new InputStreamReader(conn.getInputStream(), enconding)); 
     StringBuilder sb = new StringBuilder(16384); 
     try{ 
      String line; 
      while ((line = br.readLine()) != null){ 
       sb.append(line); 
       sb.append('\n'); 
      } 
     } finally{ 
      br.close(); 
     } 
     return sb; 
    } 


    Pattern patt = Pattern.compile(expr,Pattern.DOTALL | Pattern.UNIX_LINES); 
      URL url = new URL("http://en.wikipedia.org/wiki/Mexico"); 
      Matcher m = patt.matcher(getURLContent(url)); 
      while (m.find()) { 
       String stateURL = m.group(1); 
       String stateName = m.group(2); 
       System.out.println(stateName + "," + stateURL); 
      } 
    } 
} 
+4

메서드 내에서 메서드를 만들려고합니까? Android가 내가 모르는 뭔가를 할 수 있습니까? –

+0

^^ This. 코드가 유효하지 않습니다. 너는 그렇게 할 수 없다. –

+1

'BufferredReader' 란 무엇입니까? –

답변

8

메서드 내에서 메서드를 만들 수 없습니다. getURLContent을 내부에 선언하려고했습니다. onCreate

관련 문제