线程退出时未捕获异常(组= 0x4001d800)致命异常:主要

时间:2012-12-02 16:08:20

标签: android exception

我还是很新,所以解决方案可能很明显。 无论如何我试图让这个应用程序中的按钮打开新的活动但是当我运行它时,强制关闭。有谁知道什么是错的?我打算使用一个名为list view的东西但是没有使用我为该类制作的XML。

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>

2 个答案:

答案 0 :(得分:1)

通过此

修复您的代码
ImageButton mainMenu;

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

更新:

好的,我发现了错误。您忘记为每个OnClickListenerButton

设置ImageButton

试试这个

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

答案 1 :(得分:0)

有一件事你错误地拼写了意图。

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

应该是

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

另一方面,您定义了两个应用程序。

如果没有堆栈跟踪,很难知道还有什么可能是错误的。