【发布时间】:2012-04-18 19:46:07
【问题描述】:
我的代码似乎可以运行,但它没有显示结果文本视图上的任何结果我猜测是因为我设置代码的方式。代码在下面有人请帮助我。谢谢
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 个字符串/单词,这可能是原因。再次感谢
【问题讨论】:
-
您在“inputText”中有存储输入流行,之后您没有使用它,即您使用“s”来获取字符串以显示不是“inputstream”
-
对不起,我没有为 S 放置声明的变量。它实际上是一个全局声明的数组列表,输入与来自编辑文本的用户输入的输入文本无关。
标签: java android resources inputstream bufferedreader