Question

Why is my app force closing when I hit the button to start the Activity of First

This is the startup Activity:

public class ForeverAlone extends Activity implements OnClickListener{
    /** Called when the activity is first created. */

    Button start;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        start = (Button) findViewById(R.id.bStart);
        start.setOnClickListener(this);
    }

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(ForeverAlone.this, First.class);
                ForeverAlone.this.startActivity(myIntent);
            }

    }

This is the Activity that is MEANT to come up after I hit the button:

public class First extends Activity implements OnClickListener {

    Button firstNext;
    EditText firstFacebook, firstReallife;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first);
        firstNext = (Button) findViewById(R.id.bFirstNext);
        firstFacebook = (EditText) findViewById(R.id.etFirst1);
        firstReallife = (EditText) findViewById(R.id.etFirst2);
        firstNext.setOnClickListener(this);
        String firstFB = firstFacebook.getText().toString();
        String firstRL = firstReallife.getText().toString();
        DataHelper.insert(firstFB, firstRL);
    }



        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent(First.this, Second.class);
            First.this.startActivity(myIntent);
        }
}

Any help at all will be appreciated!

[Edit]

Here's the LogCat:

01-08 19:19:55.656: D/dalvikvm(363): GC_EXTERNAL_ALLOC freed 50K, 53% free 2553K/5379K, external 1625K/2137K, paused 76ms
01-08 19:19:57.966: D/AndroidRuntime(363): Shutting down VM
01-08 19:19:57.966: W/dalvikvm(363): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-08 19:19:57.986: E/AndroidRuntime(363): FATAL EXCEPTION: main
01-08 19:19:57.986: E/AndroidRuntime(363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kenning.foreveralone/com.kenning.foreveralone.First}: java.lang.NumberFormatException: unable to parse '' as integer
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.os.Looper.loop(Looper.java:123)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-08 19:19:57.986: E/AndroidRuntime(363):  at java.lang.reflect.Method.invokeNative(Native Method)
01-08 19:19:57.986: E/AndroidRuntime(363):  at java.lang.reflect.Method.invoke(Method.java:507)
01-08 19:19:57.986: E/AndroidRuntime(363):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-08 19:19:57.986: E/AndroidRuntime(363):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-08 19:19:57.986: E/AndroidRuntime(363):  at dalvik.system.NativeStart.main(Native Method)
01-08 19:19:57.986: E/AndroidRuntime(363): Caused by: java.lang.NumberFormatException: unable to parse '' as integer
01-08 19:19:57.986: E/AndroidRuntime(363):  at java.lang.Integer.parseInt(Integer.java:362)
01-08 19:19:57.986: E/AndroidRuntime(363):  at java.lang.Integer.parseInt(Integer.java:332)
01-08 19:19:57.986: E/AndroidRuntime(363):  at java.lang.Integer.<init>(Integer.java:105)
01-08 19:19:57.986: E/AndroidRuntime(363):  at com.kenning.foreveralone.DataHelper.insert(DataHelper.java:9)
01-08 19:19:57.986: E/AndroidRuntime(363):  at com.kenning.foreveralone.First.onCreate(First.java:27)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 19:19:57.986: E/AndroidRuntime(363):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-08 19:19:57.986: E/AndroidRuntime(363):  ... 11 more

[Edit]

I've found the cause of the "force close" problem.

It's these lines of code:

String firstFB = firstFacebook.getText().toString();
String firstRL = firstReallife.getText().toString();
DataHelper.insert(firstFB, firstRL);

How do I stop the method from running into them and sort of skip them in a way?

Was it helpful?

Solution

You are getting the instance of the EditTexts

    firstFacebook = (EditText) findViewById(R.id.etFirst1);
    firstReallife = (EditText) findViewById(R.id.etFirst2);

then getting their values

    String firstFB = firstFacebook.getText().toString();
    String firstRL = firstReallife.getText().toString();

and using them here

    DataHelper.insert(firstFB, firstRL);

but the EditTexts are empty so you are essentially passing an empty string in, hence the

Caused by: java.lang.NumberFormatException: unable to parse '' as integer

OTHER TIPS

It would help if you posted the logcat output, but my guess is that you have not listed First as an activity in your manifest. Either that, or something in First.onCreate is generating an exception.

You have a NumberFormatException. According to your logcat output you are inserting an empty string where an integer is expected in your Datahelper class:

at com.kenning.foreveralone.DataHelper.insert(DataHelper.java:9)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top