初めて人がアプリを開くチュートリアルをやろうとしています。次のエラーが発生しましたが、理由がわかりません... :(
作成時の関数でメソッドを呼び出します
作成時
// Show tutorial if is first time.
tutorial();
メソッドのチュートリアル
public void tutorial(){
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
//boolean firstTime = preferences.getBoolean("FirstTime", false);
boolean firstTime = false; //For test purposes
if (!firstTime) {
final Dialog dialog = new Dialog(this, android.R.style.Theme_DeviceDefault_NoActionBar_Fullscreen);
// Disable title.
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set dialog content layout.
dialog.setContentView(R.layout.dialog_tutorial);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("FirstTime", true);
editor.commit();
final View top_layout = (View)dialog.findViewById(R.id.top_layout);
final View tutorial0 = (View)dialog.findViewById(R.id.tutorial_0);
final View tutorial1 = (View)dialog.findViewById(R.id.tutorial_1);
final View tutorial2 = (View)dialog.findViewById(R.id.tutorial_2);
final View tutorial3 = (View)dialog.findViewById(R.id.tutorial_3);
final View tutorial4 = (View)dialog.findViewById(R.id.tutorial_4);
tutorial0.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
tutorial0.setVisibility(View.GONE);
tutorial1.setVisibility(View.VISIBLE);
return false;
}
});
tutorial1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
tutorial1.setVisibility(View.GONE);
tutorial2.setVisibility(View.VISIBLE);
return false;
}
});
tutorial2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
tutorial2.setVisibility(View.GONE);
tutorial3.setVisibility(View.VISIBLE);
return false;
}
});
tutorial3.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
tutorial3.setVisibility(View.GONE);
tutorial4.setVisibility(View.VISIBLE);
return false;
}
});
tutorial4.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
dialog.dismiss();
return false;
}
});
dialog.show();
}
}
logcat のエラー
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{victor.martin.world/victor.martin.world.ui.HomeActivity}: android.view.InflateException: Binary XML file line #62: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #62: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
at android.app.Dialog.setContentView(Dialog.java:467)
at victor.martin.world.ui.HomeActivity.tutorial(HomeActivity.java:83)
at victor.martin.world.ui.HomeActivity.onCreate(HomeActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 26 more
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
at android.content.res.Resources.loadDrawable(Resources.java:1963)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:120)
at android.widget.ImageView.<init>(ImageView.java:110)
これはxmlレイアウトです
<?xml version="1.0" encoding="utf-8"?>
<!--Below is the transparent layout positioned at startup -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/top_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="1.0"
android:visibility="visible">
<ImageView
android:id="@+id/tutorial_0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/tutorial_0"
android:visibility="visible"
android:layout_gravity="center" />
<ImageView
android:id="@+id/tutorial_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/tutorial_1"
android:visibility="gone"
android:layout_gravity="center" />
<ImageView
android:id="@+id/tutorial_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tutorial_2"
android:visibility="gone"
android:baselineAlignBottom="true"
android:layout_gravity="center"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true" />
<ImageView
android:id="@+id/tutorial_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tutorial_3"
android:visibility="gone"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:layout_centerVertical="true"
android:baselineAlignBottom="true"
android:adjustViewBounds="true"
android:layout_gravity="center" />
<ImageView
android:id="@+id/tutorial_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/tutorial_4"
android:visibility="gone"
android:layout_gravity="center" />
</LinearLayout>
コメントしてくれてありがとう。