Debugging Error - "Unfortunately, app has stopped working "

0 kayden rice · March 3, 2015
     Whenever I create a new project and run or debug it to test it out, the emulator works just fine, but when I click on my application on the emulator it loads for a second then an error message pops up and says, "Unfortunately, x application has stopped working. " (x being the application name) Every single time I try to debug my app this happens and I have no idea why because my code has no errors and it's fine. 

So if anyone knows how to fix this it would really be great!

Post a Reply

Replies

Oldest  Newest  Rating
+1 Spikeedoo G · March 3, 2015
It is probably something in your code if you app is force closing on startup.

Code please?
+1 Dol Lod · March 4, 2015
I have read through your code and I only have a few theories regarding your possible errors. 

1) Are all your activities declared in your Android Manifest? If not, declare them. This is a fairly common mistake and you have to add all activities into the manifest file. This is an example of what should be in your Android manifest file. 

<activity
            android:name="com.tadpoltechnology.universeacademy.SunActivity"
            android:label="" >
        </activity>

2) The intent in homeact should take in the getApplicationContext() context instead of view.getContext(). Honestly, this change may not be necessary, but is a good check if nothing else works.
0 Nicholas Eason · March 3, 2015
What the "Unfortuantely...." message means is that your app code has crashed. So not only would your code help, but so your logcat.
0 kayden rice · March 4, 2015
Here's the code for the 2 activities I'm using. I'll be adding a lot more activities but the code will be the same for all of them mainly.

Main Activity:


package com.tadpoltechnology.universeacademy;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btnSun = (Button) findViewById(R.id.btnSun);
        Button btnMercury = (Button) findViewById(R.id.btnMercury);
        Button btnVenus = (Button) findViewById(R.id.btnVenus);
        Button btnEarth = (Button) findViewById(R.id.btnEarth);
        Button btnMars = (Button) findViewById(R.id.btnMars);
        Button btnJupiter = (Button) findViewById(R.id.btnJupiter);
        Button btnSaturn = (Button) findViewById(R.id.btnSaturn);
        Button btnUranus = (Button) findViewById(R.id.btnUranus);
        Button btnNeptune = (Button) findViewById(R.id.btnNeptune);

        btnSun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent sunAct = new Intent(view.getContext(), SunActivity.class);
                startActivity(sunAct);
            }
        });


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

2nd Activity: 


package com.tadpoltechnology.universeacademy;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;


public class SunActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sun);

        Button btnBack = (Button) findViewById(R.id.btnBack);

        btnBack.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view){

                Intent homeAct = new Intent(view.getContext(), MainActivity.class);
                startActivity(homeAct);
            }

        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.menu_sun, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}


It's just a basic switch between activity code so if anyone could figure the problem here please let me know it would really be nice, thank you! 
0 kayden rice · March 4, 2015
Thank you very much for taking the time to look through my code. I will try both of these methods to see if it works again, thank you very much! 
  • 1

Java / Android Development

107,096 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator