Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i have a piece of code that check for duplicate entries while running the code i get an exception "Server Json response might be invalid.
Java
public void onSuccess(String response)
				{
					
					try{
							Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
							
							JSONObject obj = new JSONObject(response);
								if(obj!=null)
								{
								
								JSONArray data = obj.getJSONArray("CheckForDuplicateSerialResult");
								for(int i=0;i<data.length();i++)
		        				{
		        					JSONObject user = data.getJSONObject(i);
		        					   						
		        					String name=user.getString("Res");
		        					if(name.equals("0")){
		        							
		        					Toast t=Toast.makeText(getApplicationContext(), "Scan Next", Toast.LENGTH_SHORT);
		        						t.setGravity(Gravity.CENTER, 0, 0);
		        						t.show();
		        						}
		        						else{
		        							Toast.makeText(getApplicationContext(), "Already exist", Toast.LENGTH_SHORT).show();
		        							
		        						}
		        					
		        				}
								}
								
								
							
						}catch(JSONException e){
							Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
			                e.printStackTrace();
			    		
						}	
				}
					@Override
					public void onFailure(int statusCode, Throwable error,String content){
						//Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show();
						 if(statusCode == 404){
		                  Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
		              } 
						 else if(statusCode == 500){
		                  Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
		              }
						 else{
							 //Toast.makeText(getApplicationContext(), content, Toast.LENGTH_LONG).show();
		                  //Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
		              }
					 }

				});
			}

please help me to solve this problem
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900