-1

why my unable to start my manactivity

package cse.svu;

/**
 * Created by DELL on 11/11/2014.
 */
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.Window;
import java.util.Timer;
import java.util.TimerTask;

public class splashscreen extends Activity {

    long delay=8000;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Remove the Title Bar
            requestWindowFeature(Window.FEATURE_NO_TITLE);

            // Get the view from splash_screen.xml
            setContentView(R.layout.splash_screen);

            // Create a Timer
            Timer RunSplash = new Timer();

            // Task to do when the timer ends
            TimerTask ShowSplash = new TimerTask() {
                @Override
                public void run() {
                    // Close SplashScreenActivity.class
                    finish();

                    // Start MainActivity.class
                    Intent myIntent = new Intent(splashscreen.this,MainActivity.class);
                    startActivity(myIntent);
                }
            };

            // Start the timer
            RunSplash.schedule(ShowSplash, delay);
        }

//METHOD 2

  /*
  new Handler().postDelayed(new Runnable() {

            // Using handler with postDelayed called runnable run method

            @Override
            public void run() {
                Intent i = new Intent(MainSplashScreen.this, FirstScreen.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, 5*1000); // wait for 5 seconds

    }*/
}
so please find the solution in my programm

package cse.svu;

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 implements View.OnClickListener{

    Button con,about_svu,academic,admin,campus,research;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        con=(Button)findViewById(R.id.contact);
        about_svu=(Button)findViewById(R.id.about);
        academic=(Button)findViewById(R.id.academic);
        admin=(Button)findViewById(R.id.admin);
        campus=(Button)findViewById(R.id.campus);
        research=(Button)findViewById(R.id.research);
        con.setOnClickListener(this);
        about_svu.setOnClickListener(this);
        academic.setOnClickListener(this);
        admin.setOnClickListener(this);
        campus.setOnClickListener(this);
        research.setOnClickListener(this);
       }
            @Override
       public void onClick(View v) {
               switch(v.getId()){
                    case R.id.contact:
                        Intent intent=new Intent(MainActivity.this,contact.class);
                        startActivity(intent);
                        break;
                    case R.id.about:
                        Intent intent1=new Intent(MainActivity.this,about_svu.class);
                        startActivity(intent1);
                        break;
                    case R.id.academic:
                        Intent intent2=new Intent(MainActivity.this,academic_excellence.class);
                        startActivity(intent2);
                        break;
                    case R.id.admin:
                        Intent intent3=new Intent(MainActivity.this,adminstration.class);
                        startActivity(intent3);
                        break;
                    case R.id.campus:
                        Intent intent4=new Intent(MainActivity.this,campus_facilities.class);
                        startActivity(intent4);
                        break;
                    case R.id.research:
                        Intent intent5=new Intent(MainActivity.this,researchandpublication.class);
                        startActivity(intent5);
                        break;
               }
       };



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

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

        return super.onOptionsItemSelected(item);
    }
}

errors are coming in the program are java.lang.RuntimeException: Unable to start activity ComponentInfo{cse.svu/cse.svu.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)

sanjay
  • 695
  • 11
  • 22

2 Answers2

4

1- You should delete style.xml in values-v21 folder 2- your style.xml in values folder

<?xml version="1.0" encoding="utf-8"?>
<resources>


    <!--
        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- API 14 theme customizations can go here. -->
        <item name="colorPrimary">#ff0000</item>
    </style>

</resources>

and AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppBaseTheme" >
    </application>

good luck :)

msevgi
  • 4,828
  • 2
  • 24
  • 30
1

If you are extending ActionBarActivity in your MainActivity, you will have to change the parent theme in values-v11 also. So the style.xml in values-v11 will be -

<!-- res/values-v11/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="QueryTheme" parent="@style/Theme.AppCompat">
  <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

ActionBarCompat Problem

Community
  • 1
  • 1
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28