非静态方法getIntent()不能从静态上下文中引用

亚历克斯

我收到错误消息:

Error:(109, 18) error: non-static method getIntent() cannot be referenced from a static context

在线上:

init(getIntent().getSerializableExtra(Const.EXTRA_DATA)); 

这是我的代码:

public static class Upper_fragment extends Fragment {

        private static final String TAG = "PlayActivity";

        private Video vid;
        int mSavedVideoPosition;
        protected VideoPlayerInterface vidp;
        private LocalSingleHttpServer mServer;


        // to be implemented in concrete activities
        public Cipher getCipher() throws GeneralSecurityException {
            final Cipher c = Cipher.getInstance("AES");    // NoSuchAlgorithmException, NoSuchPaddingException
            c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("abcdef1234567890".getBytes(), "AES"));    // InvalidKeyException
            return c;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View upperView = inflater.inflate(R.layout.upper_fragment, container, false);

            vidp = (VideoPlayerInterface) upperView.findViewById(R.id.vid);
            getRTSPUrl();

            init(getIntent().getSerializableExtra(Const.EXTRA_DATA));
            return upperView;
        }
}

问题是什么?如何解决?

这是下一个代码的另一个错误错误:(120,21)错误:无法从静态上下文引用非静态方法runOnUiThread(Runnable)。我该如何纠正。请帮忙

public static class Upper_fragment extends Fragment {

        private static final String TAG = "PlayActivity";

        private Video vid;
        int mSavedVideoPosition;
        protected VideoPlayerInterface vidp;
        private LocalSingleHttpServer mServer;


        // to be implemented in concrete activities
        public Cipher getCipher() throws GeneralSecurityException {
            final Cipher c = Cipher.getInstance("AES");    // NoSuchAlgorithmException, NoSuchPaddingException
            c.init(Cipher.DECRYPT_MODE, new SecretKeySpec("abcdef1234567890".getBytes(), "AES"));    // InvalidKeyException
            return c;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View upperView = inflater.inflate(R.layout.upper_fragment, container, false);

            vidp = (VideoPlayerInterface) upperView.findViewById(R.id.vid);
            getRTSPUrl();
            init(getActivity().getIntent().getSerializableExtra(Const.EXTRA_DATA));
            return upperView;
        }


        public void getRTSPUrl() {
            final ProgressDialog dia = ProgressDialog
                    .show(getActivity(), null, "Loading...");
            new Thread(new Runnable() {

                public void run() {
                    runOnUiThread(new Runnable() {

                        public void run() {
                            dia.dismiss();
                            try {

                                mServer = new LocalSingleHttpServer();
                                final Cipher c = getCipher();
                                if (c != null) {// null means a clear video ; no need to set a decryption processing
                                    mServer.setCipher(c);
                                }
                                mServer.start();
                                String path = getPath();
                                path = mServer.getURL(path);
                                vidp.setVideoPath(path);
                                vidp.play();


                            } catch (Exception e) {
                                startActivity(new Intent(getActivity(), MainActivity.class));
                            }
                        }
                    });

                }
            }).start();


 }
素描盎司

问题是什么?

你调用getIntent()一个Fragment

如何解决?

您必须在致电getActivity()之前getIntent()

例如 :

init(getActivity().getIntent().getSerializableExtra(Const.EXTRA_DATA));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

试图让我的显示方法工作(不能从静态上下文中引用非静态方法)

非静态方法不能从静态上下文中引用

非静态方法不能从静态上下文中引用

不能从静态上下文中引用非静态方法 matcher(CharSequence)

的java - 非静态方法“getLogger”不能从静态上下文中引用

非静态方法count(int)不能从静态上下文中引用

非静态方法不能从静态上下文中的java 8流引用

JAVA - 不能从静态上下文中引用非静态方法 add(E)

非静态方法<T> findViewById(int)不能从静态上下文中引用

不能从静态上下文中引用非静态方法“inflate(byte[],int,int)”

非静态方法readData(GoogleApiClient,DataReadRequest)不能从静态上下文中引用

不能从静态上下文中引用非静态方法 getSocketFactory

非静态变量s不能从静态上下文中引用

非静态变量,不能从静态上下文中引用

“不能从静态上下文中引用的非静态变量”?

非静态类不能从静态上下文中引用

java:不能从静态上下文中引用非静态变量错误

java:非静态变量,不能从静态上下文中引用

不能从静态上下文中引用非静态变量 [JAVA]

非静态edit()不能从静态上下文中引用

不能从静态上下文中引用非静态 setGravity

不能从静态上下文中引用非静态变量?

非静态变量 this 不能从静态上下文中引用 Dormitory dormitory = new Dormitory();

为什么字符串::工作的isEmpty当非静态方法不能从静态上下文中引用?

非静态方法'getSharedPreferences(java.lang.String,int)'不能从静态上下文中引用

不能从静态上下文中引用

通知`notify()`不能从静态上下文中引用

不能从静态上下文中引用任何静态方法“getContext()”

非静态字段不能从静态上下文引用-Main方法