2012-12-02 41 views
0

我還是很新,所以解決方案可能很明顯。 任何方式我試圖讓這個應用程序中的按鈕打開新的活動,但是當我運行它時,forcecloses。有誰知道什麼是錯的?我打算使用名爲list view的東西,但是沒有使用我爲這個類製作的XML。線程退出與未捕獲的異常(組= 0x4001d800)致命例外:主

package com.example.musicbynumbers; 

import android.os.Bundle; 
import android.app.Activity; 
import android.app.ListActivity; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.ImageButton; 
import android.widget.ListView; 

public class MainMenu extends Activity implements View.OnClickListener { 
    Button majScales, minHarm, minMel; 
    ImageButton mainMenu; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main_menu); 
     mainMenu = (ImageButton) findViewById(R.id.imagelogo); 
     majScales = (Button) findViewById(R.id.majorscalesb); 


    } 




     @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       switch(arg0.getId()){ 
       case R.id.imagelogo: 
        Intent i = new Intent(MainMenu.this, MainMenu.class); 
        startActivity(i); 
        break; 
       case R.id.majorscalesb: 
        Intent j = new Intent(MainMenu.this, majorScales.class); 
        startActivity(j); 
        break;} 

    } 

} 

佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="80" 
    tools:context=".MainMenu" 

    > 

    <ImageButton 
     android:id="@+id/imagelogo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" 
     android:layout_weight="10" 
     android:gravity="center" /> 

    <Button 
     android:id="@+id/majorscalesb" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="Major Scales" 
     android:gravity="center" /> 

    <Button 
     android:id="@+id/minormelodicb" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="Minor Melodic Scales" 
     android:gravity="center"/> 

    <Button 
     android:id="@+id/minorharmonicb" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="Minor Harmonic Scales" 
     android:gravity="center"/> 

    <Button 
     android:id="@+id/arpeggiosb" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="Arpeggios" 
     android:gravity="center" /> 

     <Button 
      android:id="@+id/chromaticscalesb" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="10" 
      android:text="Chromatic Scales" 
      android:gravity="center" /> 

    <Button 
     android:id="@+id/contraryb" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="Contrary Motion" 
     android:gravity="center" /> 

    <Button 
     android:id="@+id/aboutb" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:text="About" 
     android:gravity="center" 
     > 
    </Button> 

</LinearLayout> 

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.musicbynumbers" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="16" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.musicbynumbers.MainMenu" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.example.musicbynumbers.majorScales" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.example.musicbynumbers.majorScales" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
    </application> 


</manifest> 

回答

1

ImageButton mainMenu; 

mainMenu = (ImageButton) findViewById(R.id.imagelogo); 

更新來解決您的代碼:

OK,我發現了錯誤。你忘了設置OnClickListener爲每ButtonImageButton

試試這個

majScales.setOnClickListener(this); 
    mainMenu.setOnClickListener(this); 
+0

謝謝你沒有意識到我犯了這麼多錯誤。現在它不會崩潰按鈕不工作任何想法?我會更新代碼。 –

0

一件事你拼寫錯誤的意圖。

Intent j = new Intent("com.exapmle.muscibynumbers.majorScales"); 

應該

Intent j = new Intent("com.example.musicbynumbers.majorScales"); 

另一個原因是,你必須定義兩個應用程序。

沒有堆棧跟蹤,很難知道還有什麼可能是錯誤的。

+0

謝謝,但不要偏食已經注意到,並把一個紅色標記旁邊? –

+0

不是。它不是語法錯誤。這是一個完全有效的字符串。 –

相關問題