【问题标题】:ANDROID : Failed to resolve attribute at index 13ANDROID:无法解析索引 13 处的属性
【发布时间】:2016-02-24 05:58:40
【问题描述】:

---->> java.lang.RuntimeException:无法启动活动 ComponentInfo{sharedpreferenceex.app.htc.com.listview_lv/sharedpreferenceex.app.htc.com.listview_lv.MyGrid}:android.view.InflateException:二进制 XML 文件第 44 行:膨胀类 com.android.internal.widget.ActionBarContextView 时出错

---->>引起:android.view.InflateException: Binary XML file line #44: Error inflating class com.android.internal.widget.ActionBarContextView

---->>引起:java.lang.reflect.InvocationTargetException

---->>Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13

我正面临上述三个异常。我只是想运行一个应用程序以在活动中显示文本视图。这些异常到达活动本身的 onCreate 方法。

我也查看了所有的 stackoverflow 答案,但无法找出问题所在。

我的清单.xml

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

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

    <activity
        android:name=".MyGrid"
        android:label="@string/title_activity_my_grid" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

活动 xml

 <LinearLayout 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" >


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:textSize="25dp"
    android:id="@+id/tv_example" />

活动代码

public class MyGrid extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_grid);
}

@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_my_grid, 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);
}

}

【问题讨论】:

  • 你能添加你的主题吗? (只是为了检查您是否没有使用没有 actionBar 的主题)
  • 我换了主题,效果很好。

标签: android


【解决方案1】:

我想通了。 我使用的移动设备不支持我在程序中使用的主题(Styles.xml)。 根据设备更改主题。 在 styles.xml 中设置错误的主题是导致这些异常的原因。

【讨论】:

    【解决方案2】:

    对我来说,这是通过切换到 AndroidX 并打开 jetifier 触发的。解决方法:将应用主题中的Theme.AppCompat改为Theme.MaterialComponents

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 2019-10-10
      • 1970-01-01
      • 2021-11-03
      相关资源
      最近更新 更多