2013-06-18 89 views
0

我在訪問我的代碼中的某些字段時遇到問題,我想知道處理此問題的有效方法。訪問字段,Java

public class Indexer { 
static private int startKeyIndex = 0; 
    static private String patternKey = new String(); 
        . 
        . 
private static void extractIndexes(String content) throws IOException { 
    patternKey = "this is a regex for finding keywords, hi!" 
    startKeyIndex = extractIndexFromPattern(contentKey, patternKey); 
}     . 
        . 
        . 
private static void extractKeywords(String pattern, String content) throws IOException{ 
    //The problem is in this method 
    CharSequence contentSeq = content.subSequence(0,3000); 
    String area = extractStringFromPattern(content, patternKey);  
} 
+0

如何你正在訪問? –

+0

什麼是某些領域? – Sam

+0

@你是什麼意思「無法訪問startKeyIndex的值」。它給你編譯錯誤? –

回答

0

一切工作正常。您可以訪問那些字段和字段值。

import java.io.IOException; 

public class Test { 
static private int startKeyIndex = 0; 


private static void extractIndexes(String content) throws IOException { 
    startKeyIndex = 10; 
    System.out.println(startKeyIndex); 
}     


private static void extractKeywords(String pattern, String content) throws 
                   IOException{ 
    System.out.println(startKeyIndex); 
} 


public static void main(String[] args) throws IOException { 
    extractIndexes(""); 
    extractKeywords("", ""); 
} 


} 

而結果是:

10 
10