无法从java中的静态上下文错误引用

无法从java中的静态上下文错误引用,java,Java,我的职能如下: public String [] splitString(String text) { int linebreaks=text.length()/80; //how many linebreaks do I need? String [] newText = new String[linebreaks+1]; String tmpText = text; String [] parts = tmpText.split("

我的职能如下:

public String [] splitString(String text) {

     int linebreaks=text.length()/80; //how many linebreaks do I need?  
     String [] newText = new String[linebreaks+1];       
     String tmpText = text;
     String [] parts = tmpText.split(" "); //save each word into an array-element

     //split each word in String into a an array of String text. 
     StringBuffer [] stringBuffer = new StringBuffer[linebreaks+1]; //StringBuffer is necessary because of manipulating text
     int i=0; //initialize counter 
     int totalTextLength=0;
     for(int k=0; k<linebreaks+1;k++) {
         stringBuffer[k] = new StringBuffer();
         while(true) {               
             if (i>=parts.length) break; //avoid NullPointerException
             totalTextLength=totalTextLength+parts[i].length(); //count each word in String              
             if (totalTextLength>80) break; //put each word in a stringbuffer until string length is >80
             stringBuffer[k].append(parts[i]);
             stringBuffer[k].append(" ");
             i++;
         }
         //reset counter, save linebreaked text into the array, finally convert it to a string 
         totalTextLength=0; 
         newText[k] = stringBuffer[k].toString();
     }
     return newText;
 }                      
String text = "abc";
String [] tmpText = splitString(text);
for( int k=0;k<tmpText.length;k++) {
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(textx, texty);
    contentStream.drawString(tmpText[k]); 
    contentStream.endText();
    texty = texty - 20;
}           
contentStream.setLineWidth((float) 0.25);
public String[]splitString(字符串文本){
int linebreaks=text.length()/80;//我需要多少换行符?
字符串[]新文本=新字符串[换行符+1];
字符串tmpText=文本;
String[]parts=tmpText.split(“”;//将每个单词保存到数组元素中
//将字符串中的每个单词拆分为字符串文本数组。
StringBuffer[]StringBuffer=新建StringBuffer[linebreaks+1];//由于要处理文本,因此需要StringBuffer
int i=0;//初始化计数器
int totalTextLength=0;
对于(int k=0;k=parts.length)break;//避免NullPointerException
totalTextLength=totalTextLength+parts[i].length();//计算字符串中的每个单词
if(totalTextLength>80)break;//将每个单词放入stringbuffer,直到字符串长度>80
stringBuffer[k].append(parts[i]);
stringBuffer[k]。追加(“”);
i++;
}
//重置计数器,将换行符文本保存到数组中,最后将其转换为字符串
totalTextLength=0;
newText[k]=stringBuffer[k].toString();
}
返回新文本;
}                      
我从另一个函数调用该函数,并进行如下计算:

public String [] splitString(String text) {

     int linebreaks=text.length()/80; //how many linebreaks do I need?  
     String [] newText = new String[linebreaks+1];       
     String tmpText = text;
     String [] parts = tmpText.split(" "); //save each word into an array-element

     //split each word in String into a an array of String text. 
     StringBuffer [] stringBuffer = new StringBuffer[linebreaks+1]; //StringBuffer is necessary because of manipulating text
     int i=0; //initialize counter 
     int totalTextLength=0;
     for(int k=0; k<linebreaks+1;k++) {
         stringBuffer[k] = new StringBuffer();
         while(true) {               
             if (i>=parts.length) break; //avoid NullPointerException
             totalTextLength=totalTextLength+parts[i].length(); //count each word in String              
             if (totalTextLength>80) break; //put each word in a stringbuffer until string length is >80
             stringBuffer[k].append(parts[i]);
             stringBuffer[k].append(" ");
             i++;
         }
         //reset counter, save linebreaked text into the array, finally convert it to a string 
         totalTextLength=0; 
         newText[k] = stringBuffer[k].toString();
     }
     return newText;
 }                      
String text = "abc";
String [] tmpText = splitString(text);
for( int k=0;k<tmpText.length;k++) {
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(textx, texty);
    contentStream.drawString(tmpText[k]); 
    contentStream.endText();
    texty = texty - 20;
}           
contentStream.setLineWidth((float) 0.25);
String text=“abc”;
字符串[]tmpText=拆分字符串(文本);

对于(int k=0;kA
static
方法只能调用其他
static
方法,因此您也需要定义
splitString

public static String[] splitString(String text) {

另一种方法是
static
,而
splitString
则不是

splitString
声明为静态,它应该可以工作:

public static String[] splitString(String text) {
    // ...
}

将splitString方法设置为静态,以便可以在静态上下文中引用它

public static String[] splitString(String text)

第二个方法是静态方法中的方法?请努力搜索您的错误。堆栈溢出充满了这样的问题。