hossein
hossein

Reputation: 3

parsing node json in android

i am new in android. i write request code in nodejs that get database table. i try that with postman and it was correct and return json. but in android studio, it return empty in android monitor. below is my android code. where is my problem????

@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_groups);
        get_groups();
    }


void get_groups() {


    final String url =  "http://192.168.215.2:8000/get_user2";

    final StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    Log.i("resp", response);

                }
            },

            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                    Log.i("err", error.getMessage());

                }
            }
    ) {

        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> map = new Hashtable<String, String>();
            map.put("name", Base64.encodeToString("".getBytes(), Base64.DEFAULT));
            return map;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(ActGroups.this);
    requestQueue.add(stringRequest);
}

this is post man json:

 [
    {
        "id": 1,
        "u_name": "u",
        "u_family": "uu"
    },


    {
         "id": 3,
         "u_name": "a",
         "u_family": "aa"
    },

    {
        "id": 6,
        "u_name": "b",
        "u_family": "bb"
    }
]

and below is logcat output:

05-25 12:57:25.641 1395-1395/? I/art: Not late-enabling -Xcheck:jni (already on)
05-25 12:57:25.641 1395-1395/? W/art: Unexpected CPU variant for X86 using defaults: x86
05-25 12:57:25.875 1395-1395/com.example.hosseinry.tour W/System: ClassLoader referenced unknown path: /data/app/com.example.hosseinry.tour-2/lib/x86
05-25 12:57:25.884 1395-1395/com.example.hosseinry.tour I/InstantRun: starting instant run server: is main process
05-25 12:57:26.018 1395-1395/com.example.hosseinry.tour W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-25 12:57:26.818 1395-1395/com.example.hosseinry.tour I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
05-25 12:57:26.846 1395-1443/com.example.hosseinry.tour D/NetworkSecurityConfig: No Network Security Config specified, using platform default
05-25 12:57:26.890 1395-1395/com.example.hosseinry.tour W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-25 12:57:27.078 1395-1433/com.example.hosseinry.tour I/OpenGLRenderer: Initialized EGL, version 1.4
05-25 12:57:27.078 1395-1433/com.example.hosseinry.tour D/OpenGLRenderer: Swap behavior 1
05-25 12:57:27.108 1395-1433/com.example.hosseinry.tour D/EGL_emulation: eglCreateContext: 0xa2bc6460: maj 2 min 0 rcv 2
05-25 12:57:27.160 1395-1433/com.example.hosseinry.tour D/EGL_emulation: eglMakeCurrent: 0xa2bc6460: ver 2 0 (tinfo 0x9fb92a00)
05-25 12:57:27.214 1395-1395/com.example.hosseinry.tour I/err: java.net.SocketException: Permission denied
05-25 12:57:27.217 1395-1433/com.example.hosseinry.tour D/EGL_emulation: eglMakeCurrent: 0xa2bc6460: ver 2 0 (tinfo 0x9fb92a00)

what is solution?

Upvotes: 0

Views: 94

Answers (1)

E.Abdel
E.Abdel

Reputation: 1992

You get an error :

java.net.SocketException: Permission denied

You probabelly don't handle correctly permissions, for sockets, you have to add :

<uses-permission android:name="android.permission.INTERNET"/>

to your manifest to allow you app accessing internet

Upvotes: 1

Related Questions