开发者

Passing values between methods

I've got method where I read value into variable

public void displayFromExcel(String xlsPath) {
. 
. 
. 
pole[i] = cell.getNumericCellValue(开发者_Python百科);
.
.
pole1[j] = richTextString;

Then I have method where I build a String using StringBuilder

    private void getHenkValues (StringBuilder sb) { 
    sb.append("<ColumnValue name=\"hen_allockey\">" + pole1[j] + "</ColumnValue\">\r\n"
            +"<ColumnValue name=\"hen_percentage\">"+ pole[i] + "</ColumnValue\">\r\n");
}

Then I have method where I write it into file:

protected void jobRun() throws Exception {
sb = new StringBuilder();
getHenkValues(sb);
String epilog1 = sb.toString();

FileOutputStream fos = new FileOutputStream("c:\\test\\osem.xml");
OutputStreamWriter osw = new OutputStreamWriter(fos, Charset.forName("UTF-8"));
osw.write(epilog1);
osw.flush();
osw.close();  
}

And in method main I call the method jobrun.

How can I get the values from pole[i], pole1[j] from method displayFromExcel to method getHenkValues?


Your displayFromExcel method need to return them (using a custom class or a collection of some sort, perhaps an array).

Your getHenkValues needs to accept these values as well, you could try something like:

getHenkValues(StringBuilder sb, Object value1, Object value2)

or whatever is relevant for your case.


You could make pole and pole1 private fields of the class in which displayFromExcel, getHenkValues and jobRun are located:

private Object[] pole;
private String[] pole1;

Then you can assign values to these arrays in one method and access them in another.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