【问题标题】:Simple android app crash after start [closed]启动后简单的android应用程序崩溃[关闭]
【发布时间】:2015-01-06 08:15:22
【问题描述】:

我尝试制作一个简单的 android 应用程序,它会触发网络服务器打开大门,一切正常,直到我进行了一些设计(而不是 java)更改。现在我什至无法正常启动应用程序。

如果您有任何想法,请查看并告诉我。它尝试了 apk @ Galaxy S3 和 Note 3

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="wstrends.brana" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="WS trends Gatekeeper"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="WS trends Gatekeeper" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>    

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Otevřít bránu"
        android:id="@+id/button"
        android:layout_below="@+id/password"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="43dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Pro prokračování vložte heslo"
        android:id="@+id/upper"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="29dp"
        android:password="false"
        android:textColor="#bc000000" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/password"
        android:singleLine="true"
        android:password="true"
        android:autoText="false"
        android:layout_below="@+id/upper"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="39dp"
        android:hint="Heslo" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:singleLine="false" />

</RelativeLayout>

styles.xml

<resources>
    <!-- inherit from the material theme -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Main theme colors -->
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:textColorPrimary">#fff</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#CA0700</item>
    </style>

</resources>

谢谢

【问题讨论】:

  • logcat 在哪里?
  • 发布 logcat。也提供java代码。
  • 这是我的第一个应用程序,所以我不知道有任何 logcat 工具,所以现在我看到它说“RuntimeException:无法启动活动 ComponentInfo{wstrends.brana/wstrends.brana.MainActivity}: java.lang.IllegalStateException:您需要在此活动中使用 Theme.AppCompat 主题(或后代)。” .. 现在我知道我做错了什么,谢谢大家 ;).. 对于 logcat 提示

标签: android xml crash


【解决方案1】:

尝试将您的styles.xml 更改为以下内容。主题必须是Theme.AppCompat的后代:

<resources>

    <!-- inherit from the material theme -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Main theme colors -->
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item> <!-- For support lib compat -->
        <item name="android:textColorPrimary">#fff</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#CA0700</item>
    </style>

</resources>

【讨论】:

  • 您好,感谢您的回复,查看我找到的解决方案
  • 试过这个解决方案,我想出了错误:错误:检索项目的父项时出错:找不到与给定名称匹配的资源 'android:Theme.AppCompat.Light.DarkActionBar'。
  • @Jkr 我假设您在错误消息中使用 API 21 (Lollipop),但如果您不是,那么您将没有该资源。我的错。
  • 我让它与 ICS 兼容,我不知道是否每个将使用它的人都有 Lollipop 或更高版本。无论如何感谢您的提示!
  • @Jkr 如果你决定走这条路,你可以使用v7-support library 来保持向后兼容性并获得许多新的棒棒糖功能。
【解决方案2】:

解决方案:

styles.xml 没有任何变化,但 MainActivity.java 中的一些变化修复了这个问题

public class MainActivity extends ActionBarActivitypublic class MainActivity extends Activity

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多