来自父类
Bundle bundle=new Bundle();
bundle.putStringArray("img_array", array);
for(int i=0;i<array.length;i++)
{
System.out.println("this is from arrayy...."+array[i]);//this gives me value
}
fragment = new Frag2 ();
fragment.setArguments(bundle);
这是目标类
public class Frag2 extends Fragment {
public View onCreateView(LayoutInflater inflater,
ViewGroup containerObject,
Bundle savedInstanceState){
//here is your arguments
Bundle bundle=getArguments();
//here is your list array
String[] myStrings=bundle.getStringArray("img_array");
System.out.println("this is len"+myStrings.length);//this STATMENT NOT WORKING
}
}
这是我的logcat:
03-28 08:47:49.377: E/memtrack(24381): Couldn't load memtrack module (No such file or directory)
03-28 08:47:49.377: E/android.os.Debug(24381): failed to load memtrack module: -2
03-28 08:47:50.067: E/libEGL(50): called unimplemented OpenGL ES API
03-28 08:47:50.067: E/libEGL(50): called unimplemented OpenGL ES API
03-28 08:47:50.067: E/libEGL(50): called unimplemented OpenGL ES API
03-28 08:47:50.077: E/libEGL(50): called unimplemented OpenGL ES API
03-28 08:47:50.077: E/SurfaceFlinger(50): glCheckFramebufferStatusOES error -443628859
03-28 08:47:50.077: E/SurfaceFlinger(50): got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot
03-28 08:47:50.077: E/libEGL(50): called unimplemented OpenGL ES API
03-28 08:47:50.077: E/libEGL(50): called unimplemented OpenGL ES API
03-28 08:47:53.257: E/AndroidRuntime(24396): FATAL EXCEPTION: main
03-28 08:47:53.257: E/AndroidRuntime(24396): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.leeway.hdwallpapers/com.leeway.hdwallpapers.HD_Walllpaper_Activity}: java.lang.NullPointerException
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.os.Handler.dispatchMessage(Handler.java:102)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.os.Looper.loop(Looper.java:136)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-28 08:47:53.257: E/AndroidRuntime(24396): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 08:47:53.257: E/AndroidRuntime(24396): at java.lang.reflect.Method.invoke(Method.java:515)
03-28 08:47:53.257: E/AndroidRuntime(24396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-28 08:47:53.257: E/AndroidRuntime(24396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-28 08:47:53.257: E/AndroidRuntime(24396): at dalvik.system.NativeStart.main(Native Method)
03-28 08:47:53.257: E/AndroidRuntime(24396): Caused by: java.lang.NullPointerException
03-28 08:47:53.257: E/AndroidRuntime(24396): at com.leeway.hdwallpapers.Frag2 .onCreateView(Frag2 .java:37)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.Activity.performStart(Activity.java:5241)
03-28 08:47:53.257: E/AndroidRuntime(24396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
03-28 08:47:53.257: E/AndroidRuntime(24396): ... 11 more
03-28 08:47:54.797: E/SoundPool(384): error loading /system/media/audio/ui/Effect_Tick.ogg
03-28 08:47:54.807: E/SoundPool(384): error loading /system/media/audio/ui/Effect_Tick.ogg
03-28 08:47:54.807: E/SoundPool(384): error loading /system/media/audio/ui/Effect_Tick.ogg
03-28 08:47:54.827: E/SoundPool(384): error loading /system/media/audio/ui/Effect_Tick.ogg
03-28 08:47:54.837: E/SoundPool(384): error loading /system/media/audio/ui/Effect_Tick.ogg
03-28 08:47:54.837: E/SoundPool(384): error loading /system/media/audio/ui/KeypressStandard.ogg
03-28 08:47:54.837: E/SoundPool(384): error loading /system/media/audio/ui/KeypressSpacebar.ogg
03-28 08:47:54.837: E/SoundPool(384): error loading /system/media/audio/ui/KeypressDelete.ogg
03-28 08:47:54.847: E/SoundPool(384): error loading /system/media/audio/ui/KeypressReturn.ogg
03-28 08:47:54.847: E/SoundPool(384): error loading /system/media/audio/ui/KeypressInvalid.ogg
03-28 08:47:55.017: E/InputDispatcher(384): channel 'b53c0eb0 com.leeway.hdwallpapers/com.leeway.hdwallpapers.HD_Walllpaper_Activity (server)' ~ Channel is unrecoverably broken and will be disposed!
答案 0 :(得分:0)
请勿将图像捆绑在一起。不要使用System.out.println()。使用记录器。
在你的代码中,whee是声明的img_array变量吗?你确定它不是空的吗?
答案 1 :(得分:0)
在onViewCreated中尝试
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Bundle bundle=getArguments();
//here is your list array
String[] myStrings=bundle.getStringArray("img_array");
System.out.println("this is len"+myStrings.length);//this STATMENT N
}