我正在开发一个需要以下4个项目库的Android应用程序:SDK Facebook,Google Play服务(用于显示地图)AndroidBootstrap和android-support-v7-appcompat。
我将它们作为现有Android项目导入,在我的工作区中复制它们并添加到我的项目中:(在Eclipse中,项目上的右键 - >属性 - > Android - > Add .. .Like this :
我在Java Build Path中添加了我需要的其他库,如ormlite。
所有项目都正常工作,包括显示地图的活动,但突然间,此活动停止工作,发出以下错误,它再也没有用过:
错误
03-16 13:57:18.311: E/AndroidRuntime(3089): FATAL EXCEPTION: main
03-16 13:57:18.311: E/AndroidRuntime(3089): Process: com.bora, PID: 3089
03-16 13:57:18.311: E/AndroidRuntime(3089): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bora/com.bora.MenuPrincipalMapViewActivity}: android.view.InflateException: Binary XML file line #57: Error inflating class fragment
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.os.Looper.loop(Looper.java:135)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.reflect.Method.invoke(Native Method)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.reflect.Method.invoke(Method.java:372)
03-16 13:57:18.311: E/AndroidRuntime(3089): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-16 13:57:18.311: E/AndroidRuntime(3089): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-16 13:57:18.311: E/AndroidRuntime(3089): Caused by: android.view.InflateException: Binary XML file line #57: Error inflating class fragment
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
03-16 13:57:18.311: E/AndroidRuntime(3089): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Activity.setContentView(Activity.java:2144)
03-16 13:57:18.311: E/AndroidRuntime(3089): at com.bora.MenuPrincipalMapViewActivity.onCreate(MenuPrincipalMapViewActivity.java:31)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Activity.performCreate(Activity.java:5933)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
03-16 13:57:18.311: E/AndroidRuntime(3089): ... 10 more
03-16 13:57:18.311: E/AndroidRuntime(3089): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Fragment.instantiate(Fragment.java:618)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Fragment.instantiate(Fragment.java:582)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2108)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Activity.onCreateView(Activity.java:5282)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
03-16 13:57:18.311: E/AndroidRuntime(3089): ... 21 more
03-16 13:57:18.311: E/AndroidRuntime(3089): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.bora-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
03-16 13:57:18.311: E/AndroidRuntime(3089): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
03-16 13:57:18.311: E/AndroidRuntime(3089): at android.app.Fragment.instantiate(Fragment.java:604)
03-16 13:57:18.311: E/AndroidRuntime(3089): ... 25 more
03-16 13:57:18.311: E/AndroidRuntime(3089): Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.Class.classForName(Native Method)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
03-16 13:57:18.311: E/AndroidRuntime(3089): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
03-16 13:57:18.311: E/AndroidRuntime(3089): ... 27 more
03-16 13:57:18.311: E/AndroidRuntime(3089): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
03-16 13:57:18.336: W/ActivityManager(498): Force finishing activity com.bora/.MenuPrincipalMapViewActivity
以下是引用地图的所有文件:
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bora"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.bora.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.bora.SplashFragment" android:screenOrientation="portrait" android:label="@string/app_name"
>
</activity>
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<activity android:name="com.bora.MenuPrincipalListViewActivity" android:screenOrientation="portrait" android:label="@string/app_name"/>
<activity android:name="com.bora.MenuPrincipalMapViewActivity" android:screenOrientation="portrait" android:label="@string/app_name"/>
<activity android:name="com.bora.SplashRapidoActivity" android:screenOrientation="portrait" android:label="@string/app_name"/>
<activity android:name="com.bora.DialogBusqueda" android:screenOrientation="portrait"
android:label="@string/app_name" android:theme="@style/dialog_light"/>
<!-- android:theme="@android:style/Theme.Holo.Light.Dialog" -->
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY" android:value="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
R.layout.menuprincipal_map_view :
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".MenuPrincipalMapViewActivity"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="3" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center"
>
<Button
android:id="@+id/button_event_list"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@color/Aqua"
android:text="Eventos"
android:textStyle="normal"
android:textColor="@color/gris_letra"
android:gravity="center"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center"
>
<Button
android:id="@+id/button_map"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:text="Mapa!"
android:textStyle="bold"
android:textColor="@color/Aqua"
android:gravity="center"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="3" >
<Button
android:id="@+id/button_search"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:text="@string/simbolo_buscar"
android:textStyle="bold"
android:textColor="@color/gris_letra"
android:gravity="center"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1">
<Button
android:id="@+id/button_search_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>
这里是 MenuPrincipalMapViewActivity :
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import com.bora.database.DatabaseManager;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
公共类MenuPrincipalMapViewActivity扩展android.support.v4.app.FragmentActivity {
Button Eventos, Buscar;
// SupportMapFragment Mapa;
DatabaseManager mDatabaseManager;
MapFragment mapFragment;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.menuprincipal_map_view);
mDatabaseManager = new DatabaseManager(getApplicationContext());
Eventos = (Button) findViewById(R.id.button_event_list);
Buscar = (Button) findViewById(R.id.button_search);
// Mapa = (SupportMapFragment) ((FragmentActivity) getApplicationContext()).getSupportFragmentManager().findFragmentById( R.id.map);
Buscar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog();
}
});
if(!mDatabaseManager.Busqueda_actualExists() || !mDatabaseManager.BusquedaisUpdated())
{
showDialog();
}
Eventos.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),MenuPrincipalListViewActivity.class);
startActivity(i);
}
});
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
// if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
// mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
// mapFragment.getMapAsync(this);
// Check if we were successful in obtaining the map.
// if (mMap != null) {
// setUpMap();
// }
// }
mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker"));
setUpMap();
}
});
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
/*@Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker"));
}*/
public void showDialog()
{
Intent intent=new Intent(this, DialogBusqueda.class);
startActivity(intent);
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
}
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
@Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker"));
}
public void showDialog()
{
Intent intent=new Intent(this, DialogBusqueda.class);
startActivity(intent);
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
}
所以,这就是问题,如果我在Build Java Path中检查这些库中的任何一个(下图中的红色圆圈)Eclipse块显示内部问题:&#34;无法执行dex:GC开销限制超出GC超出限额&#34;。请注意,我已使用信息here更改了我的eclipse.ini
以解决潜在错误(我读到可能是因为循环创建了相同库的不同版本而导致此错误)。
如果我不检查这些库,则会显示第一个 ERROR 。
所以,我认为,可能是android-support-v4.jar
库的问题,因为AndroidBootstrap,SDK Facebook,android-support-v7-appcompat和我的项目有不同版本的android-support-v4.jar
。< / p>
我做了什么:
0 - 我复制了myproject / lib中的google-play-services.jar
并在Java Build Path中引用了它 - &gt;图书馆 - &gt;添加JAR(没有结果,所以我从项目中删除了它。)
1 - 我复制了最后一个版本(位于android-support-v7-appcompat/lib
)并粘贴在AndroidBootstrap的/lib
文件夹,SDK Facebook和我自己的项目中。
2 - 我在一些帖子中读到可能存在问题的是来自这些库和项目的AndroidTarget,因此,我将所有目标(从库和项目)更改为同一个Google APIs 22
。
3 - 我清理并重建所有这些。
问题仍然存在。
因此,我尝试卸载google-play-services并从AndroidSDK重新安装,但没有结果。
我尝试创建一个新的工作区,再次执行所有步骤,但没有任何效果。
有趣的是,一开始所有工作都正常,包括地图。
有什么想法吗?