はじめまして。
今まではJavaやC言語など基本的なプログラムを勉強していて、
Androidは最近勉強し始めました。
Google Android アプリ開発ガイド第2版 クロノス・クラウンさんと柳井政和さんの本で勉強しています。
記載されているサンプルアプリを作成時に下記のエラーが出ました。
【エラー内容】
エミュレータを起動後、「予期せず停止しました。再起動してください。」
というエラーメッセージが出ます。
【これまでの対処法】
検索して、XMLの修正や不要アプリなどを消したのですが、それでもエラーメッセージが出ます。
XMLは本通り記述しましたし、エラーメッセージは出ないので、どこが間違えているかわかりません。
何が原因でしょうか?
開発環境 Win7、Eclipse、エミュレータ
------------------------------------------------------------------------------------------------------------------------------------------
【Tanbarin.java】
package com.crocro.android.sample;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
public class Tanbarin extends Activity {
/** Called when the activity is first created. */
//効果音
private final int[] SE_TYPE = {
R.raw.tambourine0,
R.raw.tambourine1,
R.raw.tambourine2,
R.raw.tambourine3,
R.raw.tambourine4,
R.raw.tambourine5
};
private final int SE_TYPE_MAX = 6;
private MediaPlayer[][] mSePlayer;
private final int SE_STACK_MAX = 5;
//Activity作成
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//タッチ・リスナーの登録
findViewById(R.id.tambourine_linear).setOnTouchListener(touchListener);
//効果音の初期化
try{
mSePlayer = new MediaPlayer[SE_TYPE_MAX][SE_STACK_MAX];
for(int i=0;i<SE_TYPE_MAX;i++){
for(int j=0;j<SE_STACK_MAX;j++){
mSePlayer[i][j]=MediaPlayer.create(this, SE_TYPE[i]);
mSePlayer[i][j].setLooping(false);
}
}
}catch (Exception e) {
// TODO: handle exception
}
}
//タッチ・リスナー
View.OnTouchListener touchListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO 自動生成されたメソッド・スタブ
//タッチ以外は無視
if(event.getAction() != MotionEvent.ACTION_DOWN) return false;
//変数の初期化
int centerX, centerY;
int distPer, rangePer;
centerX = v.getWidth() / 2;
centerY = v.getHeight() / 2 ;
distPer = dist(centerX, centerY, (int)event.getX(),
(int)event.getY()) * 100 / dist(centerX, centerY, 0,0);
rangePer = 100 / SE_TYPE_MAX;
//タッチ時(中央からの距離によって音を変える)
for(int i = 0; i<SE_TYPE_MAX;i++){
if(i + rangePer <= distPer && distPer < (i+1) * rangePer){
playSe(i);
}
}
return true;
}
};
//距離計算
private int dist(int x0, int y0, int x1, int y1){
return (int)Math.sqrt((x0-x1)*(x0-x1) + (y0-y1) * (y0-y1));
}
//効果音再生
public void playSe(int type){
if(mSePlayer == null) return;
try{
for(int i=0;i<SE_STACK_MAX;i++){
if(mSePlayer[type][i] == null)continue;
if(mSePlayer[type][i].isPlaying()) continue;
mSePlayer[type][i].seekTo(0);
mSePlayer[type][i].start();
break;
}
}catch(Exception e){
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------
【main.xml】
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
------------------------------------------------------------------------------------------------------------------------------------------
【chapter6_tambourine.xml】
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/
android"
android:id="@+id/tambourine_linear"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tambourine"/>
</LinearLayout>
------------------------------------------------------------------------------------------------------------------------------------------
【AndroidManifest.xml】
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="com.crocro.android.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".Tanbarin" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
------------------------------------------------------------------------------------------------------------------------------------------
よろしくご教示、お願い致します。