Getting NoSuchField exception when switching apps using intents

44 Views Asked by At

I am making an app that has two button that then open different apps I have made. This makes use of intents. The first one works fine with no issues, but the second app results in a crash and this error.

03-13 19:48:04.154 1524-1524/com.pkgname.intents E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pkgname.intents, PID: 1524
java.lang.NoSuchFieldError: com.pkgname.bmicalculator.R$id.heightLabel
at com.pkgname.bmicalculator.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

This is the line that throws an error when the button is pushed to go to the BmiCalculator module.

heightLabel = (TextView) findViewById(R.id.heightLabel);

To clear up some confusion, this is one app. The two apps the main page is linking to by the use of intents have been imported into Android Studio as modules.

1

There are 1 best solutions below

0
On

I had two XML layouts both named activity_main. As such, one app was using another activity_main that it should have been. Once I renamed the XMl file and then updated the Java code, this resolved the issue.