Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid App stops when button clicked
    primarykey
    data
    text
    <p>I am trying to write an app that has 4 menu buttons on the main screen. On clicking this each menu button, a new screen should appear. At the moment I have only written code to cater for the first button to be clicked, but it the app crashes/stops. I think the problem is that I don't have the activity of TheCompany declared in the Android Manifest file, but I don't know how I would do that. I am writing the app in Eclipse and so far I have the following files/sets of code: MainActivity.Java:</p> <pre><code>public class MainActivity extends Activity { public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View button = findViewById(R.id.TheCompany); button.setOnClickListener(new OnClickListener(){ public void onClick (View v){ startIntent(); } }); //getSupportActionBar().setDisplayHomeAsUpEnabled(true); // If your minSdkVersion is 11 or higher, instead use: // getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); return super.onCreateOptionsMenu(menu); } /** Called when the user clicks the Company button */ private void startIntent() { // Do something in response to button Intent intent = new Intent(this, TheCompany.class); startActivity(intent); } } </code></pre> <p>The Activity_main.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="The Company" android:id="@+id/TheCompany"/&gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Services"/&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Contacts" /&gt; &lt;Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Structure" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Then I have the TheCompany Java file:</p> <pre><code>public class TheCompany extends Activity { public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.company); } } </code></pre> <p>The Android.Manifest looks like:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /&gt; &lt;application android:allowBackup="true" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:icon="@drawable/logo" android:name="com.example.myfirstapp.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.example.myfirstapp.DisplayMessageActivity" android:label="@string/title_activity_display_message" android:parentActivityName="com.example.myfirstapp.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.myfirstapp.MainActivity" /&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload