【问题标题】:Getting an error android.util.SuperNotCalledException: Activity {} did not call through to super.onCreate()收到错误 android.util.SuperNotCalledException: Activity {} 没有调用 super.onCreate()
【发布时间】:2020-06-02 03:25:17
【问题描述】:

我正在制作一台播放音乐和 youtube 视频的电视。我收到以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.newapp, PID: 12965
    android.util.SuperNotCalledException: Activity {com.example.newapp/com.example.newapp.YoutubeActivity} did not call through to super.onCreate()
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3081)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3237)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:81)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1929)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:209)
        at android.app.ActivityThread.main(ActivityThread.java:7021)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:872)

这是我的 youtube 活动代码

public class YoutubeActivity extends YouTubeBaseActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.e("youtube", "onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.youtube_main);

        setupVideoPlayer();
    }

这是初始化 Activity 的代码(在另一个文件中)

 private final class ItemViewClickedListener implements OnItemViewClickedListener {
        @Override
        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                                  RowPresenter.ViewHolder rowViewHolder, Row row) {

            if (item instanceof Radio) {
                Radio radio = (Radio) item;
                Log.d(TAG, "RadioItem: " + item.toString());
                System.out.println(getActivity());
                Intent intent = new Intent(getActivity(), DetailsActivity.class);
                intent.putExtra(DetailsActivity.RADIO, radio);

                Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
                        getActivity(),
                        ((ImageCardView) itemViewHolder.view).getMainImageView(),
                        DetailsActivity.SHARED_ELEMENT_NAME)
                        .toBundle();
                getActivity().startActivity(intent, bundle);
            } else if (item instanceof Video) {
                Video video = (Video) item;
                Log.e(TAG, "VideoItem: " + item.toString());
                System.out.println(getActivity());
                Intent intent = new Intent(getActivity(), YoutubeActivity.class);
                intent.putExtra(YoutubeActivity.VIDEO, video);
                Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
                        getActivity(),
                        ((ImageCardView) itemViewHolder.view).getMainImageView(),
                        YoutubeActivity.SHARED_ELEMENT_NAME)
                        .toBundle();
                getActivity().startActivity(intent, bundle);
            }
            else if (item instanceof String) {
                if (((String) item).contains(getString(R.string.error_fragment))) {
                    Intent intent = new Intent(getActivity(), BrowseErrorActivity.class);
                    startActivity(intent);
                } else {
                    Toast.makeText(getActivity(), ((String) item), Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

如您所见,如果单击的项目是收音机,那么它会转到另一个播放收音机的活动。这完美地工作。但是,如果单击的项目是视频,它会转到 youtube 播放器活动,这会给出第一个代码块中给出的异常。
另外,你可以看到我有 super.OnCreate() 函数,所以我不确定我在哪里搞砸了。

【问题讨论】:

  • 这能回答你的问题吗? Super not called exception in android?
  • 很遗憾没有,因为我已经调用了 super.onCreate() 函数,但我仍然收到错误。
  • 请同时显示您的基本活动类
  • 我没有基本活动。对于基本活动,您是指扩展我的 YoutubeBaseActivity 的另一个类吗?编辑:语法
  • 另外,YoutubeBaseActivity 是 Youtube API 的一部分。

标签: android youtube-api


【解决方案1】:

请确保YouTubeBaseActivity 在 onCreate 事件中有 super.onCreate() 方法。

【讨论】:

  • 我的应用程序中每个类的每个 onCreate 事件中都有 super.onCreate() 方法。有关如何解决此错误的任何其他提示?
【解决方案2】:

所以我得到了它,但不是通过传统方法。我刚刚做了一个新项目并将旧项目复制到新项目。仍然不确定出了什么问题,但它现在可以正常工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    相关资源
    最近更新 更多