Response received from web service is null - java

I am sending details to be stored in a database using a web service using KSOAP. I have used visual studio to create the web service. The web service works fine. A string will be returned when the details have been inserted into the database. The problem is that this string is empty, maybe something is wrong in the way that i am getting the response. I have been trying to find out whats wrong for a long time. please help
public class Registration extends Activity{
private static final String SOAP_ACTION = "http://tempuri.org/register";
private static final String OPERATION_NAME = "register";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:58076/WebSite1/Service.asmx";
Button sqlRegister, sqlView;
EditText sqlFirstName,sqlLastName,sqlEmail,sqlMobileNumber,sqlCurrentLocation,sqlUsername,sqlPassword;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
sqlFirstName = (EditText) findViewById(R.id.etFname);
sqlLastName = (EditText) findViewById(R.id.etLname);
sqlEmail = (EditText) findViewById(R.id.etEmail);
sqlMobileNumber = (EditText) findViewById(R.id.etPhone);
sqlCurrentLocation = (EditText) findViewById(R.id.etCurrentLoc);
sqlUsername = (EditText) findViewById(R.id.etUsername);
sqlPassword = (EditText) findViewById(R.id.etPwd);
sqlRegister = (Button) findViewById(R.id.bRegister);
sqlRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
switch (v.getId()){
case R.id.bRegister:
new LongOperation().execute("");
break;
}
}
});
}
private class LongOperation extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
String firstname = sqlFirstName.getText().toString();
String lastname = sqlLastName.getText().toString();
String emailadd = sqlEmail.getText().toString();
String number = sqlMobileNumber.getText().toString();
String loc = sqlCurrentLocation.getText().toString();
String uname = sqlUsername.getText().toString();
String pwd = sqlPassword.getText().toString();
SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
Request.addProperty("fname", String.valueOf(firstname));
Request.addProperty("lname", String.valueOf(lastname));
Request.addProperty("email", String.valueOf(emailadd));
Request.addProperty("num", String.valueOf(number));
Request.addProperty("loc", String.valueOf(loc));
Request.addProperty("username", String.valueOf(uname));
Request.addProperty("password", String.valueOf(pwd));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Log.d("work","work");
try
{
httpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
String result = response.getProperty(0).toString();
Log.d("res",result);
if(result.equals("reg"))
{
Log.d("reg","reg");
return "Registered";
}
else
{
Log.d("no","no");
return "Not Registered";
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
Log.d("tag","onpost");
if(result!=null)
{
if(result.equals("Registered"))
{
Toast.makeText(Registration.this, "You have been registered Successfully", Toast.LENGTH_LONG).show();
}
else if(result.equals("Not Registered"))
{
Toast.makeText(Registration.this, "Try Again", Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(Registration.this, "Somethings wrong", Toast.LENGTH_LONG).show(); ///This is what gets printed on screen
}
}
#Override
protected void onPreExecute() {
}
#Override
protected void onProgressUpdate(Void... values) {
}
}
}

Your webservice is returning a String.
Try using this to solve your problem
Object result = envelope.getResponse();
when your webservice return values of type byte[] ,you can do this:
SoapObject response=(SoapObject)envelope.bodyIn;
Hope it helps

Related

Something Strange at my android code

This is my code in a class that extends Asynctask and its doInBackground() method:
//Building Parameters
List<NameValuePair> paramss = new ArrayList<NameValuePair>();
paramss.add(new BasicNameValuePair(TAG_EMAIL, email));
//getting JSON string from url
JSONObject json = parser.makeHttpRequest(url_get_one_member, "POST",paramss);
Log.d("Ambil Member",json.toString());
//cari tag success
try{
int success = json.getInt(TAG_SUCCESS);
if(success == 1){
member = json.getJSONArray(TAG_MEMBER);
JSONObject jObject = member.getJSONObject(0);
String emaill = jObject.getString(TAG_EMAIL);
String nama = jObject.getString(TAG_NAMA);
String alamat = jObject.getString(TAG_ALAMAT);
String no_telp = jObject.getString(TAG_NO_TELP);
String umur = jObject.getString(TAG_UMUR);
String tempatLahir = jObject.getString(TAG_TEMPAT_LAHIR);
String tglLahir = jObject.getString(TAG_TANGGAL_LAHIR);
String jlhPeliharaan = jObject.getString(TAG_JUMLAH_PELIHARAAN);
String warna = jObject.getString(TAG_WARNA_FAVORIT);
String jenisKelamin = jObject.getString(TAG_JENIS_KELAMIN);
String kota = jObject.getString(TAG_JENIS_KOTA);
//masukin semuanya ke variabel
txt_email.setText(emaill);
txt_nama.setText(nama);
txt_alamat.setText(alamat);
txt_no_telp.setText(no_telp);
txt_umur.setText(umur);
txt_tempat_lahir.setText(tempatLahir);
txt_tanggal_lahir.setText(tglLahir);
txt_jumlah_peliharaan.setText(jlhPeliharaan);
txt_warna_favorit.setText(warna);
if(jenisKelamin.equals("1")){
txt_jenis_kelamin.setText("Pria");
} else {
txt_jenis_kelamin.setText("Wanita");
}
txt_id_kota.setText(kota);
}
}catch (JSONException ex){
ex.printStackTrace();
}
return null;
Sometimes it works, sometimes it doesn't.
I've checked my logcat, the json.toString() is working but I can't set all the text to the TextView.
In onCreate() I've been initializing them all:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_profile);
//textview
txt_email = (TextView) findViewById(R.id.txt_email);
txt_nama = (TextView) findViewById(R.id.txt_nama);
txt_alamat = (TextView) findViewById(R.id.txt_alamat);
txt_no_telp = (TextView) findViewById(R.id.txt_no_telp);
txt_umur = (TextView) findViewById(R.id.txt_umur);
txt_tempat_lahir = (TextView) findViewById(R.id.txt_tempat_lahir);
txt_tanggal_lahir = (TextView) findViewById(R.id.txt_tanggal_lahir);
txt_jumlah_peliharaan = (TextView) findViewById(R.id.txt_jumlah_peliharaan);
txt_jenis_kelamin = (TextView) findViewById(R.id.txt_jenis_kelamin);
txt_warna_favorit = (TextView) findViewById(R.id.txt_warna_favorit);
txt_id_kota = (TextView) findViewById(R.id.txt_id_kota);
//button
buttonLogout = (Button) findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(new android.view.View.OnClickListener() {
#Override
public void onClick(View v) {
prefs = getSharedPreferences("login", Context.MODE_PRIVATE);
editor = prefs.edit();
editor.clear();
editor.commit();
Intent backToLogin = new Intent(Profile.this,Login.class);
startActivity(backToLogin);
finish();
}
});
btnEditProfil = (Button) findViewById(R.id.btnEditProfil);
btnEditProfil.setOnClickListener(new android.view.View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentEdit = new Intent(getApplicationContext(),EditProfile.class);
intentEdit.putExtra("emailMember", email);
startActivity(intentEdit);
}
});
btnPeliharaan = (Button) findViewById(R.id.btnPeliharaan);
btnPeliharaan.setOnClickListener(new android.view.View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentPeliharaan = new Intent(getApplicationContext(),ShowPeliharaan.class);
startActivity(intentPeliharaan);
}
});
//nagmbil email
Intent intent = getIntent();
email = intent.getStringExtra("emailMember");
new LoadMember().execute();
}
Write your AsyncTask class like this:
private class MyAsyncTask extends AsyncTask<String, Void, String>{
#Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
List<NameValuePair> paramss = new ArrayList<NameValuePair>();
paramss.add(new BasicNameValuePair(TAG_EMAIL, email));
//getting JSON string from url
JSONObject json = parser.makeHttpRequest(url_get_one_member, "POST",paramss);
Log.d("Ambil Member",json.toString());
return json.toString();
}
#Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
JSONObject json=new JSONObject(result);
try{
int success = json.getInt(TAG_SUCCESS);
if(success == 1){
member = json.getJSONArray(TAG_MEMBER);
JSONObject jObject = member.getJSONObject(0);
String emaill = jObject.getString(TAG_EMAIL);
String nama = jObject.getString(TAG_NAMA);
String alamat = jObject.getString(TAG_ALAMAT);
String no_telp = jObject.getString(TAG_NO_TELP);
String umur = jObject.getString(TAG_UMUR);
String tempatLahir = jObject.getString(TAG_TEMPAT_LAHIR);
String tglLahir = jObject.getString(TAG_TANGGAL_LAHIR);
String jlhPeliharaan = jObject.getString(TAG_JUMLAH_PELIHARAAN);
String warna = jObject.getString(TAG_WARNA_FAVORIT);
String jenisKelamin = jObject.getString(TAG_JENIS_KELAMIN);
String kota = jObject.getString(TAG_JENIS_KOTA);
//masukin semuanya ke variabel
txt_email.setText(emaill);
txt_nama.setText(nama);
txt_alamat.setText(alamat);
txt_no_telp.setText(no_telp);
txt_umur.setText(umur);
txt_tempat_lahir.setText(tempatLahir);
txt_tanggal_lahir.setText(tglLahir);
txt_jumlah_peliharaan.setText(jlhPeliharaan);
txt_warna_favorit.setText(warna);
if(jenisKelamin.equals("1")){
txt_jenis_kelamin.setText("Pria");
} else {
txt_jenis_kelamin.setText("Wanita");
}
txt_id_kota.setText(kota);
}
}catch (JSONException ex){
ex.printStackTrace();
}
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
}

