• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Must include project R file

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm fairly new to Android. I've done several small projects (in Eclipse Juno) and just started a new one. Up to now, I have not had to specifically import my project's R file. Suddenly, on my latest project, I must import the project's R file to resolve any of my layouts. Can anyone give me a clue as to why this might be? I have tried doing a clean on the project, but that did not help. I do not have android.R included anywhere to conflict. Thanks in advance - Mike
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The R stub file is automatically generated by your IDE?
You need to compile the Code and R stubs are automatically generated. Are there any other errors in your project?
Try to fix them and recompile your code.
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, may be it's stupid. You are doing a clean, but are you building it again?
 
Marshal
Posts: 4796
601
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arun Kumarr wrote:The R stub file is automatically generated by your IDE?
You need to compile the Code and R stubs are automatically generated. Are there any other errors in your project?
Try to fix them and recompile your code.


I believe that he is referring to android.R, not the generated R.java file.
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah!! Yes. I think that is what he is mentioning.
In my computer my R file is present inside the jar "..sdk\platforms\android-22\android.jar" at the location android\R.class".
I use version 22 of the sdk. Hence 'android-22' in the directory path.

But wait! Are you not using any android development tool to develop?
If not, start using one. I use the Android Studio built on top of IntelliJ Idea IDE.
You can also use Eclipse for development. But Android Studio is the official supported development environment for android.
I suggest you migrate any old projects (if present) or develop any new projects using android studio.
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arun Kumarr wrote:Ah!! Yes. I think that is what he is mentioning.
In my computer my R file is present inside the jar "..sdk\platforms\android-22\android.jar" at the location android\R.class".
I use version 22 of the sdk. Hence 'android-22' in the directory path.

But wait! Are you not using any android development tool to develop?
If not, start using one. I use the Android Studio built on top of IntelliJ Idea IDE.
You can also use Eclipse for development. But Android Studio is the official supported development environment for android.
I suggest you migrate any old projects (if present) or develop any new projects using android studio.



Arun - Yes, the R.java file is being generated automatically and I did rebuild after my clean. I'm using the Android plugins for Eclipse. I'm going through the Big Nerd Ranch Android book which uses this environment. I'll probably stay with Eclipse for that reason until I finish the book and then switch over to Android Studio.
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great. Can you post the error message and your code?
 
Ron McLeod
Marshal
Posts: 4796
601
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Tabak wrote:I'm going through the Big Nerd Ranch Android book which uses this environment.



You application is probably needing android.R.layout.simple_list_item_1 as one of the parameters for an ArrayAdapter.
 
Ron McLeod
Marshal
Posts: 4796
601
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this what you are trying?
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arun Kumarr wrote:Great. Can you post the error message and your code?



There is no real error message other than Eclipse marking anything R.xxxx as unresolvable when you comment out the R.java import. Here are the files
that have the problem:





My main activity:


Here is the R.java file:



My manifest:

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had this same problem a lot when I used Eclipse which is why switching to Android Studio might be the fastest solution.
 
Arun Kumarr
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you check if the android jars are present in class path, in eclipse?
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arun Kumarr wrote:Can you check if the android jars are present in class path, in eclipse?


android.jar and android-support-v4.jar are in the path. I appear to have the same jars as another project which does not have this problem.
 
Ron McLeod
Marshal
Posts: 4796
601
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you restate the problem? It is unclear if there is actually something wrong, or you are just wondering why android.R and/or your project's R class is needed.
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Can you restate the problem? It is unclear if there is actually something wrong, or you are just wondering why android.R and/or your project's R class is needed.



The project acutally works file. The question is why I have to specifically import the R file in my sources. I normally don't have to do this. I created a new project today and did not have to import my R file. I don't recall specifically what I did when I created the project in question, but I noticed that the package for my source is "com.bignerdranch.android.draganddraw" and the R file is in the package "com.example.dragandgraw". So it's not in the same package - so I must import it. In the project I created today, the base source package is "com.bignerdranch.android.runtracker" and the R file is in the package "com.bignerdranch.android.runtracker". They are in the same package - no need to import R. The question now is what did I do in the previous project to get the R file in a different package?...I don't remember.

I guess this mystery is somewhat solved.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic