Android NoSuchField error in R.java after process termination

I have a very nasty problem with one of my applications.

I have a splashscreen activity that loads some source data for my application and then launches the main action and ends.

As soon as the main action is launched, I will attach the application by pressing the home key, and then kill the process for my application.

When I restart my application, the splash screen launches, but does not work, as soon as I try to access any of the fields in the R.java file:

For example, I immediately try to set the text of the text view as follows:

((TextView)findViewById(R.id.splash_tv_1)).setText(application.getLanguage().pleasewait); 

This throws the following exception:

 06-29 11:18:14.661: ERROR/AndroidRuntime(21427): java.lang.NoSuchFieldError: com.pagesuite.android.reader.framework.R$id.splash_tv_1 

Then when I run it again, that’s fine.

I get the same behavior if I kill the application using the TaskKiller tool (something that I know, many users will naively use suspects) or if the OS kills my process.

Any ideas?

EDIT:

Just seen in logcat, just before performing onCreate () of this action, the following is logged:

 06-29 11:18:14.571: WARN/dalvikvm(21427): VFY: unable to resolve static field 1945 (splash_logo) in Lcom/pagesuite/android/reader/framework/R$id; 06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: replacing opcode 0x60 at 0x0000 06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: dead code 0x0002-0010 in Lcom/pagesuite/android/reader/framework/activities/PS_Splashscreen;.loadLogoImg (Lcom/pagesuite/android/reader/framework/xml/appsettings/PS_AppSettings;)V 06-29 11:18:14.571: DEBUG/dalvikvm(21427): DexOpt: couldn't find static field 06-29 11:18:14.571: WARN/dalvikvm(21427): VFY: unable to resolve static field 1946 (splash_tv_1) in Lcom/pagesuite/android/reader/framework/R$id; 06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: replacing opcode 0x60 at 0x0000 06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: dead code 0x0002-0039 in Lcom/pagesuite/android/reader/framework/activities/PS_Splashscreen;.setLanguage ()V 06-29 11:18:14.571: DEBUG/dalvikvm(21427): DexOpt: couldn't find static field 06-29 11:18:14.571: WARN/dalvikvm(21427): VFY: unable to resolve static field 1946 (splash_tv_1) in Lcom/pagesuite/android/reader/framework/R$id; 06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: replacing opcode 0x60 at 0x0000 06-29 11:18:14.571: DEBUG/dalvikvm(21427): VFY: dead code 0x0002-0020 in Lcom/pagesuite/android/reader/framework/activities/PS_Splashscreen;.setTextColors ()V 

These are three cases when I try to access R.id in my class.

It should be noted that I'm calling:

 setContentView(R.layout.ps_splashscreen); 

and it seems that this line works fine, so it is Rid that is clearly missing.

EDIT: Here is the layout:

 <?xml version="1.0" encoding="utf-8"?> 

 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical" android:gravity="center"> <ImageView android:id="@+id/splash_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/splash_tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Please wait" android:textColor="@color/white" android:textSize="20dip" /> <TextView android:id="@+id/splash_tv_2" android:layout_marginTop="20dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Loading..." android:textColor="@color/white" /> </LinearLayout> 

+4
source share
3 answers

I had the same problem and she gave me

 DexOpt: couldn't find static field 

because I had two layout XML files with the same name, one in the external library, one in the project. I do not know if this can be useful for others :)

+13
source

I think I also see this problem. Are you referencing a library project? If so, there might be no static from R.java because Eclipse cut it out when importing R.java into your project from another library.

See: https://stackoverflow.com/a/26791329/1748628

0
source
 //Have you Define this line in your oncreat method setcontentview(R.layout.yourlayout); // clen code then run again. 
-1
source

All Articles