Question

So, my app reads Data from the text view and then saves it to a file. Anyway, when I press the submit button it crashes. I have no idea, why, I tried deleting sketchy code, but that didn't work either.

Anyway, if you could take a look at my code and see what I did wrong, that would be great; also if anyone knows how to copy the LogCat, that would be super cool.

My Code:

@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)
Was it helpful?

Solution

if you looked at the logs the answer is in it. Check the line

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?

It says that you did not declare your new activity which you are trying to open on your button click in the manifest. Add it to your manifest and it should work fine.

It is trying to find your logincheck class in the manifest.

And as a side note try to follow java conventions. use camel casing for class names and such. for example your class should be names as LoginCheck. More on java conventions here.

Your manifest should already have an activity tag. under it add your new activity like this

<activity name="com.gta5news.bananaphone.logincheck" />

That should do it.

OTHER TIPS

main 01-19 07:02:49.421: E/AndroidRuntime(3074): android.content.ActivityNotFoundException: Unable to find explicit activity class

Means you have not declared logincheck activity in AndroidManifest.xml file.

Add it like this:

    <activity android:name=".logincheck" android:label="@string/app_name"></activity>

android:name like you have given for your other activitie(s)..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top