1. Download our Official Android App: Forums for Android!

Opening a new activity crashes my app

Discussion in 'Android Development' started by Gregary Boyles, Oct 2, 2017.

  1. Gregary Boyles

    Thread Starter
    Rank:
     #850
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    This method of opening a new activity was working when I had my target android version as 25 and was running my app on the android emulator.

    I have since given up trying to run my app on the emulator because it has become impossibly slow.

    Instead I am building a signed APK and installing the app on my real mobile phone.

    I downgraded the target SDK of my app to 10 because my mobile phone is quite old.

    Now when I press one of the button in my main activity (which are supposed to start a new activity) the app crashes and I have the faintest idea why.

    I have googled this problem and none of the suggested fixes work.

    I commented out all the code in the onCreate() function of the class associated with my new activity, but it makes no difference - the app still crashes. So the problem has nothing to do with any code in my activity classes.

    Suggestions?

    Code (Text):
    1.  
    2.  
    3. package com.example.greg.irrigationcontroller;
    4.  
    5. import android.app.AlertDialog;
    6. import android.content.Intent;
    7. import android.support.v7.app.AppCompatActivity;
    8. import android.os.Bundle;
    9. import android.view.View;
    10. import android.widget.Button;
    11.  
    12. public class MainActivity extends AppCompatActivity implements View.OnClickListener
    13. {
    14.  
    15.     // Used to load the 'native-lib' library on application startup.
    16.     static {
    17.         System.loadLibrary("native-lib");
    18.     }
    19.  
    20.     @Override
    21.     protected void onCreate(Bundle savedInstanceState)
    22.     {
    23.         super.onCreate(savedInstanceState);
    24.         setContentView(R.layout.activity_main);
    25.  
    26.         m_buttonSettings = (Button)findViewById(R.id.id_button_settings);
    27.         m_buttonSettings.setOnClickListener(MainActivity.this);
    28.  
    29.         m_buttonView = (Button)findViewById(R.id.id_button_view);
    30.         m_buttonView.setOnClickListener(MainActivity.this);
    31.  
    32.         m_buttonSearch = (Button)findViewById(R.id.id_button_search);
    33.         m_buttonSearch.setOnClickListener(MainActivity.this);
    34.  
    35.         m_buttonManual = (Button)findViewById(R.id.id_button_manual);
    36.         m_buttonManual.setOnClickListener(MainActivity.this);
    37.     }
    38.  
    39.     @Override
    40.     public void onClick(View view)
    41.     {
    42.         Intent intent = null;
    43.  
    44.         switch (view.getId())
    45.         {
    46.             case R.id.id_button_settings:
    47.                 intent = new Intent(getApplicationContext(), SettingsStep1Activity.class);
    48.                 break;
    49.             case R.id.id_button_search:
    50.                 break;
    51.             case R.id.id_button_view:
    52.                 intent = new Intent(getApplicationContext(), ViewSettingsActivity.class);
    53.             case R.id.id_button_manual:
    54.                 break;
    55.         }
    56.         if (intent != null)
    57.             startActivity(intent);
    58.     }
    59.  
    60.     protected Button m_buttonSettings, m_buttonView, m_buttonSearch, m_buttonManual;
    61.  
    62. }
    63.  
     

    Advertisement

  2. wseng92

    wseng92 Well-Known Member
    Rank:
     #421
    Points:
    28
    Posts:
    81
    Joined:
    Oct 26, 2015

    Oct 26, 2015
    81
    13
    28
    Male
    Please post the logcat errors
     
  3. Gregary Boyles

    Thread Starter
    Rank:
     #850
    Points:
    15
    Posts:
    30
    Joined:
    Oct 1, 2017

    Oct 1, 2017
    30
    0
    15
    Never mind - my activity was not listed in the manifest.
    As soon as I fixed that my app no longer crashed.
     

Share This Page

Loading...