Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 一个ImageButton工作,另一个崩溃应用程序_Java_Android Imagebutton - Fatal编程技术网

Java 一个ImageButton工作,另一个崩溃应用程序

Java 一个ImageButton工作,另一个崩溃应用程序,java,android-imagebutton,Java,Android Imagebutton,我在一个活动中有6个ImageButtons,第一个没有任何问题,但是其他的当点击设备时会使应用程序崩溃。 我对其余的ImageButtons使用了相同的代码-我是否遗漏了什么 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FF54561E" android:orientation="ver

我在一个活动中有6个ImageButtons,第一个没有任何问题,但是其他的当点击设备时会使应用程序崩溃。 我对其余的ImageButtons使用了相同的代码-我是否遗漏了什么

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FF54561E"
    android:orientation="vertical"
    android:textAlignment="center">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:contentDescription="@string/Logo"
        android:src="@drawable/idailment"
        android:textAlignment="center"

        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_weight="1"
        android:text="@string/IdDisease"
        android:textAlignment="center"
        android:textColor="#FFFFFF"
        android:textSize="16sp"
        android:textStyle="italic" />

    <TextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:gravity="center"
        android:text="@string/BlackRotButton"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/BlackRotAnim"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:background="@drawable/black_rot_anim"
        android:contentDescription="@string/BlackRotButton"
        android:gravity="center"
        android:onClick="goToDiseaseBlackRot"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:gravity="center"
        android:text="@string/BacterialBrownSpotButton"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/BacterialBrownSpotAnim"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:background="@drawable/bacterial_brown_spot_anim"
        android:contentDescription="@string/BacterialBrownSpotButton"
        android:gravity="center"
        android:onClick="goToDiseaseBacterialBrownSpot"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:gravity="center"
        android:text="@string/BudBlastButton"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/BudBlastAnim"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:background="@drawable/bud_blast_anim"
        android:contentDescription="@string/BudBlastButton"
        android:gravity="center"
        android:onClick="goToDiseaseBudBlast"
        android:scaleType="centerCrop" />


    <TextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:gravity="center"
        android:text="@string/RotButton"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/RotAnim"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:background="@drawable/rot_anim"
        android:contentDescription="@string/RotButton"
        android:gravity="center"
        android:onClick="goToDiseaseRot"
        android:scaleType="centerCrop" />


    <TextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:gravity="center"
        android:text="@string/SunBurnButton"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/SunBurnAnim"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:background="@drawable/sun_burn_anim"
        android:contentDescription="@string/SunBurnButton"
        android:gravity="center"
        android:onClick="goToDiseaseSunBurn"
        android:scaleType="centerCrop" />

    <TextView
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:gravity="center"
        android:text="@string/VirusButton"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        android:textStyle="bold" />

    <ImageButton
        android:id="@+id/VirusAnim"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_weight="1"
        android:background="@drawable/virus_anim"
        android:contentDescription="@string/VirusButton"
        android:gravity="center"
        android:onClick="goToDiseaseVirus"
        android:scaleType="centerCrop" />


</LinearLayout>
前几个logcat错误实际上是 非常感谢你的努力

