Итак, мое приложение читает данные из текстового представления и затем сохраняет их в файл. В любом случае, когда я нажимаю кнопку отправки, происходит сбой. Понятия не имею, почему, я пытался удалить отрывочный код, но это тоже не сработало.
В любом случае, если бы вы могли взглянуть на мой код и увидеть, что я сделал неправильно, это было бы здорово; также, если кто-нибудь знает, как скопировать LogCat, это было бы очень круто.
Мой код:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
send = (Button) findViewById(R.id.bLogIn);
user = (EditText) findViewById(R.id.eTuser);
pass = (EditText) findViewById(R.id.eTpassword);
staySignedIn = (CheckBox) findViewById(R.id.Cbstay);
send.setOnClickListener(this);
try {
Fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
Fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (staySignedIn.isChecked()) {
String u = user.getText().toString();
String p = pass.getText().toString();
File f = new File(FILENAME);
try {
Fos = new FileOutputStream(f);
//Write some Data
Fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bLogIn:
if (pass.length() == 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
else if (user.length() == 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
else {
String u = user.getText().toString();
String p = pass.getText().toString();
Bundle send = new Bundle();
send.putString("key", u);
send.putString("key", p);
Intent a = new Intent(LogIn.this, logincheck.class);
startActivity(a);
Toast.makeText(this, "Were signing you in!", Toast.LENGTH_LONG)
.show();
break;
}
}
}
}
The Logcat:
01-19 07:02:42.341: W/System.err(3074): java.io.FileNotFoundException: /userandpass (Read-only file system)
01-19 07:02:42.341: W/System.err(3074): at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
01-19 07:02:42.341: W/System.err(3074): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
01-19 07:02:42.341: W/System.err(3074): at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
01-19 07:02:42.341: W/System.err(3074): at java.io.FileOutputStream.<init>(FileOutputStream.java:69)
01-19 07:02:42.341: W/System.err(3074): at com.gta5news.bananaphone.LogIn.onCreate(LogIn.java:59)
01-19 07:02:42.341: W/System.err(3074): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-19 07:02:42.341: W/System.err(3074): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-19 07:02:42.341: W/System.err(3074): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-19 07:02:42.341: W/System.err(3074): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-19 07:02:42.351: W/System.err(3074): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-19 07:02:42.351: W/System.err(3074): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 07:02:42.351: W/System.err(3074): at android.os.Looper.loop(Looper.java:123)
01-19 07:02:42.351: W/System.err(3074): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-19 07:02:42.351: W/System.err(3074): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 07:02:42.351: W/System.err(3074): at java.lang.reflect.Method.invoke(Method.java:521)
01-19 07:02:42.351: W/System.err(3074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-19 07:02:42.351: W/System.err(3074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-19 07:02:42.351: W/System.err(3074): at dalvik.system.NativeStart.main(Native Method)
01-19 07:02:47.371: W/KeyCharacterMap(3074): No keyboard for id 0
01-19 07:02:47.371: W/KeyCharacterMap(3074): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-19 07:02:49.421: D/AndroidRuntime(3074): Shutting down VM
01-19 07:02:49.421: W/dalvikvm(3074): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-19 07:02:49.421: E/AndroidRuntime(3074): FATAL EXCEPTION: main
01-19 07:02:49.421: E/AndroidRuntime(3074): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.gta5news.bananaphone/com.gta5news.bananaphone.logincheck}; have you declared this activity in your AndroidManifest.xml?
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.app.Activity.startActivityForResult(Activity.java:2817)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.app.Activity.startActivity(Activity.java:2923)
01-19 07:02:49.421: E/AndroidRuntime(3074): at com.gta5news.bananaphone.LogIn.onClick(LogIn.java:95)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.view.View.performClick(View.java:2408)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.view.View$PerformClick.run(View.java:8816)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.os.Handler.handleCallback(Handler.java:587)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.os.Handler.dispatchMessage(Handler.java:92)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.os.Looper.loop(Looper.java:123)
01-19 07:02:49.421: E/AndroidRuntime(3074): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-19 07:02:49.421: E/AndroidRuntime(3074): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 07:02:49.421: E/AndroidRuntime(3074): at java.lang.reflect.Method.invoke(Method.java:521)
01-19 07:02:49.421: E/AndroidRuntime(3074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-19 07:02:49.421: E/AndroidRuntime(3074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-19 07:02:49.421: E/AndroidRuntime(3074): at dalvik.system.NativeStart.main(Native Method)