코딩의이 섹션이 작동하지 않는 이유와 프로그램이 스위치에서 동일한 오류를 계속 발생시키는 이유를 알고 싶습니다.디스플레이 파일 이름 readline with switch case android
내가 TXT 파일로 저장 한 파일을 읽고에 표시 할
을 (컨버터블 INT 값 또는 열거 형 변수 만. 1.7 아래의 소스 레벨에 대한 String 형의 값을 전환 할 수 허용됩니다) 프로그램.
예 : "이메일"을 사례로 써서 원하는 내용을 썼다가이 스위치에서 읽을 수 있도록 txt 파일에 저장하십시오.
누구든지이 문제를 해결할 수 있습니까? 깊이 감사드립니다. 감사. 여기
내 코드입니다 : private void ExecuteCommands(String filename) {
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard, filename + ".txt");
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
String[] tmp = line.split(" ");
//this switch case giving me problem
switch(tmp[0]){
case "Email":
String subject = sbj.getText().toString();
String message = messageBody.getText().toString();
String to = destinationAddress.getText().toString();
Intent emailActivity = new Intent(Intent.ACTION_SEND);
//set up the recipient address
emailActivity.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
//set up the email subject
emailActivity.putExtra(Intent.EXTRA_SUBJECT, subject);
//you can specify cc addresses as well
// email.putExtra(Intent.EXTRA_CC, new String[]{ ...});
// email.putExtra(Intent.EXTRA_BCC, new String[]{ ... });
//set up the message body
emailActivity.putExtra(Intent.EXTRA_TEXT, message);
emailActivity.setType("message/rfc822");
startActivity(Intent.createChooser(emailActivity, "Select your Email Provider :"));
break;
case "SMS message":
String phoneNo = textPhoneNo.getText().toString();
String sms = textSMS.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
break;
}
}
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
} 당신이 당신의 스위치 케이스 스트링 수에 포함하는 방법, (7)에서 Java
버전 문자열에 스위치/케이스를 사용 열거를 고려,하지만 어떻게