java - 运行时错误: inflating class

标签 java android eclipse maps

这里的问题很简单,但我遇到了运行时错误,如下所示:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maptest/com.example.maptest.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

我以前遇到过这个问题,我的直觉是它可能与库有关,但我不确定。我知道这里有很多类似的问题,但它们都是针对具体情况的。我只是想知道我的代码是否有任何问题。我感谢您的帮助!

我的主要 Activity 文件(MainActivity.java)是:

package com.example.maptest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;  
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {

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

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

private static final int ACTIVITY_CREATE = 0;

private void configureSettings() {
    Intent intent = new Intent(this, ConfigureSyncActivity.class);
    startActivityForResult(intent, ACTIVITY_CREATE);
}

private void setLimits() {
    Intent intent = new Intent(this, SetLimitsActivity.class);
    startActivityForResult(intent, ACTIVITY_CREATE);
}

private void violations() {
    Intent intent = new Intent(this, ViolationsActivity.class);
    startActivityForResult(intent, ACTIVITY_CREATE);
}

@Override
public boolean onOptionsItemSelected(MenuItem item){

    switch(item.getItemId()) {

    case R.id.limits:
        setLimits();
        return true;

    case R.id.sync:
        configureSettings();
        return true;

    case R.id.violations:
        violations();
        return true;


    }
    return super.onOptionsItemSelected(item);
}

}

最后但并非最不重要的是,我的 xml 布局文件:

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

最佳答案

尝试在 xml 布局文件中进行以下更改。它对我有用:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"/>

如果这不起作用,请尝试检查类名层次结构。

关于java - 运行时错误: inflating class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14946397/

相关文章:

android - 如何使用 JNI 代码正确导入 Android 库?

java - 使用 JFileChooser 设置默认保存扩展

android - 索尼 Z3 平板电脑紧凑型内核编译错误 - board-8974-gpiomux.c - 'gpio_spi_config'

android - 在 Kotlin 中使用新参数的分页 3.0 列表

java - 在 JFrame 上制作网格并用随机颜色填充

Eclipse ctrl+Shift+G 未按预期工作

java - 关于整数比较的澄清?

java - java无效归并排序方法

java - 将 jar 文件安装到 Maven 构建中的特定位置

android - libgdx AndroidApplication 类