-1

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.

Ashlee Berry
  • 75
  • 1
  • 7
  • how are the two apps at all related? did it actually ever worked in the first place? – JoxTraex Mar 13 '16 at 23:56
  • They aren't related, it's for a project using Intents. Yes they both work fine individually. I currently have them setup as libraries in Android Studio. What's strange is one works fine but the other does not. – Ashlee Berry Mar 13 '16 at 23:59
  • @AshleeBerry Does the bmicalculator's layout have an id titled "heightLabel" ? – Steve C. Mar 14 '16 at 00:02
  • If they both have different code.. then you cannot guarantee one will function like the other. Is it just 3 apps basically then that you're using, explicitly launch another app? – JoxTraex Mar 14 '16 at 00:02
  • did you confirm that in your R.java that you have the id heightLabel is defined? – JoxTraex Mar 14 '16 at 00:04
  • @JoxTraex this is all one application. The launch page displays two buttons, one to launch the BMI calculator, and one to launch the Tip Calculator. Again, these apps both work correctly individually, but I have try to combine them into one app and navigate to them using intents this app crashes when I click the button for BMI. And yes it is defined, as the BMI app functions normally. It's just when I have imported it into a new app it does not. – Ashlee Berry Mar 14 '16 at 00:05
  • @SteveC. yes it does – Ashlee Berry Mar 14 '16 at 00:08
  • @AshleeBerry Reading your comment to JoxTraex, are you saying that you have 3 modules in Android Studio and you're trying to access the other two modules by clicking buttons within the first module? – Steve C. Mar 14 '16 at 00:11
  • @SteveC. Yes that is correct. – Ashlee Berry Mar 14 '16 at 00:12
  • @AshleeBerry Ok, in your projects main settings.gradle file, did you declare each module as an include like this: ` include ':Module1', ':Module2', ':Module3'`? – Steve C. Mar 14 '16 at 00:22

1 Answers1

0

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.

Ashlee Berry
  • 75
  • 1
  • 7