JSON Query Does Not Update TextView

I have 3 textviews which I am attempting to update with data pulled via JSON - I'm not getting any errors with what I've built so far - but the textviews (nameTv, contentTv and publishedTv) don't seem to update with the data from my JSON query.
public class Player extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
public static final String API_KEY = "XXXXXXXXXXXXXXXXXXXXX";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
String title = getIntent().getStringExtra("title");
String uploader = getIntent().getStringExtra("uploader");
String viewCount = getIntent().getStringExtra("viewCount");
TextView titleTv = (TextView) findViewById(R.id.titleTv);
TextView uploaderTv = (TextView) findViewById(R.id.uploaderTv);
TextView viewCountTv = (TextView) findViewById(R.id.viewCountTv);
titleTv.setText(title);
uploaderTv.setText("by" + uploader + " |");
viewCountTv.setText(viewCount + " views");
YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
youTubePlayerView.initialize(API_KEY, this);
GetYouTubeUserCommentsTask task = new GetYouTubeUserCommentsTask(null, viewCount);
task.execute();
}
#Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult result) {
Toast.makeText(getApplicationContext(), "onInitializationFailure()",
Toast.LENGTH_LONG).show();
}
#Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
String video_id = getIntent().getStringExtra("id");
player.loadVideo(video_id);
}
}
public final class GetYouTubeUserCommentsTask extends
AsyncTask<Void, Void, Void> {
public static final String LIBRARY = "CommentsLibrary";
private final Handler replyTo;
private final String username;
String video_id = getIntent().getStringExtra("id");
public GetYouTubeUserCommentsTask(Handler replyTo, String username) {
this.replyTo = replyTo;
this.username = username;
}
#Override
protected Void doInBackground(Void... arg0) {
try {
HttpClient client = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(
"http://gdata.youtube.com/feeds/api/videos/"
+ video_id
+ "/comments?v=2&alt=json&start-index=1&max-results=50&prettyprint=true");
HttpResponse response = client.execute(request);
String jsonString = StreamUtils.convertToString(response
.getEntity().getContent());
JSONObject json = new JSONObject(jsonString);
JSONArray jsonArray = json.getJSONObject("data").getJSONArray(
"items");
List<Comments> comments = new ArrayList<Comments>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String content = jsonObject.getString("content");
String published = jsonObject.getString("published");
comments.add(new Comments(name, content, published));
TextView nameTv = (TextView) findViewById(R.id.name);
nameTv.setText(jsonObject.getString("name"));
TextView contentTv = (TextView) findViewById(R.id.content);
contentTv.setText(jsonObject.getString("content"));
TextView publishedTv = (TextView) findViewById(R.id.published);
publishedTv.setText(jsonObject.getString("published"));
}
CommentsLibrary lib = new CommentsLibrary(username, comments);
Bundle data = new Bundle();
data.putSerializable(LIBRARY, lib);
Message msg = Message.obtain();
msg.setData(data);
replyTo.sendMessage(msg);
} catch (ClientProtocolException e) {
Log.e("Feck", e);
} catch (IOException e) {
Log.e("Feck", e);
} catch (JSONException e) {
Log.e("Feck", e);
}
return null;
}
#Override
protected void onPostExecute(Void result) {
}
}
}
You can not access the UI in doInBackground() -- please see the documentation. You will need to deliver the results to onPostExecute() and handle your UI updates there.

