Fra*_*lne 11 android google-maps android-2.3-gingerbread
我在这里找到了一些关于这个问题的问题,但他们的答案似乎并不适用于我的项目是引用包含该类的库.这是我的代码:
package com.demo.app;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
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.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class Mapview extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GPSTracker gps = new GPSTracker(Mapview.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
// \n is for new line
// Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
}
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
GoogleMap mMap;
mMap = ((MapFragment) getSupportFragmentManager().findFragmentById(android.R.id.content)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
}
}
Run Code Online (Sandbox Code Playgroud)
所以你可以看到我在导入中引用了Fragment库,Eclipse没有抛出任何错误,所以它似乎承认它存在.在下图中,您可以看到我的eclipse项目显示了引用的库.在其中,您可以看到具有findFragmentById()的FragmentManager类.我还发现了其他类似的方式.因此,总结一下,我在lib文件夹中有了库,并且它们被eclipse确认并且在代码中没有出现错误,但是由于错误导致包不会导出,并且唯一的错误是在此代码旁边的第一行" p"在包中声明:'android.app.Fragment类型无法解析.它是从所需的.class文件间接引用的
有任何想法吗?
我确实尝试了几次清理和重建路径.
Joe*_*son 27
尝试改变
mMap = ((MapFragment) getSupportFragmentManager().findFragmentById(android.R.id.content)).getMap();
Run Code Online (Sandbox Code Playgroud)
至
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(android.R.id.content)).getMap();
Run Code Online (Sandbox Code Playgroud)
您必须运行Android的预ICS版本,并且您正在使用"MapFragment",它使用内置版本的Fragments而不是支持库版本.