non-static method getIntent() cannot be referenced from a static context

Alex

I'm getting error:

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

on the line:

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

Here is my code:

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;
        }
}

What is the problem? How to fix it?

Here is another error on the next code Error:(120, 21) error: non-static method runOnUiThread(Runnable) cannot be referenced from a static context. how do i correct it. please help

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();


 }
Skizo-ozᴉʞS

What is the problem?

You are calling getIntent() on a Fragment

How to fix it?

You have to call getActivity() before the getIntent()

For example :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Why does String::isEmpty works when non-static method cannot be referenced from a static context?

From Java

java - Non-static method 'getLogger' cannot be referenced from a static context

From Java

Non-static method cannot be referenced from a static context in java 8 streams

From Java

Non-static method cannot be referenced from a static context in java 8 streams

From Java

Non static field cannot be referenced from a static context- Main method

From Java

Error: Non-static method 'findViewById(int)' cannot be referenced from a static context

From Java

Android: Non-static method cannot be referenced from static context. Confused?

From Java

non-static class cannot be referenced from a static context

From Java

non static method cannot be referenced from a static context

From Java

"non-static variable this cannot be referenced from a static context"?

From Dev

java: non-static variable this cannot be referenced from a static context

From Dev

Map.merge .. non-static method cannot be referenced from static context

From Dev

Flutter: non-static method registerWith(Registrar) cannot be referenced from a static context

From Dev

Non static variable cannot be referenced from static context java

From Dev

non-static method count(int) cannot be referenced from a static context

From Dev

non-static variable s cannot be referenced from a static context

From Dev

"Non-static method cannot be referenced from static context" error

From Dev

non static variable this cannot be referenced from a static context

From Dev

non-static variable cannot be referenced from a static context java

From Dev

Error:non static method 'edit' cannot be referenced in static context

From Dev

Non-static variable filepath cannot be referenced from a static context

From Dev

Non-static edit() cannot be referenced from a static context

From Dev

Trying to get my show-method to work (Non static method cannot be referenced from static context)

From Dev

non static setGravity cannot be referenced from static context

From Dev

Non-static variable cannot be referenced from a static context?

From Dev

non-static variable cannot be referenced from static context [JAVA]

From Dev

non-static method matcher(CharSequence) cannot be referenced from a static context

From Dev

Non-static method getSocketFactory cannot be referenced from a static context

From Dev

Non-static method cannot be referenced from a static context when flattening map java 8

Related Related

  1. 1

    Why does String::isEmpty works when non-static method cannot be referenced from a static context?

  2. 2

    java - Non-static method 'getLogger' cannot be referenced from a static context

  3. 3

    Non-static method cannot be referenced from a static context in java 8 streams

  4. 4

    Non-static method cannot be referenced from a static context in java 8 streams

  5. 5

    Non static field cannot be referenced from a static context- Main method

  6. 6

    Error: Non-static method 'findViewById(int)' cannot be referenced from a static context

  7. 7

    Android: Non-static method cannot be referenced from static context. Confused?

  8. 8

    non-static class cannot be referenced from a static context

  9. 9

    non static method cannot be referenced from a static context

  10. 10

    "non-static variable this cannot be referenced from a static context"?

  11. 11

    java: non-static variable this cannot be referenced from a static context

  12. 12

    Map.merge .. non-static method cannot be referenced from static context

  13. 13

    Flutter: non-static method registerWith(Registrar) cannot be referenced from a static context

  14. 14

    Non static variable cannot be referenced from static context java

  15. 15

    non-static method count(int) cannot be referenced from a static context

  16. 16

    non-static variable s cannot be referenced from a static context

  17. 17

    "Non-static method cannot be referenced from static context" error

  18. 18

    non static variable this cannot be referenced from a static context

  19. 19

    non-static variable cannot be referenced from a static context java

  20. 20

    Error:non static method 'edit' cannot be referenced in static context

  21. 21

    Non-static variable filepath cannot be referenced from a static context

  22. 22

    Non-static edit() cannot be referenced from a static context

  23. 23

    Trying to get my show-method to work (Non static method cannot be referenced from static context)

  24. 24

    non static setGravity cannot be referenced from static context

  25. 25

    Non-static variable cannot be referenced from a static context?

  26. 26

    non-static variable cannot be referenced from static context [JAVA]

  27. 27

    non-static method matcher(CharSequence) cannot be referenced from a static context

  28. 28

    Non-static method getSocketFactory cannot be referenced from a static context

  29. 29

    Non-static method cannot be referenced from a static context when flattening map java 8

HotTag

Archive