How to resolve error with unnotified resource in R.java

Put your problem here if it does not fit any of the other categories.

How to resolve error with unnotified resource in R.java

Postby gvkreddyvamsi » Wed Feb 20, 2008 7:08 am

hi,


i have this coding for web service ....but didn't initialize resource location R.id.ws_response

how we can set new id tag in R.java ..how can hot code maually


here is my code.


package com.androidi.webservices;
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. import org.apache.commons.httpclient.HttpClient;
  5.  
  6. import org.apache.commons.httpclient.methods.GetMethod;
  7.  
  8.  
  9.  
  10. import android.app.Activity;
  11.  
  12. import android.os.Bundle;
  13.  
  14. import android.util.Log;
  15.  
  16. import android.widget.TextView;
  17.  
  18.  
  19.  
  20. public class CallingWebServices extends Activity {
  21.  
  22.     /** Called when the activity is first created. */
  23.  
  24.     @Override
  25.  
  26.     public void onCreate(Bundle icicle) {
  27.  
  28.         super.onCreate(icicle);
  29.  
  30.         setContentView(R.layout.main);
  31.  
  32.         HttpClient client = new HttpClient();
  33.  
  34.  
  35.  
  36.         GetMethod get = new GetMethod("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=MXN");
  37.  
  38.  
  39.  
  40.         try {
  41.  
  42.                         int status = client.executeMethod(get);
  43.  
  44.                         TextView resultado=(TextView)findViewById(R.id.ws_response); // <-- Error here
  45.  
  46.                         String res="";
  47.  
  48.  
  49.  
  50.                         if(status!=404)
  51.  
  52.                                 res=get.getResponseBodyAsString();
  53.  
  54.                         else
  55.  
  56.                                 res=getString(R.string.ws_not_found);
  57.  
  58.                         resultado.setText(res);
  59.  
  60.                 }
  61.  
  62.                 catch (Exception e) {
  63.  
  64.                         Log.e("Error:",e.getMessage());
  65.  
  66.                 }
  67.  
  68.                 finally {
  69.  
  70.                         get.releaseConnection();
  71.  
  72.                         get=null;
  73.  
  74.                 }
  75.  
  76.  
  77.  
  78.     }
  79.  
  80.  
  81.  
  82. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



except that no problem with remaining code.
even i set string.xml and other things
plz suggest how i can..


by
vamsi
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Top

Postby plusminus » Wed Feb 20, 2008 10:30 am

Hello vamsi,

please show us your layout-file (main.xml).

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

this is layout file

Postby gvkreddyvamsi » Wed Feb 20, 2008 12:22 pm

i have added layout file


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13. <TextView  
  14.  
  15.    android:layout_width="fill_parent"
  16.  
  17.    android:layout_height="wrap_content"
  18.  
  19.    android:text="Hello World, CallingWebServices"
  20.  
  21.    />
  22.  
  23. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Postby plusminus » Wed Feb 20, 2008 2:18 pm

Hello vamsi,

in this line :darrow: you are trying to retrieve a (Text)View you should have defined in the xml layout using the id: "R.id.ws_response"
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. TextView resultado=(TextView)findViewById(R.id.ws_response);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


You'll have to add the following line to the TextView:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:id="@+id/ws_response"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

to make that View accessible from java code.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 28 guests