0

そのため、メインのアクティビティで画像ボタンを追加しましたが、正常に機能します。私が別のものを追加するために行ったとき、私は力を閉じ始めました。それを新しいアクティビティにリンクし、新しいアクティビティをマニフェストファイルに入れました。2番目の画像ボタンのコードを削除してアプリを実行すると、正常に動作します。私のスプラッシュ画面は実際には私の主な活動ですが、それは問題ではないと思います。あなたが私に与えることができるどんな助けにも前もって感謝します。

MainActivity(新規):

   package com.crazycastles;


import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;



public class MainActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //CREATE BUTTON 1 & SOUND
        final MediaPlayer buttonSound = MediaPlayer.create(
                MainActivity.this, R.raw.swords);

        ImageButton button1 = (ImageButton) findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                startActivity(new Intent(MainActivity.this,
                        button1Activity.class));
            }
        }); 
        ImageButton multiplayerbutton = (ImageButton) findViewById(R.id.multiplayerbutton);
        multiplayerbutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                startActivity(new Intent(MainActivity.this,
                        multiplayerbuttonActivity.class));
            }
        }); 

        //END OF BUTTON1 & SOUND



        }
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    }

マニフェストファイル:

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

    <uses-sdk android:minSdkVersion="3"></uses-sdk>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:debuggable="true">


        <activity
            android:name=".SplashScreen"
            android:label="Crazy Castles" 
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:screenOrientation="landscape"
            android:configChanges="keyboard|keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity android:name="MainActivity" 
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
            android:launchMode="standard" 
            android:permission="android.permission.WAKE_LOCK"
            android:configChanges="keyboard|keyboardHidden|orientation">
        </activity>
        <activity android:name="button1Activity" 
           android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
            android:launchMode="standard" 
            android:permission="android.permission.WAKE_LOCK"
            android:configChanges="keyboard|keyboardHidden|orientation"
            android:screenOrientation="portrait"></activity>

        <activity android:name="multiplayerbuttonActivity" 
           android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
            android:launchMode="standard" 
            android:permission="android.permission.WAKE_LOCK"
            android:configChanges="keyboard|keyboardHidden|orientation"
            android:screenOrientation="portrait"></activity>



        </application>

</manifest>

スプラッシュスクリーン:

package com.crazycastles;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class SplashScreen extends Activity {

    /**
     * The thread to process splash screen events
     */
    private Thread mSplashThread;    

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Splash screen view
        setContentView(R.layout.splash);
        final MediaPlayer buttonSound = MediaPlayer.create(
                SplashScreen.this, R.raw.swords);

        final SplashScreen sPlashScreen = this;   

        // The thread to wait for splash screen events
        mSplashThread =  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        // Wait given period of time or exit on touch
                        wait(3000);
                        buttonSound.prepare();
                    }
                }
                catch(InterruptedException ex){                    
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                finish();

                // Run next activity
                Intent intent = new Intent();
                intent.setClass(sPlashScreen, MainActivity.class);
                startActivity(intent);
                stop();                    
            }
        };

        mSplashThread.start();        
    }

    /**
     * Processes splash screen touch events
     */
    @Override
    public boolean onTouchEvent(MotionEvent evt)
    {
        if(evt.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(mSplashThread){
                mSplashThread.notifyAll();
            }
        }
        return true;
    }    
} 

新しいLogCat:

    01-01 19:51:35.068: E/MediaPlayer(12462): prepareAsync called in state 8
01-01 19:51:35.427: E/AndroidRuntime(12462): FATAL EXCEPTION: main
01-01 19:51:35.427: E/AndroidRuntime(12462): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crazycastles/com.crazycastles.MainActivity}: java.lang.ClassCastException: android.widget.ImageView
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.ActivityThread.access$2500(ActivityThread.java:129)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.os.Looper.loop(Looper.java:143)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.ActivityThread.main(ActivityThread.java:4701)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at java.lang.reflect.Method.invokeNative(Native Method)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at java.lang.reflect.Method.invoke(Method.java:521)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at dalvik.system.NativeStart.main(Native Method)
01-01 19:51:35.427: E/AndroidRuntime(12462): Caused by: java.lang.ClassCastException: android.widget.ImageView
01-01 19:51:35.427: E/AndroidRuntime(12462):    at com.crazycastles.MainActivity.onCreate(MainActivity.java:41)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-01 19:51:35.427: E/AndroidRuntime(12462):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
4

1 に答える 1

3

01-01 18:25:59.553:E / global(11497):非推奨のスレッドメソッドはサポートされていません。

これはほとんど全体の話です。Threadクラスのドキュメントを見て、非推奨のメソッドを確認してください。それらの1つ以上を使用しているかどうかを確認し、コードから削除してください¹。ドキュメントには、これらのメソッドを使用すべきでない理由も記載されています。

¹たとえば、非推奨の方法を使用しているThread.stop()

于 2012-01-01T23:35:56.780 に答える