我正在做3个可以使用ViewPager片段在它们之间滑动的活动。 但是当我运行脚本时,请给我以下错误。 任何人都可以向我解释波纹管错误日志。我正在进行滑动片段活动。
07-17 14:48:29.421: W/dalvikvm(18204): threadid=1: thread exiting with uncaught exception (group=0x41723c08)
07-17 14:48:29.431: E/AndroidRuntime(18204): FATAL EXCEPTION: main
07-17 14:48:29.431: E/AndroidRuntime(18204): Process: kids.math.newmathforkids, PID: 18204
07-17 14:48:29.431: E/AndroidRuntime(18204): java.lang.NullPointerException
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:394)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:389)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:99)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:837)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.view.ViewPager.populate(ViewPager.java:987)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.View.measure(View.java:17478)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.View.measure(View.java:17478)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.View.measure(View.java:17478)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
07-17 14:48:29.431: E/AndroidRuntime(18204): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:412)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.View.measure(View.java:17478)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-17 14:48:29.431: E/AndroidRuntime(18204): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2548)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.View.measure(View.java:17478)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2285)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1396)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1595)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6624)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:812)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.Choreographer.doCallbacks(Choreographer.java:612)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.Choreographer.doFrame(Choreographer.java:582)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:798)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.os.Handler.handleCallback(Handler.java:733)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.os.Handler.dispatchMessage(Handler.java:95)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.os.Looper.loop(Looper.java:146)
07-17 14:48:29.431: E/AndroidRuntime(18204): at android.app.ActivityThread.main(ActivityThread.java:5602)
07-17 14:48:29.431: E/AndroidRuntime(18204): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 14:48:29.431: E/AndroidRuntime(18204): at java.lang.reflect.Method.invoke(Method.java:515)
07-17 14:48:29.431: E/AndroidRuntime(18204): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
07-17 14:48:29.431: E/AndroidRuntime(18204): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
07-17 14:48:29.431: E/AndroidRuntime(18204): at dalvik.system.NativeStart.main(Native Method)
07-17 14:48:29.451: W/ActivityManager(1183): Force finishing activity kids.math.newmathforkids/.level_selection
07-17 14:48:29.461: W/ActivityManager(1183): Force finishing activity kids.math.newmathforkids/.MainActivity
public class level_selection extends FragmentActivity {
MyPageAdapter pageAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.level_selection);
List<Fragment> fragments = getFragments();
pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);
}
private List<Fragment> getFragments(){
List<Fragment> fList = new ArrayList<Fragment>();
fList.add(level_selection_easy.newInstance("Fragment 1"));
fList.add(level_selection_normal.newInstance("Fragment 2"));
fList.add(level_selection_medium.newInstance("Fragment 3"));
return fList;
}
private class MyPageAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}
}
public class level_selection_easy extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.level_selection_easy, container, false);
// Create UI components here.
return v;
}
public static Fragment newInstance(String string) {
// TODO Auto-generated method stub
return null;
}
}
答案 0 :(得分:0)
public static Fragment newInstance(String string) {
// TODO Auto-generated method stub
return null; <-- Error
}
或将其更改为。
fList.add(new level_selection_easy());
fList.add(new level_selection_normal());
fList.add(new level_selection_medium());