0

I think there is a problem with my activities because it runs the splash screen fine but when it gets to home page it gives force close error. I also appreciate it if you can see if my home.java code is correct I basically wanna open other activities and for exit button to quit the application.

Android Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.decrypter"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Home"
        android:label="@string/title_activity_home" >
        <intent-filter>
            <action android:name="com.example.decrypter.HOME" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>

home.java

package com.example.decrypter;

import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;

public class Home extends Activity implements OnItemSelectedListener {

    Button btn_start,btn_about,btn_exit;
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);

        btn_start = (Button) findViewById(R.id.btn_start);
        btn_about = (Button) findViewById(R.id.btn_about);
        btn_exit = (Button) findViewById(R.id.btn_exit);

        btn_start.setOnClickListener( new View.OnClickListener() 
        {
            public void onClick(View v) {
                Intent start = new Intent(Home.this, MainPage.class);
                Home.this.startActivity(start);
            }
        });
        btn_about.setOnClickListener( new View.OnClickListener() 
        { 
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent about = new Intent(Home.this, about.class);
                Home.this.startActivity(about);
            }
        });
        btn_exit.setOnClickListener( new View.OnClickListener() 
        { 
            public void onClick(View v) {
                // TODO Auto-generated method stub
                System.exit(0);
            }
        });
    }

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

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
    }
}

String.xml

<string name="app_name">decrypter</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main_page">MainPage</string>
<string name="title_activity_home">Home</string>
 <string name="prompt">- </string>

<string-array name="numbers">
    <item >1</item>
    <item >2</item>
    <item>3</item>
    <item >4</item>
    <item>5</item>
    <item >6</item>
    <item >7</item>
    <item >8</item>
    <item>9</item>
</string-array>

home.xml

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/btn_about"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/home" >

 <Button
    android:id="@+id/btn_start"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="183dp"
    android:gravity="center"
    android:text="Start" />

 <Button
    android:id="@+id/btn_about"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btn_start"
    android:layout_below="@+id/btn_start"
    android:layout_marginTop="16dp"
    android:gravity="center"
    android:text="About me" />

 <Button
    android:id="@+id/btn_exit"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/Button01"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="15dp"
    android:gravity="center"
    android:text="Exit" />

  </RelativeLayout>
dave.c
  • 10,910
  • 5
  • 39
  • 62
  • 1
    Are you calling startActivity() on the home activity from the splash? – xordon Dec 10 '12 at 08:13
  • 2
    Post your logcat trace to see the error – Adrián Rodríguez Dec 10 '12 at 08:17
  • write instead of and post your logcat – Narendra Pal Dec 10 '12 at 08:18
  • You should post the code for your splash `Activity`, as well as the logcat output of the crash. Other issues (not related to the crash) are that: I can't see an `About` activity defined in your manifest; you [shouldn't call `System.exit()`](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon); do you really want to start another identical activity when the user presses 'start'? – dave.c Dec 10 '12 at 11:01

1 Answers1

0

In your main.java, either onClick or any other event, you have to call start activity for the home activity. Or if you want home activity to be the first to load then you can make home activity main and remove other main activities. Convert your Home activity to LAUNCHER activity.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
Shaleen
  • 829
  • 7
  • 17
  • I did try to run Home.java as main activity and it does not work there is something wrong with home.java because I have another activity and when I set that to run in manifest it works. and yes I did change the activity the will run after splash.java to home.java but no luck – user1890159 Dec 10 '12 at 17:32
  • How is your splash.java looks? Are you starting home activity on some event? – Shaleen Dec 11 '12 at 09:39