04-03 18:50:46.461140-10698/?W/SocketClient:写入错误(管道断裂)
W/ADB_服务:终止JDWP 9676连接:I/O错误布局文件似乎很完美。使用此代码。我使用了R.id:

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView blackRotButton = (ImageView)findViewById(R.id.BlackRotAnim);
blackRotButton.setBackgroundResource(R.drawable.black_rot_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton1Animation = (AnimationDrawable) blackRotButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton1Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView bacterialBrownSpotButton = (ImageView)findViewById(R.id.BacterialBrownSpotAnim);
bacterialBrownSpotButton.setBackgroundResource(R.drawable.bacterial_brown_spot_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton2Animation = (AnimationDrawable) bacterialBrownSpotButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton2Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView budBlasttButton = (ImageView)findViewById(R.id.BudBlastAnim);
budBlasttButton.setBackgroundResource(R.drawable.bud_blast_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton3Animation = (AnimationDrawable) budBlasttButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton3Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView rotButton = (ImageView)findViewById(R.id.RotAnim);
rotButton.setBackgroundResource(R.drawable.rot_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton4Animation = (AnimationDrawable) rotButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton4Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView sunBurnButton = (ImageView)findViewById(R.id.SunBurnAnim);
sunBurnButton.setBackgroundResource(R.drawable.sun_burn_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton5Animation = (AnimationDrawable) sunBurnButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton5Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView virusButton = (ImageView)findViewById(R.id.VirusAnim);
virusButton.setBackgroundResource(R.drawable.virus_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton6Animation = (AnimationDrawable) virusButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton6Animation.start();}


 /**
 * This method is called when BlackRot button is clicked.
 */
public void goToDiseaseBlackRot (View view){
    Intent intent = new Intent (this, DiseaseBlackRot.class);
    startActivity(intent);}
/**
 * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseBacterialBrownSpot (View view){
    Intent intent = new Intent (this, DiseaseBacterialBrownSpot.class);
    startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseRot (View view){
    Intent intent = new Intent (this, DiseaseRot.class);
   startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
*/
 public void goToDiseaseVirus (View view){
     Intent intent = new Intent (this, DiseaseVirus.class);
     startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseSunBurn (View view){
     Intent intent = new Intent (this, DiseaseSunBurn.class);
     startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseBudBlast (View view){
 Intent intent = new Intent (this, DiseaseBudBlast.class);
 startActivity(intent);}}

请发布logcat输出logcat太长-我应该根据什么进行过滤?已尝试-相同的结果查找logcat给出的错误…按错误进行过滤,并发送触发错误的前几个。如果没有,希望我发布的足够多,将复制更多
// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView blackRotButton = (ImageView)findViewById(R.id.BlackRotAnim);
blackRotButton.setBackgroundResource(R.drawable.black_rot_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton1Animation = (AnimationDrawable) blackRotButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton1Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView bacterialBrownSpotButton = (ImageView)findViewById(R.id.BacterialBrownSpotAnim);
bacterialBrownSpotButton.setBackgroundResource(R.drawable.bacterial_brown_spot_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton2Animation = (AnimationDrawable) bacterialBrownSpotButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton2Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView budBlasttButton = (ImageView)findViewById(R.id.BudBlastAnim);
budBlasttButton.setBackgroundResource(R.drawable.bud_blast_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton3Animation = (AnimationDrawable) budBlasttButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton3Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView rotButton = (ImageView)findViewById(R.id.RotAnim);
rotButton.setBackgroundResource(R.drawable.rot_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton4Animation = (AnimationDrawable) rotButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton4Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView sunBurnButton = (ImageView)findViewById(R.id.SunBurnAnim);
sunBurnButton.setBackgroundResource(R.drawable.sun_burn_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton5Animation = (AnimationDrawable) sunBurnButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton5Animation.start();

// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView virusButton = (ImageView)findViewById(R.id.VirusAnim);
virusButton.setBackgroundResource(R.drawable.virus_anim);

// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable diseaseButton6Animation = (AnimationDrawable) virusButton.getBackground();

// Start the animation (looped playback by default).
diseaseButton6Animation.start();}


 /**
 * This method is called when BlackRot button is clicked.
 */
public void goToDiseaseBlackRot (View view){
    Intent intent = new Intent (this, DiseaseBlackRot.class);
    startActivity(intent);}
/**
 * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseBacterialBrownSpot (View view){
    Intent intent = new Intent (this, DiseaseBacterialBrownSpot.class);
    startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseRot (View view){
    Intent intent = new Intent (this, DiseaseRot.class);
   startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
*/
 public void goToDiseaseVirus (View view){
     Intent intent = new Intent (this, DiseaseVirus.class);
     startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseSunBurn (View view){
     Intent intent = new Intent (this, DiseaseSunBurn.class);
     startActivity(intent);}
 /**
  * This method is called when BlackRot button is clicked.
 */
 public void goToDiseaseBudBlast (View view){
 Intent intent = new Intent (this, DiseaseBudBlast.class);
 startActivity(intent);}}