1. Are you ready for the Galaxy S20? Here is everything we know so far!

Server Error Occured in Android App

Discussion in 'Android Development' started by Prashant Sontale, Jul 23, 2019.

  1. Prashant Sontale

    Thread Starter

    I have a android app that takes the values from user for student, such as FirstName, LastName and Class. When the user inputs the values and clicks on button, it calls the API and stores the values into database.
    I am using Yii framework and REST API. Here when I run, there is error as com.android.volley.ServerError.
    But the values get stored in the database. Following is the code.

    What should I do? I test it using Postman, there also the values are getting saved in table but the response is not working as needed.

    Code (Text):
    1. package com.example.anitaa.studentadd;
    2.  
    3. import android.support.v7.app.AppCompatActivity;
    4. import android.os.Bundle;
    5. import android.view.View;
    6. import android.widget.Button;
    7. import android.widget.EditText;
    8. import android.widget.Toast;
    9.  
    10. import com.android.volley.AuthFailureError;
    11. import com.android.volley.Request;
    12. import com.android.volley.Response;
    13. import com.android.volley.VolleyError;
    14. import com.android.volley.toolbox.StringRequest;
    15.  
    16. import java.util.HashMap;
    17. import java.util.Map;
    18.  
    19. public class MainActivity extends AppCompatActivity {
    20.  
    21.     EditText FirstName, LastName, Class;
    22.     Button button;
    23.     String url1="http://192.168.1.3/student/web/studentrecords";
    24.  
    25.  
    26.  
    27.     @Override
    28.     protected void onCreate(Bundle savedInstanceState) {
    29.         super.onCreate ( savedInstanceState );
    30.         setContentView ( R.layout.activity_main );
    31.         FirstName= (EditText) findViewById(R.id.firstname);
    32.         LastName= (EditText) findViewById(R.id.lastname);
    33.         Class= (EditText) findViewById(R.id.studentclass);
    34.         button = (Button) findViewById(R.id.studentinformation);
    35.         button.setOnClickListener ( new View.OnClickListener () {
    36.             @Override
    37.             public void onClick(View v) {
    38.                 final String fname,lname,class2;
    39.                 fname = FirstName.getText().toString();
    40.                 lname = LastName.getText().toString();
    41.                 class2 = Class.getText().toString();
    42.                 StringRequest stringRequest1 = new StringRequest ( Request.Method.POST, url1, new Response.Listener<String> () {
    43.                     @Override
    44.                     public void onResponse(String response) {
    45.  
    46.                         Toast.makeText(MainActivity.this,response.toString (),Toast.LENGTH_SHORT).show();
    47.                     }
    48.                 }, new Response.ErrorListener () {
    49.                     @Override
    50.                     public void onErrorResponse(VolleyError error) {
    51.                         Toast.makeText(MainActivity.this,error.toString (),Toast.LENGTH_SHORT).show();
    52.                         error.printStackTrace();
    53.  
    54.                     }
    55.                 } ){
    56.                     @Override
    57.                     protected Map<String, String> getParams() throws AuthFailureError {
    58.                         Map<String, String> params = new HashMap<String, String> ();
    59.                         params.put("FirstName",fname);
    60.                         params.put("LastName",lname);
    61.                         params.put("Class",class2);
    62.                         return params;
    63.                     }
    64.                 };
    65.  
    66.                 MySingleton.getInstance ( MainActivity.this ).addToRequestque ( stringRequest1 );
    67.  
    68.             }
    69.         } );
    70.  
    71.  
    72.     }
    73.     }
    74.  
    75.  
     


  2. wseng92

    wseng92 Android Enthusiast

    Check your errors from logcat and post here.
     
    #2 wseng92, Jul 23, 2019
    Last edited: Jul 23, 2019
    23tony likes this.
  3. Prashant Sontale

    Thread Starter

    The Log cat contains too many sentences which cannot be posted as reply as its length is getting exceeded
     
  4. wseng92

    wseng92 Android Enthusiast

    You don't have to post all. Just 5 or 6 lines is enough.
     
  5. Prashant Sontale

    Thread Starter

    Code (Text):
    1.  
    2. 2019-07-18 21:06:59.632 1686-3836/? I/ActivityManager: Force stopping com.example.anitaa.student appid=10081 user=0: from pid 5673
    3. 2019-07-18 21:06:59.632 1686-3836/? I/ActivityManager: Killing 5601:com.example.anitaa.student/u0a81 (adj 0): stop com.example.anitaa.student
    4. 2019-07-18 21:06:59.637 1686-3836/? W/ActivityManager: Force removing ActivityRecord{8b4e41b u0 com.example.anitaa.student/.MainActivity t171}: app died, no saved state
    5. 2019-07-18 21:06:59.642 1686-3836/? I/WindowManager: Failed to capture screenshot of Token{a6789b8 ActivityRecord{8b4e41b u0 com.example.anitaa.student/.MainActivity t171 f}} appWin=Window{e9fecd7 u0 com.example.anitaa.student/com.example.anitaa.student.MainActivity} drawState=4
    6. 2019-07-18 21:06:59.730 1686-1712/? W/ActivityManager: setHasOverlayUi called on unknown pid: 5601
    7. 2019-07-18 21:07:00.670 2972-5282/? E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
    8. 2019-07-18 21:07:06.052 2972-5282/? E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
    9. 2019-07-18 21:07:07.083 1686-1809/? D/PackageInstaller: Inherited files: [/data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/base.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_dependencies_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_resources_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_0_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_1_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_2_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_3_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_4_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_5_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_7_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_8_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/split_lib_slice_9_apk.apk, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/oat/x86/base.odex, /data/app/com.example.anitaa.student-OoBCK78E3d51JqZHwIDBTg==/oat/x86/base.vdex]
    10. 2019-07-18 21:07:07.141 1686-1809/? D/PackageInstaller: Linked 14 files into /data/app/vmdl428671333.tmp
    11.  
     
  6. wseng92

    wseng92 Android Enthusiast

    The post you posted doesn't looked like an exception. Exception normally looked like this

    [​IMG]
     
    Deleted User likes this.
  7. Prashant Sontale

    Thread Starter

    The result I included in the code is only present. But there are some red colors statements too. such as:
    Code (Text):
    1.  
    2. 2019-07-18 21:07:00.670 2972-5282/? E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
    3. 2019-07-18 21:07:06.052 2972-5282/? E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
    4. 2019-07-23 18:06:25.147 1427-1427/? E/adbd: failed to connect to socket 'localabstract:com.example.anitaa.studentadd': Connection refused
    5. 2019-07-23 18:06:28.870 1545-5738/? E/AudioFlinger: not enough memory for AudioTrack size=131296
    6. 2019-07-23 18:06:33.953 1545-5738/? E/AudioFlinger: createRecordTrack_l() initCheck failed -12; no control block?
    7. 2019-07-23 18:06:33.960 2972-11042/? E/ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
    8. 2019-07-23 18:06:34.127 1549-1549/? E/installd: Failed to delete /data/app/vmdl1168025173.tmp: No such file or directory
    9.  
    What should I do? When I try it using Postman then also some errors are there.
     
  8. wseng92

    wseng92 Android Enthusiast

    Show the screen shot.
     
  9. Prashant Sontale

    Thread Starter

    upload_2019-7-24_18-55-13.png
     
  10. wseng92

    wseng92 Android Enthusiast

    Did your app crashed?
     
  11. Prashant Sontale

    Thread Starter

    No
     
  12. wseng92

    wseng92 Android Enthusiast

    Where you found this error? In your code?
     
  13. Prashant Sontale

    Thread Starter

    When I click on button to send the data to the server, then in the Toast, there is error as com.android.volley.ServerError, but the data is getting saved in database.
     
  14. wseng92

    wseng92 Android Enthusiast

    Toast only show "com.android.volley.ServerError" ? Nothing else?
     
  15. Prashant Sontale

    Thread Starter

    Yes Toast only shows com.android.volley.ServerError Nothing else it shows
     
  16. wseng92

    wseng92 Android Enthusiast

    Can you receive response using POSTMAN?
     
  17. Prashant Sontale

    Thread Starter

    No. using Postman I am not getting the response like a normal response but here also the data still gets saved
     
  18. wseng92

    wseng92 Android Enthusiast

    But before that can you receive response from POSTMAN ? Perhaps there are some issues on the given API ?
     
  19. Prashant Sontale

    Thread Starter

    Yes there may be some issues with API
     
  20. wseng92

    wseng92 Android Enthusiast

    You better check with API provider then.
     
Loading...

Share This Page

Loading...