Android 无法解析方法getSupportFragmentManager

Android 无法解析方法getSupportFragmentManager,android,Android,这里我得到了一个错误:“无法解析方法getSupportFragmentManager”,尽管我已经为它添加了import语句。我似乎不明白这个问题。有人能帮忙吗 代码如下: package com.example.veeresh.parsegeo; import android.content.Context; import android.view.View; import android.view.animation.Animation; import android.view.anima

这里我得到了一个错误:“无法解析方法getSupportFragmentManager”,尽管我已经为它添加了import语句。我似乎不明白这个问题。有人能帮忙吗

代码如下:

package com.example.veeresh.parsegeo;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class AgentsDropdownOnItemClickListener  implements OnItemClickListener {
public String selectedItemTag;

public GoogleMap mMap;
MapsActivity agent = new MapsActivity();

@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {


    Context mContext = v.getContext();
    MapsActivity mainActivity = ((MapsActivity) mContext);


    Animation fadeInAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_in);
    fadeInAnimation.setDuration(10);
    v.startAnimation(fadeInAnimation);


    mainActivity.popupWindowDogs.dismiss();



    selectedItemTag = ((TextView) v).getTag().toString();
    if ( selectedItemTag.equals("VISA")) {
        Toast.makeText(mContext, "Agent ID is: ", Toast.LENGTH_SHORT).show();
        if (mMap == null) {
                        // Try to obtain the map from the SupportMapFragment.
                        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                                .getMap();
                        // Check if we were successful in obtaining the map.
                        if (mMap != null) {
                           agent.setUpMapVisa();
                        }
                    }
        mMap.clear();
        agent.setUpMapAadhar();
    }



}

}
package com.example.veeresh.parsegeo;
导入android.content.Context;
导入android.view.view;
导入android.view.animation.animation;
导入android.view.animation.AnimationUtils;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.SupportMapFragment;
公共类代理DropDownonicClickListener实现了OnItemClickListener{
公共字符串selectedItemTag;
公共谷歌地图;
MapsActivity代理=新的MapsActivity();
@凌驾
公共视图单击(AdapterView arg0,视图v,内部arg2,长arg3){
Context mContext=v.getContext();
MapsActivity mainActivity=((MapsActivity)mContext);
Animation fadeInAnimation=AnimationUtils.loadAnimation(v.getContext(),android.R.anim.fade_-in);
设定持续时间(10);
v、 startAnimation(fadeInAnimation);
mainActivity.popupWindowDogs.Disclose();
selectedItemTag=((TextView)v.getTag().toString();
如果(选择EditemTag.equals(“VISA”)){
Toast.makeText(mContext,“代理ID为:”,Toast.LENGTH_SHORT.show();
如果(mMap==null){
//尝试从SupportMapFragment获取映射。
mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
//检查我们是否成功获得地图。
如果(mMap!=null){
agent.setUpMapVisa();
}
}
mMap.clear();
agent.setUpMapAadhar();
}
}
}

您应该为该类扩展
碎片活动
。按下面的方法做

public class AgentsDropdownOnItemClickListener extends FragmentActivity  implements OnItemClickListener{

有关更多信息,请参见。

您应该为该类扩展
片段活动。按下面的方法做

public class AgentsDropdownOnItemClickListener extends FragmentActivity  implements OnItemClickListener{

有关更多信息,请参阅。

您显然没有显示整个活动

在任何情况下,您都应该确保实际包含映射的活动是您请求从中查找视图的活动

这意味着: 如果地图视图位于“MapsACtivity”中,您应该这样写:

mMap = ((SupportMapFragment) mainActivity.getSupportFragmentManager().findFragmentById(R.id.map))
                            .getMap();
当然,还要确保mainActivity扩展了FragmentActivity


可以找到有关findViewByID的更多信息。

您显然没有显示整个活动

在任何情况下,您都应该确保实际包含映射的活动是您请求从中查找视图的活动

这意味着: 如果地图视图位于“MapsACtivity”中,您应该这样写:

mMap = ((SupportMapFragment) mainActivity.getSupportFragmentManager().findFragmentById(R.id.map))
                            .getMap();
当然,还要确保mainActivity扩展了FragmentActivity


可以找到有关findViewByID的更多信息。

尝试代替
公共类MainActivity扩展活动

public class MainActivity扩展了FragmentActivity

还要检查并确保导入SupportLibrary,如:

import android.support.v4.app.Fragment;

现在,您可以使用
getSupportFragmentManager()

尝试代替
公共类MainActivity extends Activity

public class MainActivity扩展了FragmentActivity

还要检查并确保导入SupportLibrary,如:

import android.support.v4.app.Fragment;

现在,您可以使用
getSupportFragmentManager()

尝试为classYay扩展FragmentActivity,这解决了无法解决的问题。现在我得到一个空指针异常:mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();最大的问题。。。你为什么要在自己的类中声明一个侦听器?我没有让你@internal_class7你不需要创建一个单独的类来声明一个侦听器你可以在你的活动中创建它,而不是在它自己的活动中尝试为类扩展FragmentActivity,这解决了无法解决的问题。现在我得到一个空指针异常:mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();最大的问题。。。为什么要在自己的类中声明一个侦听器?我没有得到@internal_class7您不需要创建单独的类来声明一个侦听器您可以在您的活动中创建它,而不是在它自己的活动中创建它您没有加载任何视图..声明的片段在哪里?我指的是xml文件..现在我得到一个空指针异常:mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();–它被设置为另一个java类的布局。您没有加载任何视图。声明的片段在哪里?我指的是xml文件..现在我得到一个空指针异常:mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();–它被设置为另一个java类的布局