1. Download our Official Android App: Forums for Android!

Apps Having trouble referencing R.java data

Discussion in 'Android Development' started by qxc, Apr 26, 2011.

  1. qxc

    qxc Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Apr 26, 2011

    Apr 26, 2011
    5
    0
    5
    I've been working on implementing an RSS feeder based on an old tutorial that I've been following.

    NewsDroid RSS Reader | Hello Android

    There are a number of errors as the tutorial using quite dated syntax and degenerate functions. That aside, I'm having problems with my R.java file.

    This is one of the .xml files I have saved in my res/layout folder called articles_list.xml

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.       android:layout_width="wrap_content"
    4.         android:layout_height="wrap_content">
    5.    
    6.     <ListView android:id="@+id/android:list"
    7.           android:layout_width="wrap_content"
    8.             android:layout_height="wrap_content"/>
    9.       <TextView android:id="@+id/android:empty"
    10.           android:layout_width="wrap_content"
    11.             android:layout_height="wrap_content"
    12.             android:text="Loading articles..."/>
    13. </LinearLayout>
    Correspondingly - my R.java looks like

    Code (Text):
    1.  
    2. /* AUTO-GENERATED FILE.  DO NOT MODIFY.
    3.  *
    4.  * This class was automatically generated by the
    5.  * aapt tool from the resource data it found.  It
    6.  * should not be modified by hand.
    7.  */
    8.  
    9. package newsDroid.com;
    10.  
    11. public final class R {
    12.     public static final class attr {
    13.     }
    14.     public static final class drawable {
    15.         public static final int icon=0x7f020000;
    16.     }
    17.     public static final class id {
    18.         public static final int cancel=0x7f050002;
    19.         public static final int ok=0x7f050003;
    20.         public static final int text1=0x7f050000;
    21.         public static final int url=0x7f050001;
    22.     }
    Code (Text):
    1.  
    2.     public static final class layout {
    3.         public static final int article_row=0x7f030000;
    4.         public static final int articles_list=0x7f030001;
    5.         public static final int feeds_list=0x7f030002;
    6.         public static final int feeds_row=0x7f030003;
    7.         public static final int main=0x7f030004;
    8.         public static final int url_editor=0x7f030005;
    9.     }
    Code (Text):
    1.  
    2.     public static final class string {
    3.         public static final int app_name=0x7f040000;
    4.         public static final int articles_list=0x7f040006;
    5.         public static final int button_cancel=0x7f040004;
    6.         public static final int button_ok=0x7f040003;
    7.         public static final int menu_delete=0x7f040002;
    8.         public static final int menu_insert=0x7f040001;
    9.         public static final int url_editor=0x7f040005;
    10.     }
    11. }

    articles_list is appearing in the appropriate place in the R.java file. But when I reference said file in my code as seen below:

    Code (Text):
    1. setContentView(R.layout.articles_list);
    I get the error that "articles_list cannot be resolved or is not a field."

    I have the same problem with my other layouts as well as all the strings I have saved in strings.xml. I don't understand why I can't reference the data members that are clearly present in R.java.

    Thanks.
     

    Advertisement

  2. tws5d

    tws5d Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 26, 2011

    Apr 26, 2011
    1
    0
    5
    Have you tried scanning the island? That usually works for me. ;)
     
  3. Narp

    Narp Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 26, 2011

    Apr 26, 2011
    1
    0
    5
    I think some cloaked banshees hit your code :/
    <3
     
  4. TzaGear

    TzaGear Lurker
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Apr 26, 2011

    Apr 26, 2011
    5
    0
    5
    Can you share the code for setContentView?



    EDIT:
    Any warnings about the id's in your xml files?
    vs


    EDIT 2:
    Check for wandering 'import android.R's as they will frag your build.
    Your R.Java is being built right? You are not trying to do it manually.



    (No insults intended, just troubleshooting blind based on things I have experienced in the past for myself and others I have helped.)
     
  5. qxc

    qxc Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Apr 26, 2011

    Apr 26, 2011
    5
    0
    5
    No warnings about the ids.

    setContentView is a member function for the Activity class.
    Activity | Android Developers

    I havn't touched R.java - it's all been built by the compiler automatically.

    Turns out the tutorial included import android.R in a few files. Changing that fixed it. Thanks.
     
  6. TzaGear

    TzaGear Lurker
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Apr 26, 2011

    Apr 26, 2011
    5
    0
    5
    Glad to hear it! If you start any other topics be sure to throw a @tzagear on twitter and I would be happy to help. Client work rarely gets me to work with fun things like Android.


    (sidenote, sry about the first question, I thought one thing typed another. Doesn't matter now but I was asking about the code around the use of setContentView :/ just for clarification.)
     

Share This Page

Loading...