1

I have to make a basic home screen with buttons and images. I was having trouble earlier with extracting string resources but I think I figured that out, and hopefully that's not interfering with the code. I don't even need the buttons to go anywhere, I just need them to appear. My code looks like this:

<Button  
    android:id="@+id/button4"
    android:layout_width="139dp"
    android:layout_height="74dp"
    android:text="@string/my_cookbook"

    app:layout_constraintStart_toEndOf="@+id/button2"
    app:layout_constraintTop_toTopOf="@+id/button2" />

<Button
    android:id="@+id/button2"
    android:layout_width="127dp"
    android:layout_height="0dp"
    android:layout_marginBottom="359dp"


    android:text="@string/recipes"
    app:layout_constraintBottom_toTopOf="@+id/button3"
    app:layout_constraintEnd_toStartOf="@+id/button4"
    app:layout_constraintStart_toEndOf="@+id/imageView4"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="39dp"
    android:text="@string/check_fridge"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button2" />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="59dp"
    android:layout_height="80dp"
    android:layout_marginBottom="108dp"
    android:contentDescription="@string/heart"
    app:layout_constraintBottom_toTopOf="@+id/imageView3"
    app:layout_constraintEnd_toStartOf="@+id/button2"
    app:layout_constraintStart_toEndOf="@+id/imageView5"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/heart" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="110dp"
    android:layout_marginStart="20dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/imageView4"
    app:srcCompat="@drawable/fridge"
    android:contentDescription="@string/to_do"
    android:layout_marginLeft="20dp" />

<ImageView
    android:id="@+id/imageView5"
    android:layout_width="31dp"
    android:layout_height="0dp"
    android:layout_marginBottom="134dp"
    app:layout_constraintBottom_toTopOf="@+id/imageView3"
    app:layout_constraintEnd_toStartOf="@+id/imageView4"
    app:layout_constraintHorizontal_chainStyle="spread_inside"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/loaf"
    android:contentDescription="@string/to_do2" />

And I'm not getting any errors, and it's saying my build is successful, but I can't get the app to run on my Galaxy S4. The emulators weren't working for me so I decided to use my phone to run it, but it pops up for a second and then says "App has stopped working". Any idea why it won't actually run?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
sJern
  • 11
  • 1
  • 3
    You need to post the stacktrace and probably a portion of the Activity code. Also see the following posts https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this and https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors and very possibly https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it. Also welcome to the wonderfully frustrating world of programming :D – codeMagic Nov 17 '17 at 14:47
  • 1
    javascript != Java – codeMagic Nov 17 '17 at 14:56

1 Answers1

0

If it is the complete XML layout file, then you're missing the "container" of the views, until you add some "container" like LinearLayout or RelativeLayout and then put the views/buttons/imageviews inside that container, it wont show anything. IF it is the complete XML code, also you should try adding a bit more code.