无法ComponentInfo您需要使用Theme.AppCompat主题,本次活动启动活动。 [英] Unable to start activity ComponentInfo You need to use a Theme.AppCompat theme with this activity.

查看:175
本文介绍了无法ComponentInfo您需要使用Theme.AppCompat主题,本次活动启动活动。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我无法启动我的manactivity

\r
\r

包cse.svu;\r
\r
/ **\r
 *创建者戴尔二○一四年十一月一十一日。\r
 * /\r
进口android.os.Bundle;\r
进口android.os.Handler;\r
进口android.app.Activity;\r
进口android.content.Intent;\r
进口android.view.Menu;\r
进口android.view.Window;\r
进口java.util.Timer中;\r
进口java.util.TimerTask中;\r
\r
公共类闪屏延伸活动{\r
\r
    长时间的延迟= 8000;\r
        @覆盖\r
        公共无效的onCreate(捆绑savedInstanceState){\r
            super.onCreate(savedInstanceState);\r
            //删除标题栏\r
            requestWindowFeature(Window.FEATURE_NO_TITLE);\r
\r
            //从splash_screen.xml视图\r
            的setContentView(R.layout.splash_screen);\r
\r
            //创建一个定时器\r
            定时器RunSplash =新的Timer();\r
\r
            //任务做定时器结束时\r
            TimerTask的ShowSplash =新的TimerTask(){\r
                @覆盖\r
                公共无效的run(){\r
                    //关闭SplashScreenActivity.class\r
                    完();\r
\r
                    //开始MainActivity.class\r
                    意图myIntent =新意图(splashscreen.this,MainActivity.class);\r
                    startActivity(myIntent);\r
                }\r
            };\r
\r
            //启动定时器\r
            RunSplash.schedule(ShowSplash,延迟);\r
        }\r
\r
//方法2\r
\r
/ *\r
新的处理程序()。postDelayed(新的Runnable(){\r
\r
            //与postDelayed使用处理器可运行叫run方法\r
\r
            @覆盖\r
            公共无效的run(){\r
                意图I =新意图(MainSplashScreen.this,FirstScreen.class);\r
                startActivity(ⅰ);\r
\r
                //关闭此活动\r
                完();\r
            }\r
        },5 * 1000); //等待5秒钟\r
\r
    } * /\r
}

\r

\r
\r所以请找到解决方案在我PROGRAMM

\r
\r

包cse.svu;\r
\r
进口android.content.Intent;\r
进口android.support.v7.app.ActionBarActivity;\r
进口android.os.Bundle;\r
进口android.view.Menu;\r
进口android.view.MenuItem;\r
进口android.view.View;\r
进口android.widget.Button;\r
\r
\r
\r
公共类MainActivity扩展ActionBarActivity实现View.OnClickListener {\r
\r
    按钮CON,about_svu,学术,管理,校园,研究;\r
\r
    @覆盖\r
    保护无效的onCreate(捆绑savedInstanceState){\r
        super.onCreate(savedInstanceState);\r
        的setContentView(R.layout.activity_main);\r
        CON =(按钮)findViewById(R.id.contact);\r
        about_svu =(按钮)findViewById(R.id.about);\r
        学术=(按钮)findViewById(R.id.academic);\r
        管理员=(按钮)findViewById(R.id.admin);\r
        校园=(按钮)findViewById(R.id.campus);\r
        研究=(按钮)findViewById(R.id.research);\r
        con.setOnClickListener(本);\r
        about_svu.setOnClickListener(本);\r
        academic.setOnClickListener(本);\r
        admin.setOnClickListener(本);\r
        campus.setOnClickListener(本);\r
        research.setOnClickListener(本);\r
       }\r
            @覆盖\r
       公共无效的onClick(视图v){\r
               开关(v.getId()){\r
                    案例R.id.contact:\r
                        意向意图=新意图(MainActivity.this,contact.class);\r
                        startActivity(意向);\r
                        打破;\r
                    案例R.id.about:\r
                        意图int​​ent1 =新意图(MainActivity.this,about_svu.class);\r
                        startActivity(intent1);\r
                        打破;\r
                    案例R.id.academic:\r
                        意图int​​ent2 =新意图(MainActivity.this,academic_excellence.class);\r
                        startActivity(intent2);\r
                        打破;\r
                    案例R.id.admin:\r
                        意图int​​ent3 =新意图(MainActivity.this,adminstration.class);\r
                        startActivity(intent3);\r
                        打破;\r
                    案例R.id.campus:\r
                        意图int​​ent4 =新意图(MainActivity.this,campus_facilities.class);\r
                        startActivity(intent4);\r
                        打破;\r
                    案例R.id.research:\r
                        意图int​​ent5 =新意图(MainActivity.this,researchandpublication.class);\r
                        startActivity(intent5);\r
                        打破;\r
               }\r
       };\r
\r
\r
\r
    @覆盖\r
    公共布尔onCreateOptionsMenu(菜单菜单){\r
        //充气菜单;如果是present这增加了项目操作栏。\r
        。getMenuInflater()膨胀(R.menu.menu_main,菜单);\r
        返回true;\r
    }\r
\r
    @覆盖\r
    公共布尔onOptionsItemSelected(菜单项项){\r
        //处理动作栏项目点击这里。操作栏会\r
        //自动处理上点击主页/向上按钮,只要\r
        //你在AndroidManifest.xml中指定一个父活动。\r
        INT ID = item.getItemId();\r
\r
        // noinspection SimplifiableIfStatement\r
        如果(ID == R.id.action_settings){\r
            返回true;\r
        }\r
\r
        返回super.onOptionsItemSelected(项目);\r
    }\r
}

\r

\r
\r

错误在程序即将被了java.lang.RuntimeException:无法启动活动ComponentInfo {cse.svu / cse.svu.MainActivity}:java.lang.IllegalStateException:您需要使用Theme.AppCompat主题(或后裔)与本次活动。
            在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)


解决方案

如果你在你的MainActivity延长ActionBarActivity,你将不得不更改父主题值-V11也。
因此,在值-V11的style.xml会 -

 <! -  RES /值-V11 /的themes.xml  - >
< XML版本=1.0编码=UTF-8&GT?;
<资源>
  <样式名称=QueryTheme父=@风格/ Theme.AppCompat>
  <! - 与Theme.Holo设备上运行你的应用程序的任何自定义在这里 - >
< /风格>

<一个href=\"http://stackoverflow.com/questions/18063395/actionbarcompat-java-lang-illegalstateexception-you-need-to-use-a-theme-appcom\">ActionBarCompat问题

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)

解决方案

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

这篇关于无法ComponentInfo您需要使用Theme.AppCompat主题,本次活动启动活动。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