Modifier Public not allowed here

2.7k views Asked by At

I'm pretty sure this is just a simple coding error. However I'm not sure what it is, the error reads Modifier Public is not allowed here.

public class getJsonResponse extends AsyncTask<Void, Void, String> {
                String serverUrl;

The code I am using involved getting Json from a server and the code works 100% when it is an Activity. However when I convert the activity to a fragment, it throws this error. Any help would be appreciated.

public class StandingsList extends Fragment {
    //make member variable is Views
    Button mButton;
    TextView mResult;
    String JSON_RESPONSE;
    ProgressDialog mProgressDialog;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate( R.layout.fragment_standings, container, false );
        return view;

        //get reference of the views
        mButton = (Button) view.findViewById( R.id.button );
        mResult = (TextView) view.findViewById( R.id.result );

        //when button is clicked
        mButton.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //call the getJsonResponse method and fetch the response from the server
                new getJsonResponse().execute();
            }
        } );


        public class getJsonResponse extends AsyncTask<Void, Void, String> {
            String serverUrl;

            public getJsonResponse() {
                mProgressDialog = new ProgressDialog( getActivity() );
                mProgressDialog.setMessage( "Please Wait" );
                mProgressDialog.setTitle( "Processing" );
                mProgressDialog.setCancelable( false );
            }

            @Override
            protected void onPreExecute() {

                //set the url from we have to fetch the json response
                serverUrl = "http://163.172.142.145/get_info.php";
                mProgressDialog.show();
            }

            @Override
            protected String doInBackground(Void... params) {
                try {
                    URL url = new URL( serverUrl );
                    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                    InputStream inputStream = httpURLConnection.getInputStream();
                    BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( inputStream ) );
                    StringBuilder stringBuilder = new StringBuilder();

                    while ((JSON_RESPONSE = bufferedReader.readLine()) != null) {

                        stringBuilder.append( JSON_RESPONSE + "\n" );

                    }

                    inputStream.close();
                    bufferedReader.close();
                    httpURLConnection.disconnect();

                    return stringBuilder.toString().trim();

                } catch (MalformedURLException e) {
                    Log.e( TAG, "MalformedURLException: " + e ); //print exception message to log
                } catch (IOException e) {
                    Log.e( TAG, "IOException: " + e ); //print exception message to log
                }
                return null;
            }

            @Override
            protected void onProgressUpdate(Void... values) {
                super.onProgressUpdate( values );
            }

            @Override
            protected void onPostExecute(String result) {
                //set the result which is returned by doInBackground() method to result textView
                mResult.setText( result );
                mProgressDialog.dismiss();
            }
        }

    }

    }
0

There are 0 answers