为什么我的 android 应用程序在 Android Studio 模拟器中一直停止?
Why does my android app keep stopping in the Android Studio emulator?
我尝试修复所有问题,但似乎找不到问题所在。这是我的 MainActivity.java 文件:
package com.weebly.chesslearners.firstgame;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.renderscript.Sampler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.view.animation.TranslateAnimation;
import static android.content.ContentValues.TAG;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new GamePanel(this));
final TextView player = (TextView) findViewById(R.id.textView);
final Button mover = (Button) findViewById(R.id.btnmove);
final ObjectAnimator animation = ObjectAnimator.ofFloat(player,"y",300, 500);
mover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
animation.setDuration(2000);
animation.setRepeatCount(1);
animation.setRepeatMode(ValueAnimator.REVERSE);
animation.start();
}
});
setContentView(R.layout.activity_main);
Log.i(TAG, "Build Successful");
}
}
我也添加了所有导入。
构建输出显示错误在行 "mover.setOnclick..." 上,但我找不到导致错误的原因。
我认为问题出在 setContentView(new GamePanel(this));
行
设置视图后,编译器将尝试在 GamePanel() 中找到您的文本视图和按钮 class,我猜它不在那里。
您可以通过添加来解决它
setContentView(R.layout.activity_main);
前
final TextView player = (TextView) findViewById(R.id.textView);
并稍后设置动态 UI 组件。
我尝试修复所有问题,但似乎找不到问题所在。这是我的 MainActivity.java 文件:
package com.weebly.chesslearners.firstgame;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.renderscript.Sampler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.view.animation.TranslateAnimation;
import static android.content.ContentValues.TAG;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new GamePanel(this));
final TextView player = (TextView) findViewById(R.id.textView);
final Button mover = (Button) findViewById(R.id.btnmove);
final ObjectAnimator animation = ObjectAnimator.ofFloat(player,"y",300, 500);
mover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
animation.setDuration(2000);
animation.setRepeatCount(1);
animation.setRepeatMode(ValueAnimator.REVERSE);
animation.start();
}
});
setContentView(R.layout.activity_main);
Log.i(TAG, "Build Successful");
}
}
我也添加了所有导入。 构建输出显示错误在行 "mover.setOnclick..." 上,但我找不到导致错误的原因。
我认为问题出在 setContentView(new GamePanel(this));
设置视图后,编译器将尝试在 GamePanel() 中找到您的文本视图和按钮 class,我猜它不在那里。
您可以通过添加来解决它
setContentView(R.layout.activity_main);
前
final TextView player = (TextView) findViewById(R.id.textView);
并稍后设置动态 UI 组件。