Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchFieldError on findViewById()

There's two android projects I want to merge, one is Main and the other is linked as Library. But I have some troubles on this line:

Button modificarC; protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         this.requestWindowFeature(Window.FEATURE_NO_TITLE);         setContentView(R.layout.activity_menu_calificaciones); modificarC = (Button) findViewById(R.id.btn_aseso); //HERE 

I tried Project Clean... also I have android-support-v4.jar on my dependencies

And this is my trace:

04-24 19:39:52.568: E/AndroidRuntime(9486): FATAL EXCEPTION: main 04-24 19:39:52.568: E/AndroidRuntime(9486): java.lang.NoSuchFieldError: com.utez.sistemas.sam.R$id.btn_aseso 04-24 19:39:52.568: E/AndroidRuntime(9486):     at com.utez.sistemas.sam.calificaciones.CalificacionesActivity.onCreate(CalificacionesActivity.java:67) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.Activity.performCreate(Activity.java:4465) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.access$600(ActivityThread.java:127) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.os.Handler.dispatchMessage(Handler.java:99) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.os.Looper.loop(Looper.java:137) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.main(ActivityThread.java:4507) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at java.lang.reflect.Method.invokeNative(Native Method) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at java.lang.reflect.Method.invoke(Method.java:511) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 04-24 19:39:52.568: E/AndroidRuntime(9486):     at dalvik.system.NativeStart.main(Native Method) 

Also here is the layout:

<LinearLayout             style="@style/LoginFormContainer"             android:layout_width="253dp"             android:layout_height="260dp"             android:layout_marginLeft="15dp"             android:layout_marginTop="30dp"             android:orientation="vertical" >              <Button                 android:id="@+id/btn_alta"                 android:layout_width="match_parent"                 android:layout_height="63dp"                 android:layout_marginLeft="25dp"                 android:layout_marginTop="5dp"                 android:background="@drawable/btn_altacalif"                 android:contentDescription="@string/action_sign_in_register"                 android:paddingLeft="32dp"                 android:paddingRight="32dp"                 android:textAlignment="center" />              <Button                 android:id="@+id/btn_aseso"                 android:layout_width="match_parent"                 android:layout_height="0dp"                 android:layout_marginLeft="25dp"                 android:layout_marginTop="5dp"                 android:layout_weight="0.16"                 android:background="@drawable/btn_modcalif"                 android:contentDescription="@string/action_sign_in_register"                 android:paddingLeft="32dp"                 android:paddingRight="32dp"                 android:textAlignment="center" />          </LinearLayout> 
like image 562
Mauricio Zárate Avatar asked Apr 25 '13 00:04

Mauricio Zárate


1 Answers

I had the same error and it turns out that the resource was overridden.

If you have one project working as a library that declares some id in a given XML file, then your main project redefines that XML, the original id is gone, but you won't see the error until run time.

In my case, a partner deleted and committed the XML from the project, then added it back in the library project. Subclipse didn't seems to notice that because I was up to date, but the XML was there on the main project.

like image 176
Moxor Avatar answered Sep 26 '22 04:09

Moxor