我的代码似乎可以运行,但它没有显示结果文本视图上的任何结果我猜测是因为我设置代码的方式。代码在下面有人请帮助我。谢谢
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main3);
Button button = (Button) findViewById(R.id.but);
input = (EditText) findViewById(R.id.editTextj);
display = (TextView) findViewById(R.id.textView8);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CCActivity3 fs = new CCActivity3();
fs.fileReader();
}// button
});// button end
}
public void fileReader() {
try {
InputStream is=this.getResources().openRawResource(R.raw.file);
BufferedReader bc = new BufferedReader(new InputStreamReader(is));
String cLine;
String inputText = "";
List<String> test2 = new ArrayList<String>();
// read file line by line
while ((cLine = bc.readLine()) != null) {
inputText = inputText + cLine + "\n";
}
s = input.getText().toString();
test = CCActivity3.getPermutation(s);//Permutation method
test2.retainAll(test);//intersection
String fg = "";
for (String s2 : test2) {
fg += s2 + "\n";
}
display.setText(fg);
bc.close();
} catch (Exception e) {// catch any errors if necessary
display.setText(e.getMessage());
}
}
如果您检查资源行,我很确定没有得到正确的结果,而且我相信它们只是分散了代码的格式。提示 res/raw 路径上的 file.txt 有超过 100,000 个字符串/单词,这可能是原因。再次感谢