I updated several of my files but they do not appear as id #s in R.java. I tried updating my imports, I tried closing then opening Eclipse, saving, and closing/opening the Emulator, but it is not working to get R.Java to recognize the updates in the files. Of the items that are missing from R.java are 2 buttons (with 2 services) which would activate a toast when pressed, I will list the files below, each one. I run the emulator (Virtual, Nexus API 17) and it shows an old version of my app that has no buttons, only text that says "Hello World". Thanks in advance.
UPDATE: I tried to clean my project (thinking that if the R.java got regenerated, then it might update itself), but it just made the R.java disappear, and created an error in the main folder, HelloWorld in the Package Explorer. Oddly enough, there were no other errors in the entire series of files that I edited. No yellow warnings, nothing. Plus I never edited the R.java file (I know it's a no-no). So then after I tried to run my project anyway, this error posted in the LogCat below.
I found this in the LogCat:
01-03 06:54:13.977: E/ThrottleService(300): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
Here are my files:
MainActivity.java
package com.example.helloworld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// Method to start the service
public void startService(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
// Method to stop the service
public void stopService(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
}
MyService.java
package com.example.helloworld;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button android:id="@+id/btnStartService"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/start_service"
android:onClick="startService"/>
<Button android:id="@+id/btnStopService"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/stop_service"
android:onClick="stopService" />
</LinearLayout>
strings.xml
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="start_service">Start Service</string>
<string name="stop_service">Stop Service</string>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".MyService" />
</application>
</manifest>
and finally, the R.java (which ignores many strings and other names)
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.example.helloworld;
public final class R {
public static final class attr {
}
public static final class dimen {
/** Default screen margins, per the Android Design guidelines.
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
*/
public static final int activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int action_settings=0x7f080000;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int main=0x7f070000;
}
public static final class string {
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int hello_world=0x7f050002;
}
public static final class style {
/**
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
API 11 theme customizations can go here.
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
API 14 theme customizations can go here.
*/
public static final int AppBaseTheme=0x7f060000;
/** Application theme.
All customizations that are NOT specific to a particular API-level can go here.
*/
public static final int AppTheme=0x7f060001;
}
}
After great help from everyone, the final solution was to begin a new project, then copy/paste each important file back into it, including updating the AndroidManifest.xml file. However, the order of operations was very important. The rebuild did not work if I copy and pasted the MainActivity.java file first, rebuilding that way gave me that odd HelloWorld folder error with no other errors in all my other files. So I thought maybe rebuilding in a certain order would work, and it did.
I had to do the rebuild in this order:
<service>
tags)I then updated all imports and saved everything, and low and behold, R.java was updated with the right ids for all of my strings and other name ids.
So while I still don't understand why I had a red error on my HelloWorld project folder in Package Explorer (that did not show a single error or warning anywhere else in any of my edited files), it looks like rebuilding the file by cutting and pasting in a new project, in a careful order, ended up updating the R.java so that I could run successfully in the emulator.
Special thanks to @TalhaQ for suggesting my files were okay and to reuse the code. Although I know I did not edit the R.java file at all, it's still a mystery why it never updated like it should have. Might have had something to do with the order of operations in the original file, since the order of operations mattered a lot in the rebuild.