java 找不到符号方法 getSupportFragmentManager()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27678325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:12:56  来源:igfitidea点击:

cannot find symbol method getSupportFragmentManager()

javaandroid

提问by Maven

And in main activity I have this

在主要活动中,我有这个

public void showTimePickerDialog(View v) {
    DialogFragment newFragment = new uSharedUtility.TimePickerFragment();
    newFragment.show(getSupportFragmentManager(), "timePicker");
}

But I am getting this error:

但我收到此错误:

Error:(566, 26) error: cannot find symbol method getSupportFragmentManager()

After searching I find out that I can make this go away by extending from FragmentActivity

搜索后我发现我可以通过从 FragmentActivity 扩展来消除

But currently my MainActivity is extending from public class Main extends ListActivitydue to some earlier requirements.

但目前我的 MainActivitypublic class Main extends ListActivity由于一些早期的要求而扩展。

Is there any other way I can solve this issue excepting for changing extending classes.?

除了更改扩展类之外,还有其他方法可以解决这个问题吗?

回答by Ganesh AB - Android

getSupportFragmentManager()is method of FragmentActivity. Your Parent activity should have extends FragmentActivity

getSupportFragmentManager()FragmentActivity 的方法。您的父活动应该扩展 FragmentActivity

Check this

检查这个

http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

回答by Brian Davis

There are other reasons for the same error message. You might need to instead call getFragmentManager()

相同的错误消息还有其他原因。您可能需要改为调用getFragmentManager()

As noted in the accepted answer to this related thread: Difference between Fragment And FragmentActivity

正如对此相关线程的公认答案所述: Difference between Fragment And FragmentActivity