gpt4 book ai didi

android - 在 android 中使用 getfragmentmanager() 时出现 "No such method error"

转载 作者:行者123 更新时间:2023-11-29 21:53:45 24 4
gpt4 key购买 nike

在我的应用程序中,我使用对话框 fragment 作为启动画面。因此它会在应用程序启动时显示启动画面。当我在低于 android 版本 3 的设备上运行该应用程序时,它显示类似“No such method error:getFragmentManager”的错误。我已经看到它可以通过使用 getSupportFragmentManager()。但是当我使用它时,启动对话框没有显示。请有人帮助我..提前致谢...

主要 Activity =>

        ft = getFragmentManager().beginTransaction(); //Here I am using getFragmentManager
newFragment = SplashDialogFragment.newInstance();
newFragment.show(MainActivity.ft, "dialog");

这是我的启动画面 fragment =>

public class SplashDialogFragment extends DialogFragment {

private EditText mEditText;


static SplashDialogFragment newInstance() {
SplashDialogFragment f = new SplashDialogFragment();
return f;
}
public void EditNameDialog() {
// Empty constructor required for DialogFragment
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.splash_fragment, container);


return view;
}

public void show(FragmentManager supportFragmentManager, String string) {
// TODO Auto-generated method stub


}


}

和错误日志=>

 > 12-07 11:09:09.330: E/AndroidRuntime(628): FATAL EXCEPTION: main
12-07 11:09:09.330: E/AndroidRuntime(628): java.lang.NoSuchMethodError: com.myapp.mlm.MainActivity.getFragmentManager
12-07 11:09:09.330: E/AndroidRuntime(628): at com.madhyamam.malayalam2.MainActivity.onCreate(MainActivity.java:103)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.os.Handler.dispatchMessage(Handler.java:99)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.os.Looper.loop(Looper.java:123)
12-07 11:09:09.330: E/AndroidRuntime(628): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-07 11:09:09.330: E/AndroidRuntime(628): at java.lang.reflect.Method.invokeNative(Native Method)
12-07 11:09:09.330: E/AndroidRuntime(628): at java.lang.reflect.Method.invoke(Method.java:507)
12-07 11:09:09.330: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-07 11:09:09.330: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-07 11:09:09.330: E/AndroidRuntime(628): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我通过将 MainActivity 扩展到 FragmentActivity 解决了这个问题。以前它是扩展 Activity。之后我使用 getSupportFragmentManager 没有任何问题。

关于android - 在 android 中使用 getfragmentmanager() 时出现 "No such method error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13757611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com