gpt4 book ai didi

java - Android 应用程序添加图像后无法启动

转载 作者:行者123 更新时间:2023-12-01 13:02:26 25 4
gpt4 key购买 nike

我遇到应用程序无法从 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 上也遇到了一些麻烦。但是当我尝试在真正的智能手机上调试时,所有错误都消失了。

关于java - Android 应用程序添加图像后无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23422984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com