Results 1 to 3 of 3
  1. #1
    StateMachine is offline Member
    Join Date
    Dec 2011
    Posts
    22
    Rep Power
    0

    Question How to make Eclipse find stuff inside same package?

    Under one and the same project in the package explorer, I have a class under a package under an src-folder, and I have a file named main.xml under a folder res/layout. This is default for Android SDK.

    Now, my class cannot resolve R.layout.main "It's not a field".

    My class is copy and paste from this tutorial, see chapter 6.6 for the code
    Android 4.0 Development Tutorial
    The line with R.layout.main is inside this block:
    Java Code:
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
    		text = (EditText) findViewById(R.id.editText1);
    	}
    There's a picture of the package explorer in chapter 6.1 in the same tutorial. Everything id identical at my place as in the tutorial, except that I have SDK for Android 3.1 and the tutorial is for Android 4.0. But I can't imagine that matters for a basic thing like this! Everything ran smoothly when following the tutorial, up until this point.

    So there must be some search path-thingie-setting with Eclipse that's out of order.

    How do I force Eclipse to make a class care about that there exists a resource inside its own project? How do I make one thing find another thing in Eclipse? (I've had similar problems before, then without Android stuff) I have Eclipse 3.7.0.

    I want to understand the stuff about build path, link source and such, anyone got some good link to explanations of it? There's no point with learning java and advanced programming concepts, if one doesn't know how do administer trivial file search paths.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: How to make Eclipse find stuff inside same package?

    except that I have SDK for Android 3.1 and the tutorial is for Android 4.0
    this actually does matter if your manifest file is set to minSdkVersion equivalent to Android 4.0


    Is your main.xml file empty or have you copied that also?

    It should be in res > layout > main.xml

    Also try saving, closing and reopening the project.

    The R.java file is auto-generated, so if you copied and pasted a bunch of stuff it might have not generated the updated code yet.

  3. #3
    StateMachine is offline Member
    Join Date
    Dec 2011
    Posts
    22
    Rep Power
    0

    Default Re: How to make Eclipse find stuff inside same package?

    Thanx for your answer!
    Restarting and saving seems to fix things here.
    And I've noticed that sometimes Eclipse marks things as errors, although they aren't. Sometimes just running it anyway eliminates them.

    I did have the R.java auto generated step by step.
    I will look into the version 3.1 and 4 stuff in the future.
    Thanks!

    As a newbie, I'm in the mess of on the one hand kinda understanding some really abstract concepts of some design patterns I've read about. And on the other hand being completely lost as to what to click next in the Eclipse djungle... A bit like a rocket scientist not knowing which way to unscrew a screw (but with reservations for the rocket scientist part of it though )
    Last edited by StateMachine; 12-27-2011 at 09:23 PM.

Similar Threads

  1. Replies: 0
    Last Post: 09-14-2011, 07:52 AM
  2. Replies: 0
    Last Post: 06-13-2011, 09:16 PM
  3. Searching through folder to find text inside all files
    By dazzabiggs in forum New To Java
    Replies: 3
    Last Post: 05-03-2011, 01:20 PM
  4. run package inside anthor package
    By AhmedAdel in forum AWT / Swing
    Replies: 4
    Last Post: 04-20-2010, 11:52 AM
  5. Replies: 1
    Last Post: 03-04-2010, 04:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •