getting data from webservices but values not getting out of async class,
public class Settings extends PreferenceActivity{
ListPreference lst1;
public static String[] batcharr;
public static String[] streamarr;
public Settings(){
// TPGetListone getlist = new TPGetListone();
// getlist.execute();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.settings);
lst1 = (ListPreference) findPreference("prefStream");
TPGetListone getlist = new TPGetListone();
getlist.execute();
lst1.setEntries(batcharr);
lst1.setEntryValues(batcharr);
}
public class TPGetListone extends AsyncTask<String, Void, Void> {
String datax = "";
JSONArray array;
List<String> lstbatch;
List<String> lststream;
private String LogStr = "Panchratna";
#Override
protected Void doInBackground(String... params) {
DataHelper gd = new DataHelper("http://xxxx.com/EventGetter","http://xxxx.com/EventGetter.asmx?wsdl","http://xxxx.com/EventGetter/GetCourseList","GetCourseList");
datax = gd.GetData("query","SELECT batch, stream FROM batch");
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
Log.i(LogStr, "onPostExecuteCATALOG");
try {
array = new JSONArray(datax);
} catch (JSONException e) {
e.printStackTrace();
}
lstbatch = new ArrayList<String>();
lststream = new ArrayList<String>();
for(int i = 0; i < array.length(); i++){
try {
lstbatch.add(array.getJSONObject(i).getString("batch"));
lststream.add(array.getJSONObject(i).getString("stream"));
} catch (JSONException e) {
e.printStackTrace();
}
}
batcharr = new String[lstbatch.size()];
streamarr = new String[lststream.size()];
for (int i=0;i<lststream.size();i++){
lststream.toArray(batcharr);
lstbatch.toArray(streamarr);
}
}
#Override
protected void onCancelled(Void aVoid) {
super.onCancelled(aVoid);
}
#Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
}
}
i know this is not a proper way,
i m using webservices to fetch json values and convert it to list<>
by debugging, values do come in List which is lstbatch and lststream,
and array batcharr and streamarr ,
but when the task executes , in on create method , batcharr and streamarr is showing error,
same method worked last time on an Activity
Please help ,
Thank You
Move this code above the Async and it will be accessible
List<String> lstbatch;
List<String> lststream;
public class TPGetListone extends AsyncTask<String, Void, Void> {
String datax = "";
JSONArray array;
//--> Remove to Up -->List<String> lstbatch;
//--> Remove to Up -->List<String> lststream;
private String LogStr = "Panchratna";
EDIT
for (int i=0;i<lststream.size();i++){
batcharr[i]=lststream.get(i);
streamarr[i]=lstbatch.get(i);
}
put this code
lst1.setEntries(batcharr);
lst1.setEntryValues(batcharr);
in
PostExecute method
protected void onPostExecute(Void aVoid) {
Log.i(LogStr, "onPostExecuteCATALOG");
try {
array = new JSONArray(datax);
} catch (JSONException e) {
e.printStackTrace();
}
lstbatch = new ArrayList<String>();
lststream = new ArrayList<String>();
for(int i = 0; i < array.length(); i++){
try {
lstbatch.add(array.getJSONObject(i).getString("batch"));
lststream.add(array.getJSONObject(i).getString("stream"));
} catch (JSONException e) {
e.printStackTrace();
}
}
batcharr = new String[lstbatch.size()];
streamarr = new String[lststream.size()];
for (int i=0;i<lststream.size();i++){
lststream.toArray(batcharr);
lstbatch.toArray(streamarr);
}
===> lst1.setEntries(batcharr);
===> lst1.setEntryValues(batcharr);
}
Related
I'm having a hard time figuring out how to implement the new MyAsyncTask().execute("") that I've searched because I have separate classes that extends Asynctask. I wanted to call the class everytime i click the button. Hope you guys can help me figure this out.
Here is my MainActivity
public class MainActivity extends AppCompatActivity {
String url = "http://192.168.254.103/dbtest/categories.php";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.start);
final ListView lv = (ListView) findViewById(R.id.lv);
final Downloader d = new Downloader(this,url,lv);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
d.execute();
}
});
}
}
Here is my Downloader.java
public class Downloader extends AsyncTask<Void,Integer, String> {
Context c;
String address;
ListView lv;
ProgressDialog pd;
public Downloader(Context c, String address, ListView lv) {
this.c = c;
this.address = address;
this.lv = lv;
}
//BEFORE JOB STARTS
#Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(c);
pd.setTitle("Fetch Data");
pd.setMessage("Please Wait");
pd.show();
}
#Override
protected String doInBackground(Void... params) {
String data = downloadData();
return data;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
pd.dismiss();
if(s != null){
Parser p =new Parser(c,s,lv);
p.execute();
}else
{
Toast.makeText(c,"Unable to download data",Toast.LENGTH_SHORT).show();
}
}
private String downloadData(){
//connect and get a stream
InputStream is = null;
String line = null;
try{
URL url = new URL(address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
is = new BufferedInputStream(con.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer sb = new StringBuffer();
if(br != null){
while((line = br.readLine()) != null)
{
sb.append(line+"\n");
}
}
else
{
return null;
}
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(is != null){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
}
and my Parser.java
public class Parser extends AsyncTask<Void,Integer,Integer> {
Context c;
ListView lv;
String data;
ArrayList<String> categories = new ArrayList<>();
ProgressDialog pd;
public Parser(Context c, String data, ListView lv) {
this.c = c;
this.data = data;
this.lv = lv;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(c);
pd.setTitle("Parser");
pd.setMessage("Please Wait");
pd.show();
}
#Override
protected Integer doInBackground(Void... params) {
return this.parse();
}
#Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
if(integer == 1)
{
//ADAPTER
ArrayAdapter<String> adapter = new ArrayAdapter<String>(c, android.R.layout.simple_list_item_1, categories);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}else
{
Toast.makeText(c,"Unable to Parse",Toast.LENGTH_SHORT).show();
}
pd.dismiss();
}
//PARSE RECEIVED DATA
private int parse(){
try
{
//ADD TGAT DATA TO JSON ARRAY FIRST
JSONArray ja = new JSONArray(data);
//CREATE JO OBJECT TO HOLD A SINGLE ITEM
JSONObject jo = null;
categories.clear();
//LOOP THROUGH ARRAY
for(int i =0 ; i<ja.length();i++)
{
jo = ja.getJSONObject(i);
//RETRIEVE NAME
String name=jo.getString("cat_name");
//ADD TO ARRAY LIST
categories.add(name);
}
return 1;
} catch (JSONException e) {
e.printStackTrace();
}
return 0;
}
}
In my Application I want to retrieve a data from the database. But the problem I am facing is that, the data is fetched from database but it is not displaying at a time when I reopen the page at that time the data is displaying. I want to reload a page when I click on Button.
Here the code is as follow :-
Btngetdata.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new InTimeInsert().execute();
}
});
private class InTimeInsert extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... args) {
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("at_username", uid));
JSONObject json = jParser.makeHttpRequest(url_intime,"GET", params);
//ownerObj = json.getJSONArray("visit");
for (int i = 0; i < ownerObj.length(); i++) {
jsonobject = ownerObj.getJSONObject(i);
time_fetch.add(jsonobject.getString("at_itime"));
}
} catch (Exception e) {
}
return null;
}
#Override
protected void onPostExecute(Void args) {
ina.setText(""+delivery_fetch);
}
}
private class AllAtendence extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... args) {
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("at_username", uid));
JSONObject json = jParser.makeHttpRequest(url_allatendence,"GET", params);
ownerObj = json.getJSONArray("visit");
for (int i = 0; i < ownerObj.length(); i++) {
jsonobject = ownerObj.getJSONObject(i);
delivery_fetch =jsonobject.getString("at_date");
lunch=jsonobject.getString("at_litime");
rejoin=jsonobject.getString("at_lotime");
out=jsonobject.getString("at_otime");
Log.d("at_line",json.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void args) {
ina.setText(""+delivery_fetch);
rejoina.setText(""+lunch);
luncha.setText(""+rejoin);
outa.setText(""+out);
if(ina.getText().toString().equals(""))
{
Btngetdata.setVisibility(View.VISIBLE);
inti.setVisibility(View.GONE);
}
else
{
Btngetdata.setVisibility(View.GONE);
}
if(luncha.getText().toString().equals(""))
{
ltime.setVisibility(View.VISIBLE);
luncht.setVisibility(View.GONE);
}
else
{
ltime.setVisibility(View.GONE);
}
if(rejoina.getText().toString().equals(""))
{
rtime.setVisibility(View.VISIBLE);
rejoint.setVisibility(View.GONE);
}
else
{
rtime.setVisibility(View.GONE);
}
if(outa.getText().toString().equals(""))
{
otime.setVisibility(View.VISIBLE);
outt.setVisibility(View.GONE);
}
else
{
otime.setVisibility(View.GONE);
}
}
}
If you fetch only one data than you can use this to solve your problem..
And use log to see if there is any err on fetching data... on catch block..Good luck.
private class InTimeInsert extends AsyncTask<Void, Void, Void> {
String fetched_data = "";
#Override
protected Void doInBackground(Void... args) {
try {
arraylist = new ArrayList<HashMap<String, String>>();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("at_username", uid));
JSONObject json = jParser.makeHttpRequest(url_intime,"GET", params);
//ownerObj = json.getJSONArray("visit");
for (int i = 0; i < ownerObj.length(); i++) {
jsonobject = ownerObj.getJSONObject(i);
this.fetched_data = jsonobject.getString("at_itime");
}
} catch (Exception e) {
Log.d("fetch err", e.toString());
}
return null;
}
#Override
protected void onPostExecute(Void args) {
ina.setText(""+this.fetched_data);
}
}
//put your code in onResume methods
#Override protected void onResume() {
super.onResume();
// call here
new InTimeInsert().execute();
}
Add .get();, while calling AsyncTask.
Like:
new InTimeInsert().execute().get();
It waits for the result of AsyncTask.
By doing this, will execute the AsyncTask first and then continues with the control flow.
I have a View Pager in my App. The View pager gets the Imagepath from the JSON & shows in a ImageView. The View pager works for the first time. But when the values are changed, it returns a error.
But I have notified the PagerAdapter about the notifyDataSetChanged.
java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 1, found: 0 Pager id: com.hello.hello:id/pager Pager class: class com.hello.hello.utils.ImageViewTouchViewPager Problematic adapter: class com.hello.hello.utils.ZoomAdapter
ASYNCTASK 1
public class FetchPromo extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
promoList = new ArrayList<String>();
progress = new ProgressDialog(getActivity());
progress.setMessage("Fetching Promotions from your Neighbouring store");
progress.show();
progress.setCanceledOnTouchOutside(false);
}
#Override
protected Void doInBackground(Void... params) {
String url = "http://46.101.126.31/mobileapp/gps/api.php?rquest=get_promotions&latitude=" + userLocation.getLatitude() + "&longitude=" + userLocation.getLongitude();
Log.d("Path", url);
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
String jsonData = response.body().string();
try {
JSONObject jsonObject = new JSONObject(jsonData);
store_name = jsonObject.getString("store_name");
JSONArray promo_path = jsonObject.getJSONArray("image_path");
Log.d("Path", store_name);
for (int i = 0; i < promo_path.length(); i++) {
String path = promo_path.getString(i);
promoList.add(path);
}
} catch (JSONException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
store.setText(store_name);
if (promoList.isEmpty()) {
promoList.add(placeholder);
}
mZoomAdapter = new ZoomAdapter(getActivity(), promoList);
mViewPager.setAdapter(mZoomAdapter);
mZoomAdapter.notifyDataSetChanged();
new FetchStore().execute();
progress.dismiss();
}
}
AYNCTASK 2 (where the data has to be loaded again)
public class FetchPromoByID extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
promoList.clear();
progress = new ProgressDialog(getActivity());
progress.setMessage("Fetching Promotions from your Choosen store");
progress.show();
progress.setCanceledOnTouchOutside(false);
}
#Override
protected Void doInBackground(Void... params) {
String url = "http://46.121.116.31/mobileapp/gps/api.php?rquest=get_promotions_by_store_id&store_id=" + Choosen_id;
Log.d("FetchPromoByID", url);
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
String jsonData = response.body().string();
try {
JSONObject jsonObject = new JSONObject(jsonData);
JSONArray promo_path = jsonObject.getJSONArray("image_path");
store_name = jsonObject.getString("store_name");
Log.d("Path", store_name);
for (int i = 0; i < promo_path.length(); i++) {
String path = promo_path.getString(i);
promoList.add(path);
}
} catch (JSONException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
mZoomAdapter = new ZoomAdapter(getActivity(), promoList);
mViewPager.setAdapter(mZoomAdapter);
mZoomAdapter.notifyDataSetChanged();
new FetchStore().execute();
progress.dismiss();
}
}
ADAPTER
public class ZoomAdapter extends PagerAdapter {
private Context context;
private ArrayList<String> IMAGES = new ArrayList<>();
public ZoomAdapter(Context context, ArrayList<String> IMAGES) {
this.IMAGES = IMAGES;
this.context = context;
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
#Override
public int getCount() {
return IMAGES.size();
}
#Override
public View instantiateItem(ViewGroup container, int position) {
String url = IMAGES.get(position);
PhotoView photoView = new PhotoView(container.getContext());
// Now just add PhotoView to ViewPager and return it
container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
Picasso.with(context)
.load(url)
.fit()
.into(photoView);
return photoView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
FetchStore
public class FetchStore extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
storeList = new ArrayList<String>();
storeID = new ArrayList<String>();
}
#Override
protected Void doInBackground(Void... params) {
String url = "http://46.101.116.31/mobileapp/gps/api.php?rquest=get_store";
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
String jsonData = response.body().string();
try {
JSONObject jsonObject = new JSONObject(jsonData);
JSONArray storearray = jsonObject.getJSONArray("stores");
for (int i = 0; i < storearray.length(); i++) {
JSONObject storeobj = storearray.getJSONObject(i);
String store = storeobj.getString("name");
String ID = storeobj.getString("id");
storeList.add(store);
storeID.add(ID);
}
} catch (JSONException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
choose.setVisibility(View.VISIBLE);
}
}
I have found many similar Questions like this. But none of the solution worked for me. Please guide me.
Thanks in Advance
I think your error is here (Async Task #2)
#Override
protected void onPreExecute() {
super.onPreExecute();
promoList.clear();
progress = new ProgressDialog(getActivity());
progress.setMessage("Fetching Promotions from your Choosen store");
progress.show();
progress.setCanceledOnTouchOutside(false);
}
You make promoList.clear() (set the count to 0),which used in ZoomAdapter instance without notifying.
So notify adapter there or make a temporary ArrayList and clear / addAll in onPostExecute
Can't pass data from onPostExecute() to adapter for my AutoComleteTextView. Logcat shows me:
An exception occurred during performFiltering()! java.lang.NullPointerException: collection == null.
public class UzActivity extends Activity {
private static final String DEBUG_TAG = "HttpExample";
List<String> responseList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uz);
final String url = "http://booking.uz.gov.ua/purchase/station/%D0%9A%D0%B8%D0%B5/";
new FetchStationTask().execute(url);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, responseList);
textView.setAdapter(adapter);
}
private class FetchStationTask extends AsyncTask<String, Void, String>{
#Override
protected String doInBackground(String... urls) {
try {
return new UzFetcher().getUrlString(urls[0]);
} catch (IOException e) {
return "Unable to retrieve web page. URL may be invalid.";
}
}
#Override
protected void onPostExecute(String result){
try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
StationResponse st = objectMapper.readValue(result, StationResponse.class);
responseList = new ArrayList<>();
for (int i = 0; i<st.mStations.size(); i++){
responseList.add(st.mStations.get(i).getTitle());
}
Log.i(DEBUG_TAG, responseList.get(0));
} catch (IOException e) {
e.printStackTrace();
}
Log.i(DEBUG_TAG, result);
}
}
java.lang.NullPointerException: collection == null.
ArrayList should be initialized first.
Just add,
responseList = new ArrayList<String>();
after setContentView();
SplashActivity.java {Updated}
public class SplashActivity extends Activity {
/** Called when the activity is first created. */
JSONObject jsonobject;
JSONArray jsonarray;
ArrayList<HashMap<String, String>> arraylist;
private String Content;
DatabaseAdapter db;
TextView txtSplashTitle,txtSplashDesc;
DatabaseAdapter databaseHelper;
Cursor cursor;
//#InjectView(R.id.txtSplashDesc) TextView txtSplashDesc=null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
//ButterKnife.inject(this);//using ButterKnife library for viewInjection
txtSplashDesc=(TextView) findViewById(R.id.txtSplashDesc);
String serverURL = "";
db = new DatabaseAdapter(this);
new LongOperation().execute(serverURL);
freeMemory();
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
//Setting fonts for textviews
setCustomFontForTextViews();
}
private void setCustomFontForTextViews() {
Typeface typeFace = Typeface.createFromAsset(getAssets(), "royalacid.ttf");
txtSplashDesc.setTypeface(typeFace);
}
// Class with extends AsyncTask class
private class LongOperation extends AsyncTask<String, Void, Void> {
private final HttpClient Client = new DefaultHttpClient();
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(SplashActivity.this);
protected void onPreExecute() {
// NOTE: You can call UI Element here.
Dialog.setMessage("Downloading source..");
Dialog.show();
}
// Call after onPreExecute method
protected Void doInBackground(String... urls) {
try {
// NOTE: Don't call UI Element here.
HttpGet httpget = new HttpGet("http://10.0.2.2:3009/findmybuffet/?storedproc=get_app_tables&flag=sudhakar");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
Content = Client.execute(httpget, responseHandler);
jsonobject = new JSONObject(Content);
jsonobject = jsonobject.getJSONObject("findmybuffet");
jsonarray = jsonobject.getJSONArray("buffets");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put("buf_off_id", jsonobject.getString("buf_off_id"));
map.put("from_time", jsonobject.getString("from_time"));
map.put("to_time", jsonobject.getString("to_time"));
map.put("online_price", jsonobject.getString("online_price"));
map.put("reserved_price", jsonobject.getString("reserved_price"));
map.put("buf_image", jsonobject.getString("buf_image"));
map.put("res_name", jsonobject.getString("res_name"));
map.put("rating", jsonobject.getString("rating"));
map.put("latitude", jsonobject.getString("latitude"));
map.put("longitude", jsonobject.getString("longitude"));
map.put("buf_type_name", jsonobject.getString("buf_type_name"));
map.put("from_date", jsonobject.getString("from_date"));
map.put("to_date", jsonobject.getString("to_date"));
map.put("city_id", jsonobject.getString("city_id"));
map.put("city_name", jsonobject.getString("city_name"));
map.put("meal_type_id", jsonobject.getString("meal_type_id"));
map.put("meal_type_name", jsonobject.getString("meal_type_name"));
map.put("buf_desc", jsonobject.getString("buf_desc"));
map.put("distance", jsonobject.getString("distance"));
Log.d("----$$$----", map.toString());
//Calling database
db.addContact(map);
try {
Cursor cursor = (Cursor) databaseHelper.getAllContacts();
cursor.moveToFirst();
if(cursor.moveToFirst()){
do{
String refDestLatitude=cursor.getString(cursor.getColumnIndex(cursor.getColumnName(7)));
Log.d("---#*#*#*#*#*#----", refDestLatitude+"");
}while(cursor.moveToNext());
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("ThrownException", e.toString());
e.printStackTrace();
}
//cursor.close();
}
// Reading all contacts
Log.d("Reading: ", "Reading all contacts..");
} catch (IOException|JSONException e) {
Error = e.getMessage();
cancel(true);
}
return null;
}
protected void onPostExecute(Void unused) {
// Close progress dialog
Dialog.dismiss();
Intent intent=new Intent(SplashActivity.this,MainActivitySherlock.class);
startActivity(intent);
}
}
private void freeMemory() {
jsonobject=null;
jsonarray=null;
arraylist=null;
Content=null;
}
}
When i debugged the app i found as below
I am having problem in the line ::
String refDestLatitude=cursor.getString(cursor.getColumnIndex(cursor.getColumnName(7)));
Cursor is able to get the value
cursor.getColumnIndex(cursor.getColumnName(7))
But exception popps up when
cursor.getString(cursor.getColumnIndex(cursor.getColumnName(4)));
is evaluated
Note:: This line was working when i was handling in adapter ..... but its not working here. do i need to cast a reference or something ?
try like this :
if(c.moveToFirst()){
do{
String refDestLatitude=cursor.getString(cursor.getColumnIndex(cursor.getColumnName(7)));
}while(c.moveToNext())
}
cursor.getString(cursor.getColumnIndex(cursor.getColumnName(7)));
You get an error because there is no column 7.
I have to ask why all the drama when you could just get the data from the column?
if (getColumnCount() > 11) { // 4+7 = 11 fail
cursor.getString(7);
}