2

i have installed on my ubuntu eclipse and the android sdk and adt.

now, if i create a new android project immediately after i create it i see bugs in Mainactivity.java: R cannot be resolved. i added import android.R and now it says that activity_main cannot be resolved or is not a field it says i can change it to activity_list_item but then it lists other bugs. this problem appears also if i import sample projects or project which was done already in an other computer.

i know this question was already asked many times but i couldnt fix it like written there.

thank you,

Boaz Code: MainActivity.java:

package com.example.test;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

 }

BuildConfig.java:

/** Automatically generated file. DO NOT MODIFY */
package com.example.test;

public final class BuildConfig {
public final static boolean DEBUG = true;

} activity_Main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
    android:id="@+id/menu_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/menu_settings"/>

 </menu>
Boaz K
  • 493
  • 1
  • 4
  • 13
  • "i added `import android.R`" You actually [don't want to do this](http://stackoverflow.com/q/11526444/1267661), it is [the wrong R file](http://stackoverflow.com/q/885009/1267661)... – Sam Jan 26 '13 at 19:50
  • remove android.R, check res/layout files for errors and try by the way clean project – deadfish Jan 26 '13 at 20:37

3 Answers3

0

It sounds like a problem with the generated files. If you're using Eclipse, try doing a clean project and make sure your gen folder is in the project build path. If not using Eclipse, make sure your gen folder is in the list of files it tries to build.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

It's probably an error with an XML file that's preventing the build to complete successfully, therefore your R file is not being generated. Click the Error Log or "Problems" tab and make sure there aren't any xml related errors in there.

Either way, import com.example.test.R; is definitely a required import and not android.R

Jade Byfield
  • 4,668
  • 5
  • 30
  • 41
  • it lists it like a bug if i write `import com.example.test.R;` – Boaz K Jan 26 '13 at 20:01
  • Could you post the code to your activity and the logcat? Also, are you trying to use any third party libraries in your app? – Jade Byfield Jan 26 '13 at 20:03
  • i don't use any third party libaries, the code here is just normal code after creating android project, i havent added any code – Boaz K Jan 26 '13 at 20:13
  • Well, import com.example.test.R; is definitely required, since you're trying to inflate your menu using that resId..and I'm sure you're calling setContentView() as well. Import it again, and then right click the project and click "Android Tools --> Fix Project Properties" and see what it suggests – Jade Byfield Jan 26 '13 at 20:16
  • `Description Resource Path Location Type Error executing AAPT: Can not run program "/ home / boaz / android-sdk-linux / platform-tools / AAPT": error = 2, cannot find file or directory: error = 2, file or directory test line 1 Android ADT problem` and `Description Resource Path Location Type layout cannot be resolved or is not a field MainActivity.java /test/src/com/example/test line 15 Java Problem ` are shown as errors – Boaz K Jan 27 '13 at 14:11
  • Try right clicking the errors you found in the Problems tab, and select "delete". Then delete your R.java file(if it exists). Then add then delete a period or something in your code to force Eclipse to rebuild the project. – Jade Byfield Jan 27 '13 at 17:58
0

Ok, I fixed it, i just wrote in terminal sudo apt-get install ia32-libs here: https://askubuntu.com/questions/204694/how-to-install-ia32-lib-on-64-bit-system

Community
  • 1
  • 1
Boaz K
  • 493
  • 1
  • 4
  • 13