- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的问答游戏中,我将轮数设置为 15。无论答案是错误还是正确,游戏都不会终止。正确答案的分数递增,否则分数递减。我的测验游戏运行正常,但我在其中添加了计时器,这样当下一个问题出现时,分数就会递减。并且在计时器的finish()方法中添加计时器和递减方法之后。我的游戏只运行了 8 或 9 轮就终止了。并且分数也减少了 150。但是在我的 decrementScore() 方法中,我仅设置了减少 50。如果不在计时器的完成方法中添加此方法,则其工作正常。我的代码和日志猫如下:-提前致谢!
代码:-
public class QuestionActivity extends Activity implements OnClickListener{
private Question currentQ;
private GamePlay currentGame;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question);
processScreen();
}
private void processScreen()
{
/**
* Configure current game and get question
*/
currentGame = ((CYKApplication)getApplication()).getCurrentGame();
currentQ = currentGame.getNextQuestion();
Button nextBtn1 = (Button) findViewById(R.id.answer1);
nextBtn1.setOnClickListener(this);
Button nextBtn2 = (Button) findViewById(R.id.answer2);
nextBtn2.setOnClickListener(this);
Button nextBtn3 = (Button) findViewById(R.id.answer3);
nextBtn3.setOnClickListener(this);
Button nextBtn4 = (Button) findViewById(R.id.answer4);
nextBtn4.setOnClickListener(this);
Button nextBtn5 = (Button) findViewById(R.id.answer5);
nextBtn5.setOnClickListener(this);
/**
* Update the question and answer options..
*/
setQuestions();
}
/**
* Method to set the text for the question and answers from the current games
* current question
*/
private void setQuestions() {
//set the question text from current question
String question = Utility.capitalise(currentQ.getQuestion());
TextView qText = (TextView) findViewById(R.id.question);
qText.setText(question);
//set the available options
List<String> answers = currentQ.getQuestionOptions();
TextView option1 = (TextView) findViewById(R.id.answer1);
option1.setText(Utility.capitalise(answers.get(0)));
TextView option2 = (TextView) findViewById(R.id.answer2);
option2.setText(Utility.capitalise(answers.get(1)));
TextView option3 = (TextView) findViewById(R.id.answer3);
option3.setText(Utility.capitalise(answers.get(2)));
TextView option4 = (TextView) findViewById(R.id.answer4);
option4.setText(Utility.capitalise(answers.get(3)));
int score = currentGame.getScore();
String scr = String.valueOf(score);
TextView score1 = (TextView) findViewById(R.id.score);
score1.setText(scr);
new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
TextView timers = (TextView) findViewById(R.id.timers);
timers.setText("Time: " + millisUntilFinished / 1000);
}
public void onFinish() {
currentGame.decrementScore();
processScreen();
}
}.start();
}
@Override
public void onClick(View arg0) {
//Log.d("Questions", "Moving to next question");
if(arg0.getId()==R.id.answer5)
{
new AlertDialog.Builder(this)
.setMessage("Are you sure?")
.setCancelable(true)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
finish();
}
}).setNegativeButton("No", null).show();
}
else
{
if(!checkAnswer(arg0)) return;
/**
* check if end of game
*/
if (currentGame.isGameOver()){
//Log.d("Questions", "End of game! lets add up the scores..");
//Log.d("Questions", "Questions Correct: " + currentGame.getRight());
//Log.d("Questions", "Questions Wrong: " + currentGame.getWrong());
Intent i = new Intent(this, EndgameActivity.class);
startActivity(i);
finish();
}
else{
Intent i = new Intent(this, QuestionActivity.class);
finish();
startActivity(i);
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_BACK :
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Check if a checkbox has been selected, and if it
* has then check if its correct and update gamescore
*/
private boolean checkAnswer(View v) {
Button b=(Button) v;
String answer = b.getText().toString();
//Log.d("Questions", "Valid Checkbox selection made - check if correct");
if (currentQ.getAnswer().equalsIgnoreCase(answer))
{
b.setBackgroundResource(R.drawable.answercolor);
//Log.d("Questions", "Correct Answer!");
currentGame.incrementScore();
}
else{
b.setBackgroundResource(R.drawable.answercolorr);
//Log.d("Questions", "Incorrect Answer!");
currentGame.decrementScore();
}
return true;
}
}
分数递减和舍入增量日志猫在 getNextQuestion() 方法中显示一些错误的类。
public class GamePlay {
private int numRounds;
private int difficulty;
private String playerName;
private int score;
private int round;
private List<Question> questions = new ArrayList<Question>();
/**
* @return the right
*/
public int getScore() {
return score;
}
/**
* @param right the right to set
*/
public void setScore(int score) {
this.score = score;
}
/**
* @return the round
*/
public int getRound() {
return round;
}
/**
* @param round the round to set
*/
public void setRound(int round) {
this.round = round;
}
/**
* @param difficulty the difficulty to set
*/
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
/**
* @return the difficulty
*/
public int getDifficulty() {
return difficulty;
}
/**
* @param questions the questions to set
*/
public void setQuestions(List<Question> questions) {
this.questions = questions;
}
/**
* @param q the question to add
*/
public void addQuestions(Question q) {
this.questions.add(q);
}
/**
* @return the questions
*/
public List<Question> getQuestions() {
return questions;
}
public Question getNextQuestion(){
//get the question
Question next = questions.get(this.getRound());
//update the round number to the next round
this.setRound(this.getRound()+1);
return next;
}
/**
* method to increment the number of correct answers this game
*/
/**
* method to increment the number of incorrect answers this game
*/
public void incrementScore(){
score=score+100;
}
public void decrementScore()
{
score=score-50;
}
/**
* @param numRounds the numRounds to set
*/
public void setNumRounds(int numRounds) {
this.numRounds = numRounds;
}
/**
* @return the numRounds
*/
public int getNumRounds() {
return numRounds;
}
/**
* method that checks if the game is over
* @return boolean
*/
public boolean isGameOver(){
return (getRound() >= getNumRounds());
}
}
日志猫:-
09-06 15:29:23.321: D/dalvikvm(3372): Debugger has detached; object registry had 1 entries
09-06 15:30:00.081: D/gralloc_goldfish(3942): Emulator without GPU emulation detected.
09-06 15:30:05.321: D/dalvikvm(3942): GC_FOR_ALLOC freed 39K, 7% free 2661K/2844K, paused 86ms, total 97ms
09-06 15:30:05.371: I/dalvikvm-heap(3942): Grow heap (frag case) to 4.795MB for 2160016-byte allocation
09-06 15:30:05.421: D/dalvikvm(3942): GC_FOR_ALLOC freed 1K, 4% free 4768K/4956K, paused 56ms, total 56ms
09-06 15:30:05.541: D/dalvikvm(3942): GC_CONCURRENT freed 1K, 4% free 4767K/4956K, paused 8ms+35ms, total 118ms
09-06 15:30:09.050: D/dalvikvm(3942): GC_FOR_ALLOC freed 16K, 3% free 5226K/5388K, paused 60ms, total 72ms
09-06 15:30:09.080: I/dalvikvm-heap(3942): Grow heap (frag case) to 7.300MB for 2160016-byte allocation
09-06 15:30:09.190: D/dalvikvm(3942): GC_CONCURRENT freed 242K, 6% free 7093K/7500K, paused 4ms+4ms, total 105ms
09-06 15:30:10.140: I/Choreographer(3942): Skipped 768 frames! The application may be doing too much work on its main thread.
09-06 15:30:12.360: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:13.364: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:16.191: I/Choreographer(3942): Skipped 53 frames! The application may be doing too much work on its main thread.
09-06 15:30:17.191: I/Choreographer(3942): Skipped 46 frames! The application may be doing too much work on its main thread.
09-06 15:30:20.225: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:21.251: I/Choreographer(3942): Skipped 45 frames! The application may be doing too much work on its main thread.
09-06 15:30:22.951: I/Choreographer(3942): Skipped 62 frames! The application may be doing too much work on its main thread.
09-06 15:30:23.934: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:26.042: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:27.050: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:28.821: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:31.370: I/Choreographer(3942): Skipped 30 frames! The application may be doing too much work on its main thread.
09-06 15:30:31.830: I/Choreographer(3942): Skipped 48 frames! The application may be doing too much work on its main thread.
09-06 15:30:32.447: I/Choreographer(3942): Skipped 45 frames! The application may be doing too much work on its main thread.
09-06 15:30:33.474: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:34.501: I/Choreographer(3942): Skipped 51 frames! The application may be doing too much work on its main thread.
09-06 15:30:35.981: I/Choreographer(3942): Skipped 50 frames! The application may be doing too much work on its main thread.
09-06 15:30:36.991: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:38.008: I/Choreographer(3942): Skipped 45 frames! The application may be doing too much work on its main thread.
09-06 15:30:40.082: I/Choreographer(3942): Skipped 43 frames! The application may be doing too much work on its main thread.
09-06 15:30:40.181: D/AndroidRuntime(3942): Shutting down VM
09-06 15:30:40.181: W/dalvikvm(3942): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
09-06 15:30:40.191: E/AndroidRuntime(3942): FATAL EXCEPTION: main
09-06 15:30:40.191: E/AndroidRuntime(3942): java.lang.IndexOutOfBoundsException: Invalid index 15, size is 15
09-06 15:30:40.191: E/AndroidRuntime(3942): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
09-06 15:30:40.191: E/AndroidRuntime(3942): at java.util.ArrayList.get(ArrayList.java:304)
09-06 15:30:40.191: E/AndroidRuntime(3942): at com.abc.cyk.quiz.GamePlay.getNextQuestion(GamePlay.java:100)
09-06 15:30:40.191: E/AndroidRuntime(3942): at com.abc.cyk.QuestionActivity.processScreen(QuestionActivity.java:42)
09-06 15:30:40.191: E/AndroidRuntime(3942): at com.abc.cyk.QuestionActivity.access$0(QuestionActivity.java:36)
09-06 15:30:40.191: E/AndroidRuntime(3942): at com.abc.cyk.QuestionActivity$1.onFinish(QuestionActivity.java:98)
09-06 15:30:40.191: E/AndroidRuntime(3942): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
09-06 15:30:40.191: E/AndroidRuntime(3942): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 15:30:40.191: E/AndroidRuntime(3942): at android.os.Looper.loop(Looper.java:137)
09-06 15:30:40.191: E/AndroidRuntime(3942): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-06 15:30:40.191: E/AndroidRuntime(3942): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 15:30:40.191: E/AndroidRuntime(3942): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 15:30:40.191: E/AndroidRuntime(3942): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-06 15:30:40.191: E/AndroidRuntime(3942): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-06 15:30:40.191: E/AndroidRuntime(3942): at dalvik.system.NativeStart.main(Native Method)
09-06 15:30:44.592: E/Trace(3971): error opening trace file: No such file or directory (2)
09-06 15:30:44.691: D/dalvikvm(3971): GC_FOR_ALLOC freed 36K, 7% free 2413K/2592K, paused 27ms, total 29ms
09-06 15:30:44.711: I/dalvikvm-heap(3971): Grow heap (frag case) to 4.553MB for 2160016-byte allocation
09-06 15:30:44.821: D/dalvikvm(3971): GC_FOR_ALLOC freed 1K, 4% free 4521K/4704K, paused 107ms, total 107ms
09-06 15:30:44.871: D/dalvikvm(3971): GC_CONCURRENT freed <1K, 4% free 4521K/4704K, paused 4ms+3ms, total 50ms
09-06 15:30:45.341: D/gralloc_goldfish(3971): Emulator without GPU emulation detected.
09-06 15:30:47.540: I/Choreographer(3971): Skipped 64 frames! The application may be doing too much work on its main thread.
我发现了我的代码中的错误。倒数计时器方法中的 finish() 方法停止完成循环,递减方法会减少每一轮的分数,而不是在计时结束时减少分数。有人可以知道如何解决吗。请帮助我。
最佳答案
该 View 中显示的错误是编译错误。那不是他想要的。他想要运行时错误。他做得正确,但是他似乎没有粘贴整个 logcat 输出,因为他发布的行都不是错误行。
编辑:或者更确切地说,它们是系统级错误,开发人员可以忽略它们,因为它们是由系统自动处理的。您需要注意的是未捕获的异常,例如 NullPointerException 或 IllegalStateException 等...这些是应用程序级错误,您需要修复这些错误。
关于java - 如何解决这些 logcat 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18671605/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 4 年前。 Improve
我在终端中使用“adb -d logcat”来查看我的应用程序日志文件。最近,我遇到了一大堆运行时错误——由于某种原因我看不到所有这些错误。它只是在结尾处以“...30 more”结束: [ 08-1
我的 Logcat 停止与我的“开发者设备”Huawei Y5 一起工作。 我使用完全更新的 Android 3.5.1,直到两天前一切正常,现在突然我的应用程序日志不再显示了。 logcat 显示以
我使用 Eclipse 开发应用程序。当我转到 eclipse 的菜单窗口-> 显示 View -> 其他时,我发现两个项目名为“LogCat”和“LogCat(deprecated)”。 LogCa
我在我的应用程序中使用 Timber 和 DebugTree。我想将所有消息记录到 Firebase 崩溃报告中。 Timber.plant(object : Timber.DebugTree()
在 Moto G 上开发我的应用程序时,我经常遇到数以万计的以下消息淹没日志。 E/MM_OSAL ( 275): isSamePayload Sync byte(0x47) not found!!
在注意到 Android Studio 中没有显示 Logcat 消息后,我尝试了所有解决方案,但都没有奏效。我最终尝试了命令 adb devices 并确定我的设备在那里,但是当我尝试 adb lo
来自命令:C:\android-sdk-windows\platform-tools>adb shell 然后是 logcat -b radio 它打印旧的历史日志。我试着像这样调用 logcat -
我每15分钟就会遇到“blank logcat”或“logcat bug”的问题,随意告诉它! 我知道以下解决方案可以解决此问题: 进入 DDMS 并选择我的设备 => 80% 的情况下,logcat
请原谅我没有以完整尺寸显示 Logcat(到目前为止,我使用的是 RAM 和图形内存有限的 VM)。 每次启动 Eclipse 时,Logcat 都会像这样显示所有这些信息列(红色圆圈)。 现在,我想
我正在尝试运行 react-native log-android 来测试在我的 react-native 手机应用程序上上传谷歌照片。我得到错误 warn The following packages
对于 Android 应用程序,我将日志保存在设备本身上,以便在出现问题时我们可以找出问题所在。此设备在无互联网环境中运行,因此无法远程写入日志。 下面的代码首先清除缓冲区,然后将记录的内容连续写入“
显示 LogCat 几分钟后消失。我从 Window->Preferences->Logcat 中将 LogCat 输出消息的数量更改为 10000。但在读取整个堆栈之前仍然消失。知道为什么会发生这种
我有一些与 Android Logcat 相关的问题,我将这些问题称为 REAL DEVICE 而不是模拟器: 我有一个程序有很多 Log.d (或其他类似的日志功能),我做了一些谷歌搜索,发现这些日
我收到很多与我的应用程序相关的此类 logcat 消息。 2019-03-13 10:05:51.065 27319-27319/com.example.fir_s1 I/chatty: uid=10
我正在对一个奇怪的错误进行故障排除,当不良行为发生时,我在 logcat 中看到了这一点。 --------- beginning of system 这是什么意思?我没有找到任何 nativ
我想通过 APPIUM 获取特定标签(例如:testing_aws)的 ADB logcats。实际上我是直接从控制台完成此操作的,如下所示 我导航至 /home/jagadeesh/android-
我刚刚开始使用 android,正在制作一个 webview 应用程序 我的整个计划是显示启动屏幕,直到 webview 加载,然后切换某些内容的可见性,然后使 webview 可见 WebView
我刚刚在运行 Mountain Lion 的 Mac 上安装了 Eclipse 3.8。我打开了 LogCat 窗口并点击最小化,它去了某个地方...... 现在当我点击 Window>Show Vi
我使用 Parse 作为我的应用程序的后端,并且我使用了他们的 quick start guide设置推送通知。 我已经一步一步地跟着它了,没有得到插入。当我启动应用程序时,我还在 logcat 中收
我是一名优秀的程序员,十分优秀!