这是MyFragmentPagerAdapter类,它在返回myFragment时找到了FragmentPagerAdapter.Error.
public class MyFragmentPagerAdapter extends FragmentPagerAdapter{
final int PAGE_COUNT = 11;
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int arg0) {
CountryDetailsFragment myFragment = new CountryDetailsFragment();
Bundle data = new Bundle();
data.putInt("current_page", arg0+1);
myFragment.setArguments(data);
return myFragment;<----error is shown here.
}
@Override
public int getCount() {
return PAGE_COUNT;
}
My CountryDetailsFragment如下。它扩展了Fragment,我已将2个textviews填充到视图寻呼机中,如下所示。
public class CountryDetailsFragment extends Fragment{
int mCurrentPage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPage = data.getInt("current_page", 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.country_details_fragment_layout, null);
ViewPager pager = (ViewPager) v.findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager(); <---Here the error is shown for getSupportFragmentManager()
MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(fm);
pager.setAdapter(pagerAdapter);
TextView tv = (TextView) v.findViewById(R.id.country_details);
TextView details = (TextView) v.findViewById(R.id.country_details_more);
Bundle b = getArguments();
tv.setText("Details of " + Country.name[b.getInt("position")]);
details.setText(Country.details[b.getInt("position")]);
return v;
}
Stacktrace如下
03-03 05:15:31.093:E / AndroidRuntime(910):致命异常:主要 03-03 05:15:31.093:E / AndroidRuntime(910):android.content.ActivityNotFoundException:找不到处理Intent的活动{act = com.example.simplelistdetail.CountryDetailsActivity(has extras)} 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.Activity.startActivityForResult(Activity.java:3390) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.Activity.startActivityForResult(Activity.java:3351) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.Activity.startActivity(Activity.java:3587) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.Activity.startActivity(Activity.java:3555) 03-03 05:15:31.093:E / AndroidRuntime(910):at com.example.simplelistdetail.MainActivity.onListFragmentItemClick(MainActivity.java:62) 03-03 05:15:31.093:E / AndroidRuntime(910):at com.example.simplelistdetail.CountryListFragment.onListItemClick(CountryListFragment.java:48) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.ListFragment $ 2.onItemClick(ListFragment.java:160) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.widget.AdapterView.performItemClick(AdapterView.java:298) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.widget.AbsListView.performItemClick(AbsListView.java:1100) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.widget.AbsListView $ PerformClick.run(AbsListView.java:2788) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.widget.AbsListView $ 1.run(AbsListView.java:3463) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.os.Handler.handleCallback(Handler.java:730) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.os.Handler.dispatchMessage(Handler.java:92) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.os.Looper.loop(Looper.java:137) 03-03 05:15:31.093:E / AndroidRuntime(910):在android.app.ActivityThread.main(ActivityThread.java:5103) 03-03 05:15:31.093:E / AndroidRuntime(910):at java.lang.reflect.Method.invokeNative(Native Method) 03-03 05:15:31.093:E / AndroidRuntime(910):at java.lang.reflect.Method.invoke(Method.java:525) 03-03 05:15:31.093:E / AndroidRuntime(910):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 03-03 05:15:31.093:E / AndroidRuntime(910):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 03-03 05:15:31.093:E / AndroidRuntime(910):at dalvik.system.NativeStart.main(Native Method) 03-03 05:15:33.582:I / Process(910):发送信号。 PID:910 SIG:9
答案 0 :(得分:0)
如果CountryDetailsFragment
延长Fragment
,则问题不应退出。仍然可能是您正在混合framework
和support library
的导入。在
android.support.v4.Fragment
或
android.app.Fragment