org.json.JSONException: End of input at character BUG json android : hello everyone i know that this issue is very known but i can't solucionate so far :(! after of all, i have a project and the data is stored perfectly in the DB (localhost) im using www.000webhost.com. so the problem it isnt the php files or something with the connection of my app. the issue happens with

> JSONObject jsonResponse = new JSONObject(response);

in this stackover issue http://stackoverflow.com/questions/14036847/org-json-jsonexception-end-of-input-at-character somebody wrote that the solution is this:

Change

 

    JSONObject jsonObject = new JSONObject(result);

to

    result=getJSONUrl(url);  //<< get json string from server
    JSONObject jsonObject = new JSONObject(result);

but in my app the method getJSONUrl doesn't exists so that option doesnt work for me :( some advice my friends?

## RegisterActivity.java

    package com.tonikamitv.loginregister;
    
    import android.app.AlertDialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    
    import com.android.volley.RequestQueue;
    import com.android.volley.Response;
    import com.android.volley.toolbox.Volley;
    
    import org.json.JSONException;
    import org.json.JSONObject;
    
    public class RegisterActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_register);
    
            final EditText etAge = (EditText) findViewById(R.id.etAge);
            final EditText etName = (EditText) findViewById(R.id.etName);
            final EditText etUsername = (EditText) findViewById(R.id.etUsername);
            final EditText etPassword = (EditText) findViewById(R.id.etPassword);
            final Button bRegister = (Button) findViewById(R.id.bRegister);
    
            bRegister.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String name = etName.getText().toString();
                    final String username = etUsername.getText().toString();
                    final int age = Integer.parseInt(etAge.getText().toString());
                    final String password = etPassword.getText().toString();
    
                    Response.Listener<String> responseListener = new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            try {
    
                                JSONObject jsonResponse = new JSONObject(response);
                                boolean success = jsonResponse.getBoolean("success");
                                if (success) {
                                    Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                                    RegisterActivity.this.startActivity(intent);
                                } else {
                                    AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                                    builder.setMessage("Register Failed")
                                            .setNegativeButton("Retry", null)
                                            .create()
                                            .show();
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    };
    
                    RegisterRequest registerRequest = new RegisterRequest(name, username, age, password, responseListener);
                    RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
                    queue.add(registerRequest);
                }
            });
        }
    }
## the error in the console


    5-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err: org.json.JSONException: End of input at character 0 of 
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at org.json.JSONTokener.nextValue(JSONTokener.java:97)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:156)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.tonikamitv.loginregister.RegisterActivity$1$1.onResponse(RegisterActivity.java:43)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.tonikamitv.loginregister.RegisterActivity$1$1.onResponse(RegisterActivity.java:39)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at android.os.Looper.loop(Looper.java:135)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5910)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
        05-02 22:17:35.391 1041-1041/com.tonikamitv.loginregister W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
        05-02 22:24:07.721 1041-1041/com.tonikamitv.loginregister D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
        05-02 22:25:31.951 1041-1041/com.tonikamitv.loginregister W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection

