2016-05-18 42 views
-1

enter image description here嘿傢伙我在我的Java 1類的工作結束我的項目。我們正在製作記憶/集中游戲。我的問題是,當我點擊下一個活動的簡單按鈕時,應用程序崩潰。我嘗試過使用片段和活動,但似乎無法正確使用它。我也嘗試過在我的主要活動中使用我需要的佈局,以查看是否可以顯示它。即使這樣,它只是在應用程序啓動時崩潰。任何幫助,將不勝感激。xml佈局崩潰加載Android應用程序

啓動屏幕活動。

package com.bignerdranch.android.memory; 


import android.app.Activity; 
import android.content.Intent; 
import android.media.AudioManager; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.CheckBox; 



public class MemoryActivity extends Activity { 

private Button mEasy; 
private Button mMedium; 
private Button mHard; 
private CheckBox mSilence; 
public MediaPlayer player; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_memory); 


    player = new MediaPlayer(); 
    player = MediaPlayer.create(this, R.raw.mkstartmusic); 
    player.setAudioStreamType(AudioManager.STREAM_MUSIC); 
    player.setLooping(true); 
    player.start(); 



    mEasy = (Button)findViewById(R.id.easy); 
    mEasy.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent easy = new Intent(getApplicationContext(), EasyGame.class); 
      startActivity(easy); 

     } 
    }); 

    mMedium = (Button)findViewById(R.id.medium); 
    mMedium.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

     } 
    }); 

    mHard = (Button)findViewById(R.id.hard); 
    mHard.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 

     } 
    }); 

    mSilence = (CheckBox)findViewById(R.id.silence); 
    mSilence.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      if(mSilence.isChecked()) { 
       player.pause(); 
      } else if(mSilence.isChecked() == false) { 
       player.start(); 
      } 

     } 
    }); 

} 

@Override 
protected void onStop() { 
    super.onPause(); 
    if (player != null){ 
     player.stop(); 
     if (isFinishing()){ 
     player.stop(); 
     player.release(); 
     } 
    } 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.layout.activity_memory, menu); 
    return true; 


} 

} 

次活動(容易的選擇)

package com.bignerdranch.android.memory; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.widget.ImageButton; 

public class EasyGame extends Activity { 

private ImageButton buttOne; 
private ImageButton buttTwo; 
private ImageButton buttThree; 
private ImageButton buttFour; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_easy); 

    buttOne = (ImageButton)findViewById(R.id.ImageButton01); 
    buttOne.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 


     } 
    }); 

    buttTwo = (ImageButton)findViewById(R.id.ImageButton02); 
    buttTwo.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 


     } 
    }); 

    buttThree = (ImageButton)findViewById(R.id.ImageButton03); 
    buttThree.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 


     } 
    }); 

    buttFour = (ImageButton)findViewById(R.id.ImageButton04); 
    buttFour.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 


     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.layout.activity_easy, menu); 
    return true; 



} 
} 

這是佈局容易的選擇

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/easyback" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:background="@drawable/easyback" 
    android:clickable="false" 
    android:duplicateParentState="false" 
    android:longClickable="false" 
    android:scaleType="centerCrop" /> 

<ImageButton 
    android:id="@+id/ImageButton04" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:layout_below="@+id/ImageButton01" 
    android:layout_toRightOf="@+id/ImageButton01" 
    android:layout_toEndOf="@+id/ImageButton01" 
    android:maxHeight="25dp" 
    android:maxWidth="25dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/dragonemb" /> 

<ImageButton 
    android:id="@+id/ImageButton02" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:layout_above="@+id/ImageButton04" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 

    android:layout_marginRight="22dp" 
    android:layout_marginEnd="22dp" 
    android:maxHeight="25dp" 
    android:maxWidth="25dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/dragonemb" /> 

<ImageButton 
    android:id="@+id/ImageButton03" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:layout_alignTop="@+id/ImageButton04" 
    android:layout_toLeftOf="@+id/ImageButton04" 
    android:layout_toStartOf="@+id/ImageButton04" 
    android:maxHeight="25dp" 
    android:maxWidth="25dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/dragonemb" /> 

<ImageButton 
    android:id="@+id/ImageButton01" 
    android:layout_width="80dp" 
    android:layout_height="80dp" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="152dp" 
    android:layout_toLeftOf="@+id/ImageButton02" 
    android:maxHeight="25dp" 
    android:maxWidth="25dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/dragonemb" /> 

</RelativeLayout> 
+0

'應用程序崩潰'意味着每個人都搜索崩潰日誌。沒有人會檢查代碼。發佈堆棧跟蹤。 –

+0

發佈你的Logcat –

+0

找到崩潰,請更新你的logcat。 – Ankur1994a

回答

3

好這不是你發佈的完整的崩潰日誌,但在它的頂部,我看到roidManifest.xml?。而且這是確保你沒有定義在你的androidmanifest.xmlEasyGame活動,以便裏面添加application標籤這一行,

<manifest package="com....." . . . > 
    <application . . . > 

     <activity 
      android:name=".EasyGame" 
      android:label="easygame"> 
     </activity> 
     . . . 
    </application> 
</manifest> 

另外你想投你ImageButtonButton考慮固定這一點。

+0

我之前就有過,並拿出來。我已經添加了它,並從上面的評論中提出建議,但仍然崩潰。 –

+0

確定然後通過複製粘貼它來發布完整的崩潰日誌...不要張貼半截圖。 –

+0

我試圖複製/粘貼LogCat,但它不會讓我。我所能做的只是發佈它的更新截圖。 –

1

添加下面AndroidManfest

<activity 
     android:name=".EasyGame" 
     /> 
1

其簡單的只是代碼將此行添加到您的AndroidManifest

<activity android:name="Activity"/> 

logcat也提到,您需要將Android清單,你沒有內聲明的活動。請仔細閱讀logcat,因爲它確實有助於發現哪裏出了問題。

0

好的,所以我嘗試了所有你們的建議,我曾經是問題的一部分,最後的問題證明我需要將我的圖像添加到drawable-xhdpi。感謝你的幫助。