I am developing an android app... where I developed a table in MySql and table has certain results for values of 1-10 and all the values are entered seperately ...
in my android application when a particular value is displayed the result of that value has to be taken from the table... but it is not working correctly ...the message is getting like 'unfortunately application closed'... i am adding my code here... please check the code and if found any mistake pls help.....
Activity.java
public class FirstResult extends Activity
{
String pid;
TextView txtName;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
// single product url
private static final String url_product_detials = "http://iascpl.com/app/get_product_details.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCT = "product";
//private static final String TAG_PID = "pid";
//private static final String TAG_NUMBER = "number";
//private static final String TAG_PRICE = "price";
private static final String TAG_DESCRIPTION = "description";
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.firstresult_xm);
TextView txt1 = (TextView) findViewById (R.id.textView2);
txt1.setText(getIntent().getStringExtra("name10"));
pid = txt1.getText().toString();
new GetProductDetails().execute();
}
/**
* Background Async Task to Get complete product details
* */
class GetProductDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(FirstResult.this);
pDialog.setMessage("Loading product details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting product 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
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pid", pid));
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_product_detials, "GET", params);
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_PRODUCT); // JSON Array
// get first product object from JSON Array
JSONObject product = productObj.getJSONObject(0);
// product with this pid found
// Edit Text
txtName = (TextView) findViewById(R.id.textView3);
// display product data in EditText
txtName.setText(product.getString(TAG_DESCRIPTION));
}else{
// product with pid 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();
}
}
}
php file
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["pid"])) {
$pid = $_GET['pid'];
// get a product from products table
$result = mysql_query("SELECT *FROM prediction WHERE pid = $pid");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["pid"] = $result["pid"];
$product["number"] = $result["number"];
// $product["price"] = $result["price"];
$product["description"] = $result["description"];
$product["created_at"] = $result["created_at"];
$product["updated_at"] = $result["updated_at"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
my Logcat
11-05 11:44:12.701: E/AndroidRuntime(7643): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-05 11:44:12.701: E/AndroidRuntime(7643): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-05 11:44:12.701: E/AndroidRuntime(7643): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-05 11:44:12.701: E/AndroidRuntime(7643): at com.example.numero.JSONParser.makeHttpRequest(JSONParser.java:63)
11-05 11:44:12.701: E/AndroidRuntime(7643): at com.example.numero.FirstResult$GetProductDetails$1.run(FirstResult.java:105)
11-05 11:44:12.701: E/AndroidRuntime(7643): at android.os.Handler.handleCallback(Handler.java:725)
11-05 11:44:12.701: E/AndroidRuntime(7643): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 11:44:12.701: E/AndroidRuntime(7643): at android.os.Looper.loop(Looper.java:137)
11-05 11:44:12.701: E/AndroidRuntime(7643): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-05 11:44:12.701: E/AndroidRuntime(7643): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 11:44:12.701: E/AndroidRuntime(7643): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 11:44:12.701: E/AndroidRuntime(7643): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-05 11:44:12.701: E/AndroidRuntime(7643): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-05 11:44:12.701: E/AndroidRuntime(7643): at dalvik.system.NativeStart.main(Native Method)
11-05 11:52:08.052: E/Trace(7805): error opening trace file: No such file or directory (2)
11-05 11:56:14.171: E/AndroidRuntime(7805): FATAL EXCEPTION: main
11-05 11:56:14.171: E/AndroidRuntime(7805): android.os.NetworkOnMainThreadException
11-05 11:56:14.171: E/AndroidRuntime(7805): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
11-05 11:56:14.171: E/AndroidRuntime(7805): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
11-05 11:56:14.171: E/AndroidRuntime(7805): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
11-05 11:56:14.171: E/AndroidRuntime(7805): at java.net.InetAddress.getAllByName(InetAddress.java:214)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-05 11:56:14.171: E/AndroidRuntime(7805): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-05 11:56:14.171: E/AndroidRuntime(7805): at com.example.numero.JSONParser.makeHttpRequest(JSONParser.java:63)
11-05 11:56:14.171: E/AndroidRuntime(7805): at com.example.numero.FirstResult$GetProductDetails$1.run(FirstResult.java:105)
11-05 11:56:14.171: E/AndroidRuntime(7805): at android.os.Handler.handleCallback(Handler.java:725)
11-05 11:56:14.171: E/AndroidRuntime(7805): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 11:56:14.171: E/AndroidRuntime(7805): at android.os.Looper.loop(Looper.java:137)
11-05 11:56:14.171: E/AndroidRuntime(7805): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-05 11:56:14.171: E/AndroidRuntime(7805): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 11:56:14.171: E/AndroidRuntime(7805): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 11:56:14.171: E/AndroidRuntime(7805): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-05 11:56:14.171: E/AndroidRuntime(7805): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-05 11:56:14.171: E/AndroidRuntime(7805): at dalvik.system.NativeStart.main(Native Method)
11-05 11:56:25.961: E/Trace(7893): error opening trace file: No such file or directory (2)
runOnUiThread(new Runnable() {
#Override
public void run()
{
// TODO Auto-generated method stub
try {
txt3.setText(product.getString(TAG_DESCRIPTION));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}else{
// product with pid not found
}
add this line after
/ get first product object from JSON Array
JSONObject product = productObj.getJSONObject(0);
// product with this pid found
// Edit Text
txtName = (TextView) findViewById(R.id.textView3);
that will solve the issue
You need to post the stack trace of the problem. You will find it in your logcat view. Also, on a sidenote:
runOnUiThread(new Runnable() {
public void run() {
This doesnt make any sense at all at this place because you are basically running a background thread, then you synchronize it and run it on the main thread. Depending on your settings, that won't work because Android does not allow network operations on the main / UI thread.
Edit after LogCat was added:
It's exactly what I mentioned. Android does not allow you to run network traffic on the UI thread. Remove that runOnUiThread stuff from the runOnBackground.
Now to set the data you can two one of two things:
Add the runOnUiThread part where you set the textView. Something like:
runOnUiThread(new Runnable() {
public void run() {
TextView tv = findViewById...
tv.setText(...
}
}
Return the object you need. This is actually how AsyncTask is supposed to work:
In your AsyncTask's runOnBackground, you'd do:
return product.getString(TAG_DESCRIPTION)
Then, in onPostExecute you get that String and set it to your TextViews.
Related
I'm trying to add some values to my database from my android application through JSON.
I have used the below code previously with eclipse and worked perfectly, now im trying it using android studio and it isn't working I don't know why!
code:
public class Main2Activity extends AppCompatActivity {
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
EditText ID;
EditText fname;
EditText lname;
EditText phone;
Button addbtn;
// url to create new product
private static String url_create_product = "http://www.lamia.byethost18.com/add_info.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
String H,Q,C,Ls;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ID = (EditText) findViewById(R.id.ID);
lname = (EditText) findViewById(R.id.lname);
fname = (EditText) findViewById(R.id.fname);
phone = (EditText) findViewById(R.id.phone);
H = ID.getText().toString();
Q = lname.getText().toString();
C = fname.getText().toString();
Ls = phone.getText().toString();
addbtn = (Button) findViewById(R.id.addbtn);
addbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
new CreateNewProduct().execute();
}
});
}
class CreateNewProduct extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Main2Activity.this);
pDialog.setMessage("Creating Product..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating product
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("ID", H));
params.add(new BasicNameValuePair("lname", Q));
params.add(new BasicNameValuePair("fname", C));
params.add(new BasicNameValuePair("phone", Ls));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
// Intent i = new Intent(getApplicationContext(), AdminExercise.class);
// startActivity(i);
// closing this screen
finish();
} else {
// failed to create product
}
} 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 done
pDialog.dismiss();
}
}
}
I got this error:
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/JSON Parser: Error parsing data org.json.JSONException: Value <html><body><script of type java.lang.String cannot be converted to JSONObject
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: Process: com.example.hatim.maps, PID: 1934
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at android.os.AsyncTask$3.done(AsyncTask.java:309)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:242)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at com.example.hatim.maps.Main2Activity$CreateNewProduct.doInBackground(Main2Activity.java:113)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at com.example.hatim.maps.Main2Activity$CreateNewProduct.doInBackground(Main2Activity.java:77)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at android.os.AsyncTask$2.call(AsyncTask.java:295)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
04-14 21:08:36.214 1934-1980/com.example.hatim.maps E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
I don't get what is the error?
can someone help please? thank you!
It seems that your request is not receiving a JSON, may be is an HTML error because the value received starts with html format:
E/JSON Parser: Error parsing data org.json.JSONException: Value <html><body><script of type java.lang.String cannot be converted to JSONObject
I am trying to create list view with json .
And this is the Logcat Stacktrace
1215-1239/com.skripsi.mazdamobil E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at com.skripsi.mazdamobil.Data_Tipsntrick$DownloadList.doInBackground(Data_Tipsntrick.java:186)
at com.skripsi.mazdamobil.Data_Tipsntrick$DownloadList.doInBackground(Data_Tipsntrick.java:164)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Data_Tipsntrick.java:164
private class DownloadList extends AsyncTask<Void,Void,Void> <- line 164
{
protected void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(Data_Tipsntrick.this);
pDialog.setMessage("Tunggu Sebentar...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
Data_Tipsntrick.java:186
protected Void doInBackground(Void... unused)
{
String url_param;
url_param="fungsi.php?pl="+filepl+"&kategori="+filekategori;
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url+url_param);
Log.d("log", "url:" + url + url_param);
try
{
JSONArray result = json.getJSONArray("result"); <<-- line 186
for (int i = 0; i < result.length(); i++)
{
JSONObject c = result.getJSONObject(i);
String id = c.getString("id");
String pesan = c.getString("pesan");
String nama_tipsntrick = c.getString("nama");
String kategori_tipsntrick= c.getString("kategori");
HashMap<String,String> map = new HashMap<String,String>();
map.put(in_id,id);
map.put(in_pesan,pesan);
map.put(in_nama,nama_tipsntrick);
map.put(in_kategori,kategori_tipsntrick);
resultList.add(map);
}
Log.d("log", "bla:" + resultList);
}
catch (JSONException e)
{
e.printStackTrace();
}
return null;
}
next
05-05 11:06:11.299 1215-1215/com.skripsi.mazdamobil E/WindowManager﹕ Activity com.skripsi.mazdamobil.Data_Tipsntrick has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{416ef190 V.E..... R.....ID 0,0-304,96} that was originally added here
android.view.WindowLeaked: Activity com.skripsi.mazdamobil.Data_Tipsntrick has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{416ef190 V.E..... R.....ID 0,0-304,96} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:345)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:239)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at com.skripsi.mazdamobil.Data_Tipsntrick$DownloadList.onPreExecute(Data_Tipsntrick.java:173)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.skripsi.mazdamobil.Data_Tipsntrick.onCreate(Data_Tipsntrick.java:66)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Data_Tipsntrick.java:173
protected void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(Data_Tipsntrick.this);
pDialog.setMessage("Tunggu Sebentar...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show(); <-- line 173
}
Data_Tipsntrick.java:66
new DownloadList().execute();
What am i doing wrong.Granted i don't know much java.
JSON Response
{"result":[{"id":"7","nama":"sadasdas","kategori":"berkendara","pesan":"dasdasdasdasd"},{"id":"5","nama":"Menggati Ban Bocor","kategori":"berkendara","pesan":"asdsadasdas"}]}
Well you can try this way if you are getting proper JSON response:
...
...
try {
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url+url_param);
JSONArray result = json.getJSONArray("result");
if(result!=null) {
for (int i = 0; i < result.length(); i++) {
JSONObject c = (JSONObject) result.get(i);
String id = "", pesan = "", nama_tipsntrick = "", kategori_tipsntrick = "";
if (c.has("id"))
id = c.getString("id");
if (c.has("pesan"))
pesan = c.getString("pesan");
if (c.has("nam"))
nama_tipsntrick = c.getString("nama");
if (c.has("kategori"))
kategori_tipsntrick = c.getString("kategori");
HashMap<String, String> map = new HashMap<String, String>();
map.put(in_id, id);
map.put(in_pesan, pesan);
map.put(in_nama, nama_tipsntrick);
map.put(in_kategori, kategori_tipsntrick);
resultList.add(map);
}
}
Log.d("log", "bla:" + resultList);
} catch (JSONException e) {
e.printStackTrace();
}
I got this error whenever I change my URL to my online hosting, but if I change to 10.0.2.2 everything seems fine and running.
LogCat
02-01 23:02:18.302 17643-18052/com.example.jithea.testlogin E/JSON Parser﹕ Error parsing data org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject
02-01 23:02:18.303 17643-18052/com.example.jithea.testlogin W/dalvikvm﹕ threadid=12: thread exiting with uncaught exception (group=0x40d8d9a8)
02-01 23:02:18.303 17643-18052/com.example.jithea.testlogin W/dalvikvm﹕ threadid=12: uncaught exception occurred
02-01 23:02:18.304 17643-18052/com.example.jithea.testlogin W/System.err﹕ java.lang.RuntimeException: An error occured while executing doInBackground()
02-01 23:02:18.304 17643-18052/com.example.jithea.testlogin W/System.err﹕ at android.os.AsyncTask$3.done(AsyncTask.java:299)
02-01 23:02:18.304 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
02-01 23:02:18.305 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
02-01 23:02:18.305 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:239)
02-01 23:02:18.305 17643-18052/com.example.jithea.testlogin W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-01 23:02:18.305 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-01 23:02:18.306 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-01 23:02:18.306 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.lang.Thread.run(Thread.java:838)
02-01 23:02:18.306 17643-18052/com.example.jithea.testlogin W/System.err﹕ Caused by: java.lang.NullPointerException
02-01 23:02:18.306 17643-18052/com.example.jithea.testlogin W/System.err﹕ at com.example.jithea.testlogin.NewsActivity$LoadAllProducts.doInBackground(NewsActivity.java:132)
02-01 23:02:18.306 17643-18052/com.example.jithea.testlogin W/System.err﹕ at com.example.jithea.testlogin.NewsActivity$LoadAllProducts.doInBackground(NewsActivity.java:107)
02-01 23:02:18.307 17643-18052/com.example.jithea.testlogin W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-01 23:02:18.307 17643-18052/com.example.jithea.testlogin W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-01 23:02:18.307 17643-18052/com.example.jithea.testlogin W/System.err﹕ ... 4 more
02-01 23:02:18.307 17643-18052/com.example.jithea.testlogin W/dalvikvm﹕ threadid=12: calling UncaughtExceptionHandler
02-01 23:02:18.315 17643-18052/com.example.jithea.testlogin E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
Caused by: java.lang.NullPointerException
at com.example.jithea.testlogin.NewsActivity$LoadAllProducts.doInBackground(NewsActivity.java:132)
at com.example.jithea.testlogin.NewsActivity$LoadAllProducts.doInBackground(NewsActivity.java:107)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
02-01 23:02:18.371 17643-17659/com.example.jithea.testlogin I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x528dc150) fps:43.08, dur:1044.57, max:73.51, min:6.02
And here's my NewsActivity.java
public class NewsActivity extends ListActivity {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParserNews jParser = new JSONParserNews();
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "http://agustiniancampusevents.site40.net/newsDB/get_all_news.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_NEWS = "news";
private static final String TAG_PID = "pid";
private static final String TAG_NEWSTITLE = "newstitle";
// products JSONArray
JSONArray products = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
// Hashmap for ListView
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
// Get listview
ListView lv = getListView();
// on seleting single product
// launching Edit Product Screen
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String pid = ((TextView) view.findViewById(R.id.pid)).getText()
.toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
ViewNewsActivity.class);
// sending pid to next activity
in.putExtra(TAG_PID, pid);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
}
// Response from Edit Product Activity
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
/**
* Background Async Task to Load all product by making HTTP Request
*/
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
*/
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(NewsActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
*/
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_NEWS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String newstitle = c.getString(TAG_NEWSTITLE);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NEWSTITLE, newstitle);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),
ViewNewsActivity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* *
*/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
NewsActivity.this, productsList,
R.layout.news_list_item, new String[]{TAG_PID,
TAG_NEWSTITLE},
new int[]{R.id.pid, R.id.newstitle});
// updating listview
setListAdapter(adapter);
}
});
}
}
}
I am using MySQL database, and I'm selecting my data from database using JSONParser.class I found on the internet, but the value always showing Null, please help, i'm new at this
Here's my main activity class:
public class Profil extends Activity{
private static String url = "http://10.0.2.2/koperasidb/tampil_profil.php";
private static final String TAG_ANGGOTA = "anggota";
private JSONParser jsonParser;
private JSONObject json;
private JSONArray jArray;
String kodeanggota;
private Session session;//global variable
private String no_ba,nm,jk,agama,tmptlahir,tgllahir,blnlahir,thnlahir,status,alamat,notelp,email;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
session = new Session(this); //onCreate Session class
//mengambil string kdanggota
kodeanggota = session.getkdanggota();
jsonParser = new JSONParser();
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("kode", kodeanggota));
//profil = new ArrayList<HashMap<String, String>>();
try {
json = jsonParser.makeHttpRequest(url, "POST", postParameters);
jArray = json.getJSONArray(TAG_ANGGOTA);
for (int i = 0; i < jArray.length(); i++) {
JSONObject job = jArray.getJSONObject(i);
no_ba = job.getString("no_ba");
nm = job.getString("nama");
jk = job.getString("jk");
agama = job.getString("agama");
tmptlahir = job.getString("tmptlhr");
tgllahir = job.getString("tgllhr");
blnlahir = job.getString("blnlhr");
thnlahir = job.getString("thnlhr");
status = job.getString("status");
alamat = job.getString("alamat");
notelp = job.getString("notelp");
email = job.getString("email");
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
tampilkanprofil();
}
}
private void tampilkanprofil() {
TextView profilnama = (TextView) findViewById(R.id.profilnamaanggota);
profilnama.setText(nm);
TextView profiljk = (TextView) findViewById(R.id.profiljk);
profiljk.setText(jk);
TextView profilnoba = (TextView) findViewById(R.id.profilkodeba);
profilnoba.setText(no_ba);
TextView profilagama = (TextView) findViewById(R.id.profilagama);
profilagama.setText(agama);
TextView profilttl = (TextView) findViewById(R.id.profilttl);
profilttl.setText(tmptlahir + ", " + tgllahir + " " + blnlahir + " " + thnlahir);
TextView profilstatus = (TextView) findViewById(R.id.profilstatus);
profilstatus.setText(status);
TextView profilalamat = (TextView) findViewById(R.id.profilalamat);
profilalamat.setText(alamat);
TextView profilnotelp = (TextView) findViewById(R.id.profilnotelp);
profilnotelp.setText(notelp);
TextView profilemail = (TextView) findViewById(R.id.profilemail);
profilemail.setText(email);
}
}
And here's my php file:
<?php
include ("koneksi.php");
$response = array();
$kd=$_POST['kdanggota'];
$result = mysql_query("SELECT * FROM anggota_baru WHERE kd_anggota ='$kd' ") or die(mysql_error());
$response["anggota"] = array();
while($row = mysql_fetch_array($result)){
$profil = array();
$profil["no_ba"] = $row["no_ba"];
$profil["nama"] = $row["nama_lengkap"];
$profil["jk"] = $row["kelamin"];
$profil["agama"] = $row["agama"];
$profil["tmptlhr"] = $row["tempat_lahir"];
$profil["ttgllhr"] = $row["tgl_lahir"];
$profil["blnlhr"] = $row["bln_lahir"];
$profil["thnlhr"] = $row["thn_lahir"];
$profil["status"] = $row["status_nikah"];
$profil["alamat"] = $row["alamat"];
$profil["notelp"] = $row["no_telp"];
$profil["email"] = $row["email"];
array_push($response["anggota"],$profil);
}
echo json_encode($response);
?>
here's my logcat error:
05-08 20:20:26.246: WARN/System.err(871): org.json.JSONException: No value for no_ba
05-08 20:20:26.256: WARN/System.err(871): at org.json.JSONObject.get(JSONObject.java:354)
05-08 20:20:26.256: WARN/System.err(871): at org.json.JSONObject.getString(JSONObject.java:510)
05-08 20:20:26.256: WARN/System.err(871): at com.randy.koperasidb.Profil.onCreate(Profil.java:55)
05-08 20:20:26.256: WARN/System.err(871): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-08 20:20:26.266: WARN/System.err(871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
05-08 20:20:26.266: WARN/System.err(871): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-08 20:20:26.266: WARN/System.err(871): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-08 20:20:26.286: WARN/System.err(871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-08 20:20:26.286: WARN/System.err(871): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 20:20:26.296: WARN/System.err(871): at android.os.Looper.loop(Looper.java:123)
05-08 20:20:26.296: WARN/System.err(871): at android.app.ActivityThread.main(ActivityThread.java:3647)
05-08 20:20:26.306: WARN/System.err(871): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 20:20:26.306: WARN/System.err(871): at java.lang.reflect.Method.invoke(Method.java:507)
05-08 20:20:26.316: WARN/System.err(871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-08 20:20:26.316: WARN/System.err(871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-08 20:20:26.327: WARN/System.err(871): at dalvik.system.NativeStart.main(Native Method)
05-08 20:20:26.346: DEBUG/AndroidRuntime(871): Shutting down VM
05-08 20:20:26.346: WARN/dalvikvm(871): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): FATAL EXCEPTION: main
05-08 20:20:26.366: ERROR/AndroidRuntime(871): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.randy.koperasidb/com.randy.koperasidb.Profil}: java.lang.NullPointerException
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.os.Looper.loop(Looper.java:123)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.ActivityThread.main(ActivityThread.java:3647)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at java.lang.reflect.Method.invoke(Method.java:507)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at dalvik.system.NativeStart.main(Native Method)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): Caused by: java.lang.NullPointerException
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at com.randy.koperasidb.Profil.tampilkanprofil(Profil.java:78)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at com.randy.koperasidb.Profil.onCreate(Profil.java:72)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
05-08 20:20:26.366: ERROR/AndroidRuntime(871): ... 11 more
05-08 20:20:26.396: WARN/ActivityManager(61): Force finishing activity com.randy.koperasidb/.Profil
05-08 20:20:26.416: WARN/ActivityManager(61): Force finishing activity com.randy.koperasidb/.Home
05-08 20:20:26.927: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{40693400 com.randy.koperasidb/.Profil}
05-08 20:20:28.177: INFO/Process(871): Sending signal. PID: 871 SIG: 9
05-08 20:20:28.207: INFO/ActivityManager(61): Process com.randy.koperasidb (pid 871) has died.
05-08 20:20:28.217: INFO/WindowManager(61): WIN DEATH: Window{406a6770 com.randy.koperasidb/com.randy.koperasidb.login paused=false}
05-08 20:20:28.257: ERROR/InputDispatcher(61): channel '40774e40 com.randy.koperasidb/com.randy.koperasidb.Home (server)' ~ Consumer closed input channel or an error occurred. events=0x8
05-08 20:20:28.257: ERROR/InputDispatcher(61): channel '40774e40 com.randy.koperasidb/com.randy.koperasidb.Home (server)' ~ Channel is unrecoverably broken and will be disposed!
05-08 20:20:28.327: INFO/WindowManager(61): WIN DEATH: Window{40774e40 com.randy.koperasidb/com.randy.koperasidb.Home paused=true}
05-08 20:20:29.027: WARN/InputManagerService(61): Got RemoteException sending setActive(false) notification to pid 871 uid 10041
You are passing parameter from client app with name "kode" in line
postParameters.add(new BasicNameValuePair("kode", kodeanggota));
But you are accepting with name "kdanggota" in line
$kd=$_POST['kdanggota'];
Therefore server is sending empty array and you are not checking either array is empty or not. Please use same name of parameter while sending and receiving data.
one error I can see without the logcat which is as following;
1 - You have assigned key kode in your BasicNameValuePair while you are trying to fetch 'kdanggota' in you php wile in $_POST which does not exists. So change the fourth line of php as following
`$kd=$_POST['kode'];` //You need to write kode here because that is what is the key for your pair.
Please also post logcat for more information
My application code is as follows,
public class Alarm extends MainActivity {
public String str;
public void onReceive(Context context, Intent intent) {
//---get the CB message passed in---
Bundle bundle = intent.getExtras();
SmsCbMessage[] msgs = null;
str = "";
if (bundle != null) {
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsCbMessage[pdus.length];
for (int i=0; i<msgs.length; i++) {
msgs[i] = SmsCbMessage.createFromPdu((byte[])pdus[i]);
str += "CB " + msgs[i].getGeographicalScope() + msgs[i].getMessageCode() + msgs[i].getMessageIdentifier() + msgs[i].getUpdateNumber();
str += " :";
str += "\n";
}
}
}
EditText user_value;
Button startalarm;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
startalarm = (Button) findViewById(R.id.startalarm);
user_value = (EditText) findViewById(R.id.user_value);
startalarm.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
// TODO Auto-generated method stub
if(user_value.length()==0)
{
Toast.makeText(getBaseContext(), "Please enter a value.", Toast.LENGTH_LONG).show();
}
SQLiteDatabase aa = openOrCreateDatabase("MLIdata", MODE_WORLD_READABLE, null);
Cursor c = aa.rawQuery("SELECT CblocationName FROM MLITable WHERE CblocationCode = '"+str+"'", null);
c.moveToFirst();
c.getString(c.getColumnIndex("CblocationName"));
String sas = user_value.getText().toString();
if(sas==getString(c.getColumnIndex("CblocationName")))
{
//here comes the alarm code
Toast.makeText(getBaseContext(), "till here it has executed.", Toast.LENGTH_LONG).show();
Notification notification = new Notification(android.R.drawable.ic_popup_reminder,
"My Notification", System.currentTimeMillis());
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
}
}
});
}
}
Though there are no errors, when I run this code it force closes when I press the 'startalarm' button.
My log cat is as follows,
11-05 01:31:03.029: W/ResourceType(1554): No package identifier when getting value for resource number 0x00000000
11-05 01:31:03.029: W/dalvikvm(1554): threadid=1: thread exiting with uncaught exception (group=0x40018578)
11-05 01:31:03.029: E/AndroidRuntime(1554): FATAL EXCEPTION: main
11-05 01:31:03.029: E/AndroidRuntime(1554): android.content.res.Resources$NotFoundException: String resource ID #0x0
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.content.res.Resources.getText(Resources.java:201)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.content.res.Resources.getString(Resources.java:254)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.content.Context.getString(Context.java:183)
11-05 01:31:03.029: E/AndroidRuntime(1554): at my.project.mil.Alarm$1.onClick(Alarm.java:68)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.view.View.performClick(View.java:2485)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.view.View$PerformClick.run(View.java:9080)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.os.Handler.handleCallback(Handler.java:587)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.os.Looper.loop(Looper.java:130)
11-05 01:31:03.029: E/AndroidRuntime(1554): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-05 01:31:03.029: E/AndroidRuntime(1554): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 01:31:03.029: E/AndroidRuntime(1554): at java.lang.reflect.Method.invoke(Method.java:507)
11-05 01:31:03.029: E/AndroidRuntime(1554): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-05 01:31:03.029: E/AndroidRuntime(1554): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-05 01:31:03.029: E/AndroidRuntime(1554): at dalvik.system.NativeStart.main(Native Method)
I've tried all the solutions given in the below link, yet none helped.
Android, string resource not found
Help required,
Thank you.
I had no idea my comment would fix your exception. I will put it as an answer so you can close this question.
Change this line:
if(sas==getString(c.getColumnIndex("CblocationName")))
to
if(sas.equals(getString(c.getColumnIndex("CblocationName"))))
Read up on String comparison if you don't understand why this should be like this.