谷歌地图v2,缺少'android.support.v4.app.FragmentActivity'

时间:2014-04-30 12:48:34

标签: android google-maps

我的问题:

  • 安装活动后,LogCat中有错误消息(找不到类“android.support.v4.app.FragmentActivity”),但我没有使用FragmentActivity,应用程序运行没有问题。
  • 我的设备:GT-I8190Android 4.1.2

logcat的:

04-30 13:55:46.294: E/dalvikvm(7011): Could not find class 'android.support.v4.app.FragmentActivity',
 referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-30 13:55:46.294: W/dalvikvm(7011): VFY: unable to resolve instanceof 135 (Landroid/support/v4/app/FragmentActivity;)
 in Lcom/google/android/gms/common/GooglePlayServicesUtil;
04-30 13:55:46.294: D/dalvikvm(7011): VFY: replacing opcode 0x20 at 0x0008
04-30 13:55:46.294: E/dalvikvm(7011): Could not find class 'android.support.v4.app.FragmentActivity',
 referenced from method com.google.android.gms.common.GooglePlayServicesUtil.showErrorDialogFragment
04-30 13:55:46.294: W/dalvikvm(7011): VFY: unable to resolve check-cast 135 (Landroid/support/v4/app/FragmentActivity;)
 in Lcom/google/android/gms/common/GooglePlayServicesUtil;
04-30 13:55:46.294: D/dalvikvm(7011): VFY: replacing opcode 0x1f at 0x000c
04-30 13:55:46.474: D/dalvikvm(7011): GC_CONCURRENT freed 192K, 11% free 9604K/10759K, paused 20ms+3ms, total 72ms
04-30 13:55:46.474: D/dalvikvm(7011): WAIT_FOR_CONCURRENT_GC blocked 33ms
04-30 13:55:46.524: I/Google Maps Android API(7011): Google Play services client version: 4323000
04-30 13:55:46.534: I/Google Maps Android API(7011): Google Play services package version: 4325034

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.thomaskuenneth.examples"
    android:versionCode="1"
    android:versionName="1.0" >
    <!-- Original: beide Werte=17 -->
    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="17" />
    <permission
        android:name="com.thomaskuenneth.examples.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-permission android:name="com.thomaskuenneth.examples.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.thomaskuenneth.examples.MenuActivity2"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyATuuvskBPfu2A7EsrzQwDZYmVu8w0zZi8" />
    </application>
</manifest>

的活动:

package com.thomaskuenneth.examples;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MenuActivity2 extends Activity {
    private static final String TAG = MenuActivity2.class.getSimpleName(); 
    private LocationManager manager;
    private GoogleMap map;
    String sarr[] = {"Hamburg","53.558","9.927","Nürnberg","049:27","011:05",
            "Schochwitz","051:31:47","011:44:46","Bern","46.9466","7.44412",
            "Berlin","52.518611","13.376111","Wien","48.208031","16.358128",
            "Leipzig"," 51.340333","12.374751","Kalkutta","22:32:36","88:20:3"};
    int ortInd = 0;
    LatLng lalo;
    String ort="";
    LocationListener listener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        // get Location Manager
      manager = (LocationManager) getSystemService(LOCATION_SERVICE);
      map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        String message="";
        if (map == null) {
            message="No map created";
            Toast.makeText(MenuActivity2.this, message, Toast.LENGTH_LONG).show();
            return;
        }
        message="Map created !!!";
        Toast.makeText(MenuActivity2.this, message, Toast.LENGTH_LONG).show();
    }
    void showmap() {
        //set marker, title only on touch on marker
        map.addMarker(new MarkerOptions().position(lalo).title(ort+"X"));
        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(lalo, 15));
        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }
    @Override
    protected void onResume() {
      super.onResume();
//    getAllPrv();
    }
    @Override
    protected void onPause() {
      super.onPause();
      if (manager != null && listener != null)
        manager.removeUpdates(listener);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_menu, menu);
        return true;
    }
    void bestIndex(String s) {
      ortInd = -1;
      for (int i = 0; i<sarr.length; i+=3) {
          if (sarr[i].equalsIgnoreCase(s)) {
            ortInd = i;
            lalo = new LatLng(Location.convert(sarr[ortInd+1]),
                    Location.convert(sarr[ortInd+2]));
            showmap();
            break;
          }
      }
    }
  public boolean onOptionsItemSelected(MenuItem item) {
    String s="";
    switch (item.getItemId()) {
      default:
        s = (String) item.getTitle();
//          Toast.makeText(MenuActivity.this, s, Toast.LENGTH_SHORT).show();
        bestIndex(s);
    }
        return false;

  }
}

我正在寻找这些消息的解释。请帮帮我。

关心Wicki

2 个答案:

答案 0 :(得分:2)

这些消息实际上只是警告虚拟机(Dalvik)发现了对FragmentActivity类的一些引用,但它无法找到该类的定义。只要您的代码不会导致引用FragmentActivity的代码执行,您就没有问题。如果您要执行该代码,您的应用程序将崩溃。

答案 1 :(得分:2)

你在项目lib文件夹

中有android-support-v4.jar吗?

如果没有&#34; 图书馆&#34;文件夹然后创建一个

然后点击

Project> Android Tools >Add support Library.

这会对你有所帮助。最后清理项目并重启Eclipse