Web service (.net ), not working as expected

I've programmed ( actually followed a tutorial ) simple web service in android, using Ksoap libary. But it seems that it doesn't work well. Below is my simple code:
public class MainActivity extends Activity {
TextView tv;
SoapPrimitive response;
final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
final String METHOD_NAME = "CelsiusToFahrenheit";
final String NAMESPACE = "http://www.tempuri.org/";
final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getValue();
}
});
}
private void getValue() {
SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
soapObject.addProperty("Celsius", "33");
SoapSerializationEnvelope serial = new SoapSerializationEnvelope(SoapEnvelope.VER11);
serial.dotNet = true;
serial.setOutputSoapObject(soapObject);
HttpTransportSE transport = new HttpTransportSE(URL);
try {
transport.call(SOAP_ACTION, serial);
response = (SoapPrimitive) serial.getResponse();
tv.setText(response+"");
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
}
I only get a response "Error" in my text view. Can anyone tell me what is wrong here?
I found what was wrong. I wrote:
final String NAMESPACE = "http://www.tempuri.org/";
instead of
final String NAMESPACE = "http://tempuri.org/";
It's working now.

Retrieve email belonging to username in android

I have to develop a login form android application.Here, i have to enter the username and password. If it is correct, fetch the email belonging to the username and display it in the textview and if the username and password is wrong, display login failed message.
This is my webservice code:
public class Login {
public String authentication(String username,String password) {
String retrievedUserName = "";
String retrievedPassword = "";
String retrievedEmail = "";
String status = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_customers WHERE login = '"+username+"'");
ResultSet result = statement.executeQuery();
while(result.next()){
retrievedUserName = result.getString("login");
retrievedPassword = result.getString("password");
retrievedEmail = result.getString("email");
}
if(retrievedUserName.equals(username)&&retrievedPassword.equals(password)&&!(retrievedUserName.equals("") && retrievedPassword.equals(""))){
status = "Success";
}
else {
status = "Login fail!!!";
}
}
catch(Exception e){
e.printStackTrace();
}
return status;
}
};
This is my android code:
public class CustomerLogin extends Activity {
private static final String SPF_NAME = "vidslogin";
private static final String USERNAME = "login";
private static final String PASSWORD = "password";
private static final String PREFS_NAME = null;
CheckBox chkRememberMe;
private String login;
String mGrandTotal,total,mTitle;
EditText username,userPassword;
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://10.0.0.75:8085/XcartLogin/services/Login?wsdl";
private final String SOAP_ACTION = "http://xcart.com/authentication";
private final String METHOD_NAME = "authentication";
private String uName;
/**Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customer_login);
Bundle b = getIntent().getExtras();
total = b.getString("GrandTotal");
mTitle = b.getString("Title");
TextView grandtotal = (TextView) findViewById(R.id.grand_total);
grandtotal.setText("Welcome ," + mTitle );
chkRememberMe = (CheckBox) findViewById(R.id.rempasswordcheckbox);
username = (EditText) findViewById(R.id.tf_userName);
userPassword = (EditText) findViewById(R.id.tf_password);
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
username.setText(loginPreferences.getString(USERNAME, ""));
userPassword.setText(loginPreferences.getString(PASSWORD, ""));
Button login = (Button) findViewById(R.id.btn_login);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
loginAction();
}
});
}
private void loginAction(){
boolean isUserValidated = true;
boolean isPasswordValidated = true;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText username = (EditText) findViewById(R.id.tf_userName);
String user_Name = username.getText().toString();
EditText userPassword = (EditText) findViewById(R.id.tf_password);
String user_Password = userPassword.getText().toString();
//Pass value for userName variable of the web service
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("username");//Define the variable name in the web service method
unameProp.setValue(user_Name);//set value for userName variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable
//Pass value for Password variable of the web service
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
String status = response.toString();
TextView result = (TextView) findViewById(R.id.tv_status);
result.setText(response.toString());
if(status.equals("Success")) {
// ADD to save and read next time
String strUserName = username.getText().toString().trim();
String strPassword = userPassword.getText().toString().trim();
if (null == strUserName || strUserName.length() == 0) {
// showToast("Enter Your Name");
username.setError( "username is required!" );
isUserValidated = false;
}
if (null == strPassword || strPassword.length() == 0) {
// showToast("Enter Your Password");
isPasswordValidated = false;
userPassword.setError( "password is required!" );
}
if (isUserValidated = true && isPasswordValidated == true) {
if (chkRememberMe.isChecked()) {
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
loginPreferences.edit().putString(USERNAME, strUserName).putString(PASSWORD, strPassword).commit();
}
else {
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
loginPreferences.edit().clear().commit();
}
}
if (isUserValidated && isPasswordValidated) {
Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);
intent.putExtra("GrandTotal", total);
intent.putExtra("Title", mTitle);
intent.putExtra("login",username.getText().toString());
startActivity(intent);
}
}
else {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_custom_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.TOP, 0, 30);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
catch(Exception e){
}
}
}
If the login is success, it will have to display the email on textview. How can i do that?
You can use asy task to do this,
in doInBackground
Do your login operations. Asyctask makes this operation in another task.
when complated in onPostExecute
show the success message. But you need to use runOnUiThread because you cant reach ui controls from non ui thread.
private class loginTask extends AsyncTask<URL, Integer, int> {
protected Long doInBackground(URL... urls) {
// start login process
return 1;
}
protected void onPostExecute(int result) {
_activity.runOnUiThread(new Runnable() {
#Override
public void run() {
textview.setText("login success");
}
});
}
}

Using AsyncTask and returning values to the UI main thread

I have an Android activity to display the output of a web service. I've called the web service inside another private class which extends AsyncTask, and want to return a value to the main UI thread.
This is my activity.
public class CallCalcService extends Activity {
private String METHOD_NAME = "sum"; // our webservice method name
private String NAMESPACE = "http://backend.android.web.org";
private String SOAP_ACTION = NAMESPACE + METHOD_NAME;
private static final String URL = "http://192.168.1.14:8080/AndroidBackend1/services/Calculate?wsdl";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_calc_service);
//TextView tv = (TextView) findViewById(R.id.textView1);
//Object res=new HardWorkThread().execute();
//tv.setText("Addition : "+ res.toString());
new HardWorkThread()
{
public void onPostExecute(String result)
{
TextView txt = (TextView) findViewById(R.id.textView1);
txt.setText("Addition : "+result);
}
}.execute("");
}
private class HardWorkThread extends AsyncTask{
#Override
protected String doInBackground(Object... params) {
// TODO Auto-generated method stub
String result=null;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("i", 5);
request.addProperty("j", 15);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION,envelope);
result = envelope.getResponse().toString();
System.out.println("Result : " + result);
//((TextView) findViewById(R.id.textView1)).setText("Addition : "+ result.toString());
} catch (Exception E) {
E.printStackTrace();
//((TextView) findViewById(R.id.textView1)).setText("ERROR:"
// + E.getClass().getName() + ":" + E.getMessage());
}
return result;
}
}
}
What I want to do is return the String result value to the main UI, so that I can set that value to the textview.
String result;
TextView tv=findViewById(R.id.textView1);
tv.setText(result);
How might I do this?
You should Override the onPostExecute() method.
Something like this :
#Override
protected void onPostExecute(String result) {
TextView tv = findViewById(R.id.textView1);
tv.setText(result);
}

Categories

Resources