android中的下一个活动出错[重复]

Posted

技术标签:

【中文标题】android中的下一个活动出错[重复]【英文标题】:error in next activity in android [duplicate] 【发布时间】:2017-03-27 17:33:50 【问题描述】:

当我从 MainActiviy 开始时,它运行良好,但是当我添加另一个活动,然后单击按钮并转到主要活动时,它显示我很遗憾停止工作。我将新活动定义为我的启动器活动。当应用程序启动时它会出现,但是当我单击主要活动的按钮时,它在这里停止工作是我的清单

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

<!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
     Google Maps android API v2, but you must specify either coarse or fine
     location permissions for the 'MyLocation' functionality. 
-->

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.myapp.android.locationapi.maps.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<permission
    android:name="com.myapp.android.locationapi.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <uses-library android:name="com.google.android.maps"/>

    <activity
        android:name=".chek"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".SignIn"/>
    <!--         <activity android:name=".MainActivity"></activity> -->
    <activity android:name=".Signup"/>
    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyDauI14NETaUpIitn9lfYvkar11cKKNhIc"/>

    <activity android:name=".MainActivity">
    </activity>
</application>

这是我启动活动的代码:

startactivity(new Intent(chck.this,MainActivity.class));

这是我的日志

java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.nexurs/com.example.nexurs.MainActivity: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2455)
                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2517)
                                                                    at android.app.ActivityThread.access$800(ActivityThread.java:162)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                    at android.os.Looper.loop(Looper.java:189)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5529)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
                                                                 Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
                                                                    at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:199)
                                                                    at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:133)
                                                                    at com.example.nexurs.MainActivity.onCreate(MainActivity.java:38)

【问题讨论】:

请发布您的 Logcat 的输出。 请出示你的logcat 先生,我更新了我的帖子 这是解决方案,希望对您有用。 ***.com/questions/26515058/… 添加一些最简洁的活动代码 【参考方案1】:

在@style/AppTheme.NOactionBar 中添加这两行

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
   </style>

否则删除 android:theme="@style/AppTheme.NoActionBar"

【讨论】:

它仍然无法正常工作。 .当我删除工具栏=(工具栏)findViewById(R.id.toolbar); setSupportActionBar(工具栏);从 mainactivity 它的作品,但它没有显示我的导航抽屉图标

以上是关于android中的下一个活动出错[重复]的主要内容,如果未能解决你的问题,请参考以下文章

单击按钮以转到从 Spinner 选择的下一个活动时出错

视图隐藏在android活动中的其他视图后面

启动 Android 活动时出错

如何导航到android中的下一个sqlite表列?

Android - Asynctask完成时的下一个活动

启动新活动 Android 时出错