片段参数返回NPE uriString?

时间:2014-06-08 02:41:13

标签: android android-fragments

这段代码给出了什么......

我试图使用setArguments将数据传递给片段。

这是主要活动中的代码:

      Bundle args = new Bundle();
      Log.d("channel0001", "videoScene");
            try{
            message = (JSONObject) new JSONTokener(intent.getStringExtra("message")).nextValue();
            System.out.printf("mloqooBroadcast",message);
            String incomingScene = message.getString("url");
            Log.d("mloqooBroadcast", incomingScene);
            output = incomingScene.replaceFirst("s","");
            String sceneProvider = message.getString("sceneProvider");
            if(sceneProvider.equalsIgnoreCase("loqootv") || (sceneProvider.equalsIgnoreCase("youtubeScene"))){
                Log.d("channel0001", "youtubeScene");
                sceneProvider = message.getString("sceneProvider");
                networkName = message.getString("networkName");
                networkAvatar = message.getString("networkAvatar");
                Tag1 = message.getString("sceneTag1");
                Tag3 = message.getString("sceneTag3");
                sceneLat = message.getString("sceneLat");
                sceneLong = message.getString("sceneLong");
                args.putString("sceneProvider", message.getString("sceneProvider"));
                args.putString("url", output);
                args.putString("networkName", message.getString("networkName"));
                args.putString("networkAvatar", message.getString("networkAvatar"));
                args.putString("Tag1", message.getString("sceneTag1"));
                args.putString("Tag3", message.getString("sceneTag3"));
                args.putString("sceneLat", message.getString("sceneLat"));
                args.putString("sceneLong", message.getString("sceneLong"));
                Log.d("channel0001", networkAvatar);
                Log.d("channel0001", networkName);
                Log.d("channel0001", Tag3);
                Log.d("channel0001", Tag1);
                Log.d("channel0001", output);
              }catch(JSONException e){
                System.out.printf("fScreen.IncomingScene.Error", e);    
            }
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(R.anim.enter, R.anim.exit);
            FragVideo fragVideo = new FragVideo();
            fragVideo.setArguments(args);
            fragmentTransaction.replace(R.id.pip_fragment, fragVideo, "video");
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();

这是片段中的代码:

        @Override
        public void onActivityCreated(Bundle savedInstanceState) { 
        super.onActivityCreated(savedInstanceState);
        Bundle args = getArguments();
        video = (VideoView)getView().findViewById(R.id.videoView);
    Log.d("LifeCycle.Video","FirstIntent");
        String sceneUrl = args.getString("url");    
        String sceneProvider = args.getString("sceneProvider");
        String networkName = args.getString("networkName");
        String networkAvatar = args.getString("networkAvatar");
        String sceneTag1 = args.getString("Tag1");
        String sceneTag3 = args.getString("Tag3");
        String sceneLat = args.getString("sceneLat");
        String sceneLong = args.getString("sceneLong");
        //Log.d("fragVIDEO",networkName);
        //Log.v("video_url", sceneProvider);
        new video().execute(sceneUrl);
        ......
        @Override
    protected Void doInBackground(String... params) {
        try {
            Uri uri = Uri.parse(params[0]);
            publishProgress(uri);
        } catch (Exception e) {
            e.printStackTrace();

        }

        return null;
    }

}

我一直收到NullPointerException:uriString错误。

        06-07 19:30:19.397: W/System.err(13944): java.lang.NullPointerException: uriString
        06-07 19:30:19.397: W/System.err(13944):    at android.net.Uri$StringUri.<init>(Uri.java:464)
        06-07 19:30:19.397: W/System.err(13944):    at android.net.Uri$StringUri.<init>(Uri.java:454)
        06-07 19:30:19.397: W/System.err(13944):    at android.net.Uri.parse(Uri.java:426)
        06-07 19:30:19.397: W/System.err(13944):    at tv.loqoo.FourthScreen.Fragments.FragVideo$video.doInBackground(FragVideo.java:183)
        06-07 19:30:19.397: W/System.err(13944):    at tv.loqoo.FourthScreen.Fragments.FragVideo$video.doInBackground(FragVideo.java:1)
        06-07 19:30:19.397: W/System.err(13944):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
        06-07 19:30:19.397: W/System.err(13944):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        06-07 19:30:19.397: W/System.err(13944):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        06-07 19:30:19.397: W/System.err(13944):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        06-07 19:30:19.397: W/System.err(13944):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        06-07 19:30:19.397: W/System.err(13944):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        06-07 19:30:19.397: W/System.err(13944):    at java.lang.Thread.run(Thread.java:856)

我知道整个流程正在发挥作用,因为如果我这样做......

        new video().execute("url_to_some_video");
一切都很有效,所以我知道数据没有从主要活动中传递出去。

0 个答案:

没有答案