隨機字符串正常工作。Android隨機字符串不檢查
現在不工作檢查。 我輸入的文字是EditText繪製的。
但檢查不起作用。爲什麼? 代碼:
public static StringBuffer random() {
String str = new String(
"G12HIJdefgPQRSTUVWXYZabc56hijklmnopqAB78CDEF0KLMNO3rstu4vwxyz9");
StringBuffer sb = new StringBuffer();
sb.toString();
String ar = null;
Random r = new Random();
int te = 0;
for (int i = 1; i <= 10; i++) {
te = r.nextInt(62);
ar = ar + str.charAt(te);
sb.append(str.charAt(te));
}
return sb;
}
public void onCreate(Bundle icicle) {
setContentView(R.layout.main);
random = random().toString();
TextView display = (TextView) findViewById(R.id.textView1);
display.setText("Random Number: " + random); // Show the random number
et = (EditText) findViewById(R.id.etNumbers);
ok = (Button) findViewById(R.id.button1);
ok.setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
charsEntered = et.getText().toString();
} catch (NumberFormatException nfe) {
Toast.makeText(et.getContext(), "Bla bla bla", Toast.LENGTH_LONG)
.show();
}
if (random == charsEntered) {
Toast.makeText(et.getContext(), "Good!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(et.getContext(), "Bad!", Toast.LENGTH_LONG).show();
}
}
}
你能否解釋一下你的問題更多? –
只是不工作檢查。 – Defus
Defus,如果可能的話,請確保代碼發佈在_here_而不是像pastebin這樣的網站上。這樣,即使其他網站完全消失,問題仍然有用。而且,僅供參考,「不起作用」並不是一個有用的錯誤報告。也許你可以詳細說明發生了什麼。 – paxdiablo