I am doing a learning project. Faced with mysticism:

after writing the identifier for the View and starting the app in the emulator, R.java disappears in the project in an inexplicable way.

More details:

Set identifiers:

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_accent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/user_profile.placeholder.image" android:textColor="@color/white" android:fontFamily="sans-serif-medium" android:layout_above="@id/photo_placeholder" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/photo_placeholder" android:layout_width="@dimen/placeholder_photo_size_90" android:layout_height="@dimen/placeholder_photo_size_90" android:scaleType="centerCrop" android:src="@drawable/add_a_photo_48px" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/spacing_large_56"/> </RelativeLayout> 

Run the application in the emulator to see what the views look like.

After starting the application, we get the error:

Error: (58, 51) found at (at 'layout_above' with value '@ id / photo_placeholder').

The error is due to the fact that all R.java from the project completely disappeared.

Running the app with earlier changes did not lead to anything like this.

I'm in ahu ... some confusion.

Without relying on Git, I made local project backups after each change in which the project remained operational. This allowed us to accurately determine the moment of disappearance of R.java.

R.java disappear at the moment of launching the app.

What could it be?

Work got up, I do not understand what is happening.

Here are R.java, found by searching in the project before mystical changes:

Before the changes

After all these files are missing, the assembly crashes.

Technical information:

Project: https://github.com/miller7777777/DevIntensive Hometask_3 branch see DevIntensive \ app \ src \ main \ res \ layout \ activity_main.xml file

Windows 10x64 Android Studio 2.1.2

Screw healthy, walked chkdsk, no problem. There are no viruses.

Clean project / Rebuild Project also does not help.

What could it be?

  • Yes you are right. Transferred "+" to the first mentionIDID photo_placeholder - it all worked. Thank you I will not lay out the whole code, there is a large sheet, I will lay out only the problem piece. - Miller777

1 answer 1

The class R autogenerated at each compilation, but it is not created if there are errors in the markup. There is no mystery here - the compiler cannot simply convert XML into code and build a project, and therefore there is nothing to generate R from.

Transfer the "plus sign" after the commercial AT (@ + id) to the first mention ID photo_placeholder in your markup (B attribute android:layout_above TextView widget in your case):

  <TextView ... android:layout_above="@+id/photo_placeholder"/> 

And in the rest of the references to this ID, remove the "plus sign" (in particular, in the android:id attribute of the ImageView widget).

It’s quite obvious from an error that you are trying to access a resource by a name that does not exist yet / The name is associated with the resource by this very plus sign and the first mention of the name in the markup should be with a plus sign - this plus sign indicates that you need to add the name of the widget for later reference.