android–super.onStart()上的NullPointerException

android–super.onStart()上的NullPointerException,第1张

概述目前我正在编写Fragment,它扩展了扩展YouTubePlayerSupportFragment的自定义SherlockFragment.不幸的是,应用程序崩溃了.码:publicstaticclassYouTubeVideoextendsSherlockYouTubeFragmentimplementsYouTubePlayer.OnInitializedListener{privateTextView

目前我正在编写Fragment,它扩展了扩展YouTubePlayerSupportFragment的自定义SherlockFragment.不幸的是,应用程序崩溃了.

码:

    public static class YouTubeVIDeo extends SherlockYouTubeFragment         implements YouTubePlayer.OnInitializedListener{private TextVIEw TitlevIEw;private TextVIEw descvIEw;private TextVIEw countvIEw;private TextVIEw timevIEw;private Bundle data; private YouTubePlayer ytp;private String Title;private String ID;private String desc;private String count;private String time;private int timeint;private int timem;private int times;private Tracker myTracker;private ShareActionProvIDer mShareActionProvIDer;@OverrIDepublic VIEw onCreateVIEw (LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState){    data = getArguments();    return inflater.inflate(R.layout.youtubevIEw, container, false);}@OverrIDepublic voID onStart() {     TitlevIEw = (TextVIEw) getVIEw().findVIEwByID(R.ID.Title);     descvIEw = (TextVIEw) getVIEw().findVIEwByID(R.ID.descriptiontext);     countvIEw = (TextVIEw) getVIEw().findVIEwByID(R.ID.vIEwcounttext);     timevIEw = (TextVIEw) getVIEw().findVIEwByID(R.ID.timetext);     Title = data.getString("Title");     ID = data.getString("ID");     desc = data.getString("description");     count = data.getString("vIEwcount");     time = data.getString("time");     EasyTracker.getInstance().setContext(this.getActivity());     myTracker = EasyTracker.getInstance().getTracker();     FragmentManager fragmentManager = getFragmentManager();     FragmentTransaction fragmentTransaction = fragmentManager             .beginTransaction();     YouTubePlayerSupportFragment fragment = new YouTubePlayerSupportFragment();      fragment.initialize(ID, this);     fragmentTransaction.add(R.ID.youtubeplayer, fragment);     fragmentTransaction.commit();  TitlevIEw.setText(Title);  descvIEw.setText(desc);  countvIEw.setText(count);  try {      timeint = Integer.parseInt(time);      timem = timeint/60;      times = timeint - (timem*60);        } catch(NumberFormatException nfe) {    // Handle parse error.  }  if (times<10){timevIEw.setText(String.valueOf(timem)+":0"+String.valueOf(times)); }  else{      timevIEw.setText(String.valueOf(timem)+":"+String.valueOf(times));  }  super.onStart(); } @OverrIDe public voID onInitializationFailure(ProvIDer arg0,YouTubeInitializationResult arg1) {  Toast.makeText(this.getActivity(), "UruchamianIE filmu nIE powiodło się", Toast.LENGTH_LONG).show(); } @OverrIDe public voID onInitializationSuccess(ProvIDer provIDer, YouTubePlayer player,boolean wasrestored) {  ytp = player;  player.addFullscreenControlFlag(4);  if(ytp !=null){        ytp.loadVIDeo(ID);       } } public boolean onCreateOptionsMenu(Menu menu) {     MenuInflater inflater = getSherlockActivity().getSupportMenuInflater();     inflater.inflate(R.menu.vIDeo_menu, menu);     mShareActionProvIDer = (ShareActionProvIDer)menu.findItem(R.ID.share).getActionProvIDer();     mShareActionProvIDer.setShareIntent(createShareIntent());     return true; } private Intent createShareIntent() {     myTracker.trackEvent("vIDeovIEw", "share", Title + ID, (long) 3);        Intent sendIntent = new Intent();    sendIntent.setAction(Intent.ACTION_SEND);    sendIntent.putExtra(Intent.EXTRA_TEXT, Title + " - http://ignastv.tk/ID/" + ID);    sendIntent.setType("text/plain");    mShareActionProvIDer.setShareIntent(sendIntent);    return sendIntent;} public boolean onoptionsItemSelected(MenuItem item) {     int itemID = item.getItemID();        if(itemID == R.ID.vIDsite){            myTracker.trackEvent("vIDeovIEw", "open-in", Title + ID, (long) 3);            Intent govIDeo = new Intent(Intent.ACTION_VIEW);            govIDeo.setData(Uri.parse(ID));            startActivity(govIDeo);            return true;}        else {            return super.onoptionsItemSelected(item);        }}}

最有趣的是LogCat显示出行的NullPointerException:

    super.onStart();

这是LogCat:

    04-27 20:19:30.055: E/AndroIDRuntime(14706): FATAL EXCEPTION: main    04-27 20:19:30.055: E/AndroIDRuntime(14706): java.lang.NullPointerException    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at com.Google.androID.youtube.player.YouTubePlayerSupportFragment.onStart(UnkNown Source)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at com.app.app.MainActivity$YouTubeVIDeo.onStart(MainActivity.java:519)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.support.v4.app.Fragment.performStart(Fragment.java:1332)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:906)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:1080)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.support.v4.app.FragmentManagerImpl.run(FragmentManager.java:420)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.os.Handler.handleCallback(Handler.java:725)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.os.Handler.dispatchMessage(Handler.java:92)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.os.Looper.loop(Looper.java:137)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at androID.app.ActivityThread.main(ActivityThread.java:5039)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at java.lang.reflect.Method.invokeNative(Native Method)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at java.lang.reflect.Method.invoke(Method.java:511)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:560)    04-27 20:19:30.055: E/AndroIDRuntime(14706):    at dalvik.system.NativeStart.main(Native Method)

这段代码有什么问题?

解决方法:

在SDK中并不清楚,但只要我能够解决它,你就不会扩展YouTubePlayerFragment.您只需在您的布局中包含片段(它也可以作为嵌套片段).

基本上你有两种选择:

>扩展YouTubeBaseActivity并扩展包含YouTubePlayerVIEw的布局 – 它可以工作但你不能使用碎片
>使用您最喜欢的活动并为包含YouTubePlayerFragment的布局进行充气.不要延长它.

我已成功将YoutubePlayerFragment添加为嵌套片段(更新:这会导致一些内存泄漏,因此您可能更愿意避免它).您可以在YouTubePlayerFragment周围添加其他组件,但请注意,因为docs表示您无法在播放视频时将此视图与其他视图叠加在一起.

因此,要解决您的问题,请不要扩展YouTubePlayerFragment,只需将其包含在您的布局中即可.通过调用此片段的初始化,您将在回调中获得一个YouTubePlayer,您可以使用它来控制视频.

总结

以上是内存溢出为你收集整理的android – super.onStart()上的NullPointerException全部内容,希望文章能够帮你解决android – super.onStart()上的NullPointerException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118986.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存