R.java

Joe

Thành viên VIP
21/1/13
2,685
1,243
113
Hi Javadroids with Android-flu...

The more I see you guys get into deep Android-influenza the more pity I feel...As a Quack doctor I usually cure people with my "Principle of Operation" pill. Because you guys (or most of you) are IDE-addicted and unable to live without IDE, especially when you guys are fully in an inescapable stranglehold of Android-influenza, I give you some inside view about the most dangerous virus called R.java. This virus R.java intrudes secretly into your brain and stays there undamaged forever. It header says
PHP:
/* 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.
*/
And when you dare to "touch" this R.java virus your project might be immediately in the toilet. However, when you gather your wit and courage and peruse carefully the R.java virus you see some strange DNA genes like that
PHP:
public final class R {
  public static final class attr {
  }
  public static final class drawable {
      public static final int ic_launcher=0x7f020000;
  }
  public static final class id {
      public static final int webview=0x7f050000;
  }
  public static final class layout {
      public static final int main=0x7f030000;
  }
  public static final class string {
      public static final int app_name=0x7f040001;
      public static final int HelloWord=0x7f040000;
  }
  ...
What are these strange DNA strings 0x7f020000, 0x7f050000 etc. ? If you've read my Android-OS posting http://congdongjava.com/forum/threads/android-os-architecture.17842/ you might remember the strange Icelandic name Dalvik. Right? Yes this strange machine needs such pointers for quick accesses. The simple reason is that a mobile phone is usually memory scarcer than a PC and DVM doesn't have the luxury to hog everything. Also: The DNA strings are the pointers for its quickest-accesses. If you unknowably tinker with these DNA strings your project could become suddenly a dangerous zombie... Hence the WARNING !

Now let's dig deeper into details:
Your res-directory contains certainly some "required" subdirectories. For example:
- drawable
- layout
- etc.

The pointer ic_launcher points directly to the ic_launcher of the subdirectories drawable-XX
The other pointers are similar to ic_launcher. In R.java file, each resource category will be created as one class. In each resource class all respective elements will be created as static members. All these are final members. Also, so we must access them with their class names, like R.drawable.ic_launcher, R.layout.main, etc.

Too abstract and too theoretically ? Well, I give you an example. Every newbie started obligatorily with the "HelloWorld". The DNA strings for this little app are:
Strings.xml:
...
<string name="HelloWorld".../string>
<string name="app_name"...</string>
...
---> app_name=0x7f040001 and HelloWord=0x7f040000

main.xml:
...
android:id="@+id/webview"
...
---> "@+id/webview" = 0x7f050000

It's quite simple and easy, isn't it ? For the case that your R.java virus is somehow kaput you have no other choice than to look at all your xml files for the missing part. And if you are so too tired and couldn't find anything it's best to delete the whole project and start anew as a virgin...
Also, hands off from fumbling with the R.java virus. This virus is reserved for such a quack doctor like me...:D
 

HeisVietkhang

New Member
23/7/13
21
8
3
No they're not DNA. They have started with
Code:
public static final
, but later the
Code:
final
has been removed. I don't remember exactly but they don't encourage you to rely on such "DNA". The removal of
Code:
final
could be a hint.

P.S: Could you use some plugin to enable Markdown?
 

Joe

Thành viên VIP
21/1/13
2,685
1,243
113
No they're not DNA. They have started with
Code:
public static final
, but later the
Code:
final
has been removed. I don't remember exactly but they don't encourage you to rely on such "DNA". The removal of
Code:
final
could be a hint.
=)) if you know what DNA means....BTW, due to distraction I forgot the word static.
P.S: Could you use some plugin to enable Markdown?
I'm not IDE-addicted. Never use Eclipse or whatever IDE to "produce" an applet.
Google for details (about Vietkhang)
Hope that your exhibitionism won't hurt your privacy;)
 

HeisVietkhang

New Member
23/7/13
21
8
3
Well I don't know DNA. Just thought if you think those are immutable then that's wrong. About Markdown, I think you're a moderator, so it'd be great if you could support that system for this forum's comment editor.

Just think of what you see. If my nick was HeisObama then everyone would know I'm not Obama. I'd like to let kids know that someone exists. Since you're not kid, and you don't know about him (Vietkhang), probably you're not Vietnamese, right?

Talking about privacy, let me just ask you that where is privacy policy of this site? How do you treat your users?

You don't need to answer, I already knew.

I thought you were nice, don't make me wrong. Thanks.
 

Joe

Thành viên VIP
21/1/13
2,685
1,243
113
Well I don't know DNA. Just thought if you think those are immutable then that's wrong. About Markdown, I think you're a moderator, so it'd be great if you could support that system for this forum's comment editor.
You confuse or you play confusing with your Markdown ? Moderator is not God and has to obey the rules set by the Admin. A society always has some rules and those who won't comply with the rules are either asocial or rebellious.
Just think of what you see. If my nick was HeisObama then everyone would know I'm not Obama. I'd like to let kids know that someone exists. Since you're not kid, and you don't know about him (Vietkhang), probably you're not Vietnamese, right?
So, it's not your exhibitionist name then you misuse the name of someone without asking for permission. It's in the States an offense. Is such a misuse of name NOT an offense in Vietnam ? Yes, I'm not Vietnamese. I'm a FrancoGerman.
Talking about privacy, let me just ask you that where is privacy policy of this site? How do you treat your users?
You don't need to answer, I already knew.
I thought you were nice, don't make me wrong. Thanks.
You seem not to understand what privacy means. This site or whatever site doesn't care about your privacy. It's you who has to care about your privacy. How can you expect that this site or FB or whatever site cares for you about your privacy when you don't care but talk loudly about YOUR privacy. Are you an underage who needs parental care ?
You misunderstood everything.
1) I've thought your name is HeisViekhang and you probably understand German. HeisVietkhang is in German NameVietKhang.
2) I understand you very well. You want me to break the rules set up by the Admin by asking for the plug-in.
3) From the nick HeisVietKhang (or NameVietKang) in conjunction with your motto "Google for details (about Vietkhang) I want to decently hint you about the privacy.
Yes, because of your good English I thought you'd comprehend what I wrote. But I may be wrong. Sorry.