gpt4 book ai didi

android - 使用 android.support.v4.app.FragmentActivity.getActionBar 时为 “No such method error”

转载 作者:太空狗 更新时间:2023-10-29 15:30:42 25 4
gpt4 key购买 nike

我正在 Gingerbread 中尝试抽屉导航一切正常。当我单击导航菜单时出现此异常。我添加了所有库、主题、抽屉列表。实际上我需要 fragment 中的 getsupportActionBar() 所以我怎样才能得到它请帮助我。

代码:

public class RiverFragment extends Fragment{


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

// Retrieving the currently selected item number
int position = getArguments().getInt("position");

// List of rivers
String[] rivers = getResources().getStringArray(R.array.rivers);

// Creating view correspoding to the fragment
View v = inflater.inflate(R.layout.fragment_layout, container, false);

// Getting reference to the TextView of the Fragment
TextView tv = (TextView) v.findViewById(R.id.tv_content);

// Setting currently selected river name in the TextView
tv.setText(rivers[position]);

// Updating the action bar title
getActivity().getActionBar().setTitle(rivers[position]);


return v;
}
}

异常(exception):

01-04 11:47:21.601: E/AndroidRuntime(20537): FATAL EXCEPTION: main
01-04 11:47:21.601: E/AndroidRuntime(20537): java.lang.NoSuchMethodError: android.support.v4.app.FragmentActivity.getActionBar
01-04 11:47:21.601: E/AndroidRuntime(20537): at in.wptrafficanalyzer.navigationdrawerdemo.RiverFragment.onCreateView(RiverFragment.java:36)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.os.Handler.handleCallback(Handler.java:587)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.os.Handler.dispatchMessage(Handler.java:92)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.os.Looper.loop(Looper.java:130)
01-04 11:47:21.601: E/AndroidRuntime(20537): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-04 11:47:21.601: E/AndroidRuntime(20537): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 11:47:21.601: E/AndroidRuntime(20537): at java.lang.reflect.Method.invoke(Method.java:507)
01-04 11:47:21.601: E/AndroidRuntime(20537): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-04 11:47:21.601: E/AndroidRuntime(20537): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-04 11:47:21.601: E/AndroidRuntime(20537): at dalvik.system.NativeStart.main(Native Method)

最佳答案

您的 Activity 必须扩展 ActionBarActivity而不是 FragmentActivity(请注意 ActionBarActivity 扩展了 FragmentActivity - 它只是通过 getSupportActionBar() 添加了对操作栏的支持).

关于android - 使用 android.support.v4.app.FragmentActivity.getActionBar 时为 “No such method error”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20917759/

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