android


retrieving data from database mySQL, application has stopped (Android studio)


The problem occurs when i want to retrieve details of a record from the database, when i run the project it tells me that the project has stopped working. the error is on this line JSONObject json = jParser.makeHttpRequest(url_Edu_details, "GET", params);
package com.example.dell.adegma;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class GetEduDetails extends GetRecords {
TextView txtName;
String ID;
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
private static final String url_Edu_details= "http://10.10.88.105/app_connect/get_school_details.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_EDUCATION = "education";
private static final String TAG_ID = "ID";
private static final String TAG_SNAME = "SName";
private static final String TAG_TYPE = "Type";
private static final String TAG_GENDER = "Gender";
private static final String TAG_GRADES = "Grades";
private static final String TAG_LOCATION = "Location";
private static final String TAG_TELEPHONE = "Telephone";
private static final String TAG_CURRICULUM = "Curriculum";
private static final String TAG_EMAIL = "Email";
private static final String TAG_FEES = "Fees";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_get_records);
Intent i = getIntent();
ID = i.getStringExtra(ID);
new loadEduDetails().execute();
}
/**
* Background Async Task to Get complete school details
* */
class loadEduDetails extends AsyncTask<String, String, String> {
/* Before starting background thread Show Progress Dialog*/
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(GetEduDetails.this);
pDialog.setMessage("Loading school details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting school details in background thread
* */
protected String doInBackground(String... params) {
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
// Check for success tag
int success;
try {
// Building Parameters
HashMap<String, String> params = new HashMap<>();
params.put(TAG_ID,ID);
// getting school details by making HTTP request
// Note that school details url will use GET request
JSONObject json = jParser.makeHttpRequest(url_Edu_details, "GET", params);
// check your log for json response
Log.d("Single school Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received school details
JSONArray educationObj = json.getJSONArray(TAG_EDUCATION); // JSON Array
// get first school object from JSON Array
JSONObject education = educationObj.getJSONObject(0);
// school with this id found
// Edit Text
txtName = (TextView) findViewById(R.id.SchoolName);
// display data in TextView
txtName.setText(education.getString(TAG_SNAME));
}else{
// school with id not found
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
}
Here is the logcat:-
03-31 15:18:17.144 6012-6012/com.example.dell.adegma D/AndroidRuntime: Shutting down VM
03-31 15:18:17.146 6012-6012/com.example.dell.adegma E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dell.adegma, PID: 6012
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at libcore.net.UriCodec.encode(UriCodec.java:132)
at java.net.URLEncoder.encode(URLEncoder.java:57)
at com.example.dell.adegma.JSONParser.makeHttpRequest(JSONParser.java:38)
at com.example.dell.adegma.GetEduDetails$loadEduDetails$1.run(GetEduDetails.java:107)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5651)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

Related Links

Problem in getting result after invoking audio recorder and camera
How to set background of listview?
Draw Lines perodically
Emalator and Phone Shows More Icons for one application?
How to pass String array to webservice using ksoap2?
Get values from a Activity with CheckBoxList to another Activity
Launch Android App with Specific Activity
Holding wifi locks in a foreground service
Android Spinner get selected value OnSelectedItemListener();
SQLite Connections & Locking
View overlapping using library components
How to connect to twitter with Oauth? (requesting easy code example)
Take image from SD card, compress it, and save it back to SD?
How can I check if emails can be sent from my phone?
App gettin NullPointerException missing view in Layout
ANDROID: Help, outofmemory bitmap exceeds budget size. how to recycle?

Categories

HOME
shell
windows
mstest
heap
resultset
comsol
frequency-distribution
keytool
powershell-v5.0
lilypond
poedit
kendo-mobile
r-mice
inno-download-plugin
scriptella
tiki-wiki
jquery-multiselect
has-and-belongs-to-many
underscore.js
errbot
gp
alm
constexpr
scrollview
anki
cart
catch-unit-test
card.io
sharepoint-workflow
flatmap
c9.io
vmware-fusion
drupal-theming
zenhub
context-sensitive-grammar
backbone-collections
er-diagram
css-transforms
java-websocket
cmp
django-1.10
omxplayer
reporting-services-2012
cda
phpwebsocket
upx
fink
nullable
sapi
decimalformat
pypiserver
flock
rate-limiting
zen-cart
apache-commons-daemon
xmltype
theos
beatsmusic
android-vibration
big-ip
sql-scripts
imagefilter
xml-dsig
file-not-found
windows-embedded-standard
spring-3
scmmanager
pagedown
pstack
correlated-subquery
josql
azman
predicatebuilder
node-redis
matlab-load
w3c-geolocation
unattended-processing

Resources

Encrypt Message