Java 尝试运行带有按钮的简单应用程序
我必须用按钮和图像制作一个基本的主屏幕。我之前在提取字符串资源时遇到了问题,但我想我已经解决了,希望这不会干扰代码。我甚至不需要按钮去任何地方,我只需要它们出现。我的代码如下所示:Java 尝试运行带有按钮的简单应用程序,java,android,samsung-galaxy,Java,Android,Samsung Galaxy,我必须用按钮和图像制作一个基本的主屏幕。我之前在提取字符串资源时遇到了问题,但我想我已经解决了,希望这不会干扰代码。我甚至不需要按钮去任何地方,我只需要它们出现。我的代码如下所示: <Button android:id="@+id/button4" android:layout_width="139dp" android:layout_height="74dp" android:text="@string/my_cookbook" app:la
<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" />
我没有收到任何错误,它说我的构建成功了,但我无法让应用程序在我的Galaxy S4上运行。模拟器对我不起作用,所以我决定用我的手机运行它,但它会弹出一秒钟,然后说“应用程序停止工作”。知道它为什么不会真正运行吗?如果它是完整的XML布局文件,那么您就缺少视图的“容器”,除非您添加一些“容器”,如LinearLayout或RelativeLayout,然后将视图/按钮/图像视图放在该容器中,否则它不会显示任何内容。如果它是完整的XML代码,您也应该尝试添加更多的代码。如果它是完整的XML布局文件,那么您将丢失视图的“容器”,除非您添加一些“容器”,如LinearLayout或RelativeLayout,然后将视图/按钮/图像视图放在该容器中,否则它不会显示任何内容。如果是完整的XML代码,您还应该尝试添加更多的代码。您需要发布stacktrace,可能还有部分活动代码。也可以看到下面的帖子,很有可能。同样欢迎来到令人沮丧的编程世界:Djavascript!=Java您需要发布stacktrace,可能还有部分活动代码。也可以看到下面的帖子,很有可能。同样欢迎来到令人沮丧的编程世界:Djavascript!=JAVA