这里的问题很简单,但是我遇到了运行时错误,如下所示:
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
我以前遇到过这个问题,我的直觉是它可能与库有关,但我不确定。我知道这里有很多这样的问题,但它们非常具体。我只是想知道我的代码是否有任何问题。感谢您的帮助!
我的主要活动文件(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"/>