R.java can't be modified - android

I was trying to modify the R.java in android. I deleted the generated java files. After saving, it doesn't seem to change anything. The R.java file i have looks like this
/* 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.
*/
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int myEditText=0x7f050000;
public static final int myListView=0x7f050001;
}
public static final class layout {
public static final int colors=0x7f030000;
public static final int dimens=0x7f030001;
public static final int main=0x7f030002;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
I wanted to change it, to be more like this one:
/* 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.
*/
public final class R {
public static final class attr {
}
public static final class color {
public static final int notepad_lines=0x7f040001;
public static final int notepad_margin=0x7f040002;
public static final int notepad_paper=0x7f040000;
public static final int notepad_text=0x7f040003;
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int myEditText=0x7f050000;
public static final int myListView=0x7f050001;
}
public static final class layout {
public static final int colors=0x7f030000;
public static final int dimens=0x7f030001;
public static final int main=0x7f030002;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
It so frustrating every time I save it, it goes back to its old state because it's auto generated . How do I modify it?

R.java is an auto generated file contains all your resources used in project. If you want to change R.java you can't.
You have to add or delete resources, then it will be modified according to your resources present in project.
This is basic thing in Android. You have to read Android Developers documents, then you will get good knowledge about it.

You cannot modify R.java in android it will be generated automatically when we are developing an xml file.... here id numbers will be stored of different views so we can't modify it..

Related

Error:Content is not allowed in prolog after recent update of android plugin 3.2.1,gradle 4.6 , errors in colors.xml and xml files inside the drawable

Here, I am attaching the codes of the above mentioned xml files that comes by default after creating a new project. I have tried invalidating cathes & restart and also clean and rebuild but none of them worked for me. I know the problem is similar to the this , but I have not created these files myself, these are being created themselves as I create a new project, earlier these used to be created in correct format but after the updates these are being created in incorrect format.Please someone suggest any solution, is there any bug in this update?
colors.xml
/* AUTO-GENERATED FILE. DO NOT MODIFY.** This class was automatically generated by the* gradle plugin from the resource data it found. It* should not be modified by hand.*/package android.su
ic_launcher_background.xml
/* AUTO-GENERATED FILE. DO NOT MODIFY.** This class was automatically generated by the* gradle plugin from the resource data it found. It* should not be modified by hand.*/package android.support.graphics.drawable;
public final class R {private R() {}
public static final class attr {private attr() {}
public static int font = 0x7f040097;public static int fontProviderAuthority = 0x7f040099;public static int fontProviderCerts = 0x7f04009a;public static int fontProviderFetchStrategy = 0x7f04009b;public static int fontProviderFetchTimeout = 0x7f04009c;public static int fontProviderPackage = 0x7f04009d;public static int fontProviderQuery = 0x7f04009e;public static int fontStyle = 0x7f04009f;public static int fontWeight = 0x7f0400a0;}public static final class bool {private bool() {}
public static int abc_action_bar_embed_tabs = 0x7f050001;}public static final class color {private color() {}
public static int notification_action_color_filter = 0x7f060047;public static int notification_icon_bg_color = 0x7f060048;public static int ripple_material_light = 0x7f060053;public static int secondary_text_default_material_light = 0x7f060055;}public static final class dimen {private dimen() {}
public static int compat_button_inset_horizontal_material = 0x7f08004c;public static int compat_button_inset_vertical_material = 0x7f08004d;public static int compat_button_padding_horizontal_material = 0x7f08004e;public static int compat_button_padding_vertical_material = 0x7f08004f;public static int compat_control_corner_material = 0x7f080050;public static int notification_action_icon_size = 0x7f080086;public static int notification_action_text_size = 0x7f080087;public static int notification_big_circle_margin = 0x7f080088;public static int notification_content_margin_start = 0x7f080089;public static int notification_large_icon_height = 0x7f08008a;public static int notification_large_icon_width = 0x7f08008b;public static int notification_main_column_padding_top = 0x7f08008c;public static int notification_media_narrow_margin = 0x7f08008d;public static int notification_right_icon_size = 0x7f08008e;public static int notification_right_side_padding_top = 0x7f08008f;public static int notification_small_icon_background_padding = 0x7f080090;public static int notification_small_icon_size_as_large = 0x7f080091;public static int notification_subtext_size = 0x7f080092;public static int notification_top_pad = 0x7f080093;public static int notification_top_pad_large_text = 0x7f080094;}public static final class drawable {private drawable() {}
public static int notification_action_background = 0x7f09005d;public static int notification_bg = 0x7f09005e;public static int notification_bg_low = 0x7f09005f;public static int notification_bg_low_normal = 0x7f090060;public static int notification_bg_low_pressed = 0x7f090061;public static int notification_bg_normal = 0x7f090062;public static int notification_bg_normal_pressed = 0x7f090063;public static int notification_icon_background = 0x7f090064;public static int notification_template_icon_bg = 0x7f090065;public static int notification_template_icon_low_bg = 0x7f090066;public static int notification_tile_bg = 0x7f090067;public static int notify_panel_notification_icon_bg = 0x7f090068;}public static final class id {private id() {}
public static int action_container = 0x7f0c0009;public static int action_divider = 0x7f0c000b;public static int action_image = 0x7f0c000c;public static int action_text = 0x7f0c0012;public static int actions = 0x7f0c0013;public static int async = 0x7f0c0017;public static int blocking = 0x7f0c0019;public static int chronometer = 0x7f0c001f;public static int forever = 0x7f0c0033;public static int icon = 0x7f0c0036;public static int icon_group = 0x7f0c0037;public static int info = 0x7f0c0039;public static int italic = 0x7f0c003a;public static int line1 = 0x7f0c003e;public static int line3 = 0x7f0c003f;public static int normal = 0x7f0c0049;public static int notification_background = 0x7f0c004a;public static int notification_main_column = 0x7f0c004b;public static i
ic_launcher_foreground.xml
/* AUTO-GENERATED FILE. DO NOT MODIFY.** This class was automatically generated by the* gradle plugin from the resource data it found. It* should not be modified by hand.*/package android.support.graphics.drawable.animated;
public final class R {private R() {}
public static final class attr {private attr() {}
public static int coordinatorLayoutStyle = 0x7f04006d;public static int font = 0x7f040097;public static int fontProviderAuthority = 0x7f040099;public static int fontProviderCerts = 0x7f04009a;public static int fontProviderFetchStrategy = 0x7f04009b;public static int fontProviderFetchTimeout = 0x7f04009c;public static int fontProviderPackage = 0x7f04009d;public static int fontProviderQuery = 0x7f04009e;public static int fontStyle = 0x7f04009f;public static int fontWeight = 0x7f0400a0;public static int keylines = 0x7f0400ba;public static int layout_anchor = 0x7f0400bf;public static int layout_anchorGravity = 0x7f0400c0;public static int layout_behavior = 0x7f0400c1;public static int layout_dodgeInsetEdges = 0x7f0400c4;public static int layout_insetEdge = 0x7f0400c5;public static int layout_keyline = 0x7f0400c6;public static int statusBarBackground = 0x7f040116;}public static final class bool {private bool() {}
public static int abc_action_bar_embed_tabs = 0x7f050001;}public static final class color {private color() {}
public static int notification_action_color_filter = 0x7f060047;public static int notification_icon_bg_color = 0x7f060048;public static int ripple_material_light = 0x7f060053;public static int secondary_text_default_
Those aren't XML files, and the error therefore indicates an immediate catastrophic parsing failure.

Room database architecture entity extends error

While using android Room i'm having the following entity:
#Entity
public class Call implements Parcelable {
#PrimaryKey(autoGenerate = true)
private long id;
private String filePath;
private long durationInMillis;
private String phoneNumber;
private int isStarred;
private int isIncoming;
private long timestampCreated;
}
All works great. But now I want my pojo (Call.class) to extends an Abstract class as following:
#Entity
public class Call extends BaseViewTypeData implements Parcelable {
....
....
}
And i'm getting the following error:
Error:Cannot figure out how to save this field into database. You can
consider adding a type converter for it.
Error:Cannot find getter for field.
Error:Cannot find setter for field.
Error:Cannot figure out how to read this field from a cursor.
Error:Cannot find getter for field.
Error:Cannot find setter for field.
The parent (BaseViewTypeData.class) is a simple class to handle multiple view types in a recycler views.
public abstract class BaseViewTypeData extends BaseObservable {
public static final int VIEW_TYPE_CALL = 0;
public static final int VIEW_TYPE_SETTINGS_HEADER = 1;
public static final int VIEW_TYPE_SETTINGS_TITLE_SUBTITLE = 2;
public static final int VIEW_TYPE_SETTINGS_TITLE_SUBTITLE_SWITCH = 3;
public static final int VIEW_TYPE_SETTINGS_DIVIDER = 4;
public static final int VIEW_TYPE_SETTINGS_TITLE_SWITCH = 5;
public static final int VIEW_TYPE_CALL_LOG_DATA = 6;
public static final int VIEW_TYPE_CHECKBOX_TITLE_SUBTITLE = 7;
#Ignore
public abstract int getViewType();
}
The parent (BaseViewTypeData.class) is a simple class to handle multiple view types in a recycler views.
I suspect that your problem is not with BaseViewTypeData, but with BaseObservable, as Room will not know how to deal with the BaseObservable fields.
In general, having your entity inherit from classes that you do not control is unlikely to work.

Interface with constant definition (review of code)

In a legacy code of an Android device I've found following piece of art (definition of interface):
public interface ErrorIdentifiers {
public static final int SUCCESS = 0;
public static final int NOT_AVAILABLE = 1;
public static final int GENERIC_FAILURE = 2;
public static final int REQUEST_NOT_SUPPORTED = 3;
public static final int REQUEST_CANCELLED = 4;
public static final int INVALID_RESPONSE = 5;
public static final int LIST_DOWNLOAD_NOT_FINISHED = 6;
public static final int TIMEOUT_ERROR = 7;
public static final int DIR_FOUND = 0;
public static final int DIR_NOT_FOUND = 1;
public static final int DIR_INVALID_PROVIDER = 2;
public static final int DIR_NO_DATA_CONNECTION = 3;
public static final int DIR_OTHER_ERROR = 4;
// ... and many many more
}
The it's then used like this:
resultcode = ErrorIdentifiers.SUCCESS;
Is it bad to use interface in that way? How to do error identifiers in a proper way?
Nothing wrong when using an interface like this.
However, there's some redundancy in the code. public static final could be removed as redundant, as per JLS 9.3:
Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.

Why are some constants public and other private in an Android library code

Problem
Why some constants are under the public modifier while some other private? Are those under public can be called from applications that use the library? If so, how to call the constant from an app, is it like this: CertainLibraryClass.ActivityResultCode.CODE_A?
Code
public class CertainLibraryClass {
public class ActivityResultCode {
public static final int CODE_A = 0X02;
public static final int CODE_B = 0X03;
public static final int CODE_C = 0X04;
}
public class VersionCode {
private static final int VERSION_MAJOR = 1;
private static final int VERSION_MINOR1 = 0;
private static final int VERSION_MINOR2 = 2;
}
// ....
}
Why some constants are under the public modifier?
Ans: So that all other classes can access it e.g.RESULT_OK,SUCCESS.
Why some constants are under the private modifier?
Ans:So that only that class can access it
e.g. consider you are calling getId() libarary function from your class
public class CertainLibraryClass {
private static int ID=0;
public static int getId()
{
return ID+1;
}
here you are not accessing ID field directly ,instead you are calling getId() function which ultimately returns the id, it means that ID variable is internally used by CertainLibraryClass class

Will Int value R.string.app_name Change If Restart App Or something Else

As title says, I suspect my R.string.app_name changed. Since my notification sometimes never update any more, but code below did executed (I can see it in logcat). Is that possible?
nm.notify(R.string.app_name, notification);
Log.i(TAG, "B:showNotification(): id = " + R.string.app_name);
No, this is not possible as all R.*.* resources are defined as constants in your R.java file (in the /gen/<your-package> folder). These are not edited by Android later on.
Example:
public final class R {
public static final class anim {
public static final int accelerate_interpolator=0x7f040000;
public static final int activity_slide_in=0x7f040001;
public static final int activity_slide_out=0x7f040002;
}
public static final class attr {
}
public static final class drawable {
public static final int ic_action_search=0x7f020000;
public static final int ic_launcher=0x7f020001;
}
public static final class id {
public static final int main_layout=0x7f070001;
public static final int scroll=0x7f070000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f050000;
}
public static final class style {
public static final int AppTheme=0x7f060000;
}
}
This is the R.java file from one of my real projects. As you can see, each value is a final int which is assigned when you're developing the app (all values are assigned using hex, so you'd have to use an online converter to the actual int value)

Categories

Resources