我遇到的应用程序无法从Android虚拟设备启动。我正在使用版本4.4.2。我从res文件夹放到drawable-mdpi文件夹中的所有图像。调试错误如下所示。

Thread [<1> main] (Suspended (exception RuntimeException))
<VM does not provide monitor information>
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2195
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2245
ActivityThread.access$800(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 135
ActivityThread$H.handleMessage(Message) line: 1196
ActivityThread$H(Handler).dispatchMessage(Message) line: 102
Looper.loop() line: 136
ActivityThread.main(String[]) line: 5017
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 515
ZygoteInit$MethodAndArgsCaller.run() line: 779
ZygoteInit.main(String[]) line: 595
NativeStart.main(String[]) line: not available [native method]


MainActivity.java

import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

private CrystalBall mCrystalBall = new CrystalBall();
private TextView mAnswerLabel;
private Button mGetAnswerButton;
private ImageView mCrystalBallImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Declare our View variables
    //Assign them the Views from layout files
    mAnswerLabel = (TextView) findViewById(R.id.textView1);
    mGetAnswerButton = (Button) findViewById(R.id.button1);

    mGetAnswerButton.setOnClickListener(new View.OnClickListener(){

        public void onClick(View arg0) {
            String answer = mCrystalBall.getAnswer();

            //Update the label with our dynamic answer
            mAnswerLabel.setText(answer);

            animateCrystalBall();
            animateAnswer();
            playSound();
        }

    });
}

private void animateCrystalBall() {
    mCrystalBallImage = (ImageView) findViewById(R.id.imageView1);
    mCrystalBallImage.setImageResource(R.drawable.ball_animation);
    AnimationDrawable ballAnimation = (AnimationDrawable) mCrystalBallImage.getDrawable();

    ballAnimation.start();
}

private void animateAnswer() {
    AlphaAnimation fadeInAnimation = new AlphaAnimation(0, 1);
    fadeInAnimation.setDuration(1500);
    fadeInAnimation.setFillAfter(true);

    mAnswerLabel.setAnimation(fadeInAnimation);
}

private void playSound() {
    MediaPlayer player = MediaPlayer.create(this, R.raw.crystal_ball);
    player.start();

    player.setOnCompletionListener(new OnCompletionListener() {


        public void onCompletion(MediaPlayer mp) {
            mp.release();
        }
    });




}

最佳答案

我认为是AVD中的问题。尝试重新创建虚拟设备或在真实的智能手机上调试。曾经我在AVD方面也遇到了麻烦。但是,当我尝试在真正的智能手机上调试时,所有错误都消失了。

10-08 07:13