0

私はまだこれに非常に慣れていないので、解決策はおそらく明白です。とにかく、このアプリのボタンで新しいアクティビティを開こうとしていますが、実行すると強制終了します。誰かが何が悪いのか知っていますか?リストビューと呼ばれるものを使用するつもりでしたが、クラス用に作成した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>
4

2 に答える 2

1

これでコードを修正します

ImageButton mainMenu;

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

アップデート:

OK、エラーが見つかりました。を設定するのOnClickListenerを忘れたButtonImageButton

これを試して

    majScales.setOnClickListener(this);
    mainMenu.setOnClickListener(this);
于 2012-12-02T16:16:45.720 に答える
0

一つには、あなたは意図を間違って綴った。

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

する必要があります

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

もう1つは、2つのアプリケーションを定義しています。

スタックトレースがないと、他に何が間違っているのかを知るのは困難です。

于 2012-12-02T16:14:25.440 に答える