如何解决这些错误? [英] How do i fix the errors?
问题描述
我看了你好Android的book.The计划将发挥我在原始文件夹中复制一个声音,但该程序没有运行,并给出错误。
I read Hello Android book.The program will play a sound that i copy in raw folder but the program is not run and gives errors.
错误:
activity_main不能得到解决或不是一个字段
activity_main cannot be resolved or is not a field
温度不能得到解决或不是一个字段
temp cannot be resolved or is not a field
Audio.java
Audio.java
package org.example.audio;
import android.app.Activity;
import android.media.MediaPlayer;
import android.view.KeyEvent;
import android.os.Bundle;
public class Audio extends Activity{
private MediaPlayer up;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
up=MediaPlayer.create(this,R.raw.Guilty);
}
@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
MediaPlayer mp;
switch(keyCode){
case KeyEvent.KEYCODE_DPAD_UP:
mp=up;
break;
default:
return super.onKeyDown(keyCode, event);
}
mp.seekTo(0);
mp.start();
return true;
}
}
请帮我,我修复错误。
干杯。
Please help me that i fix the errors. Cheers.
推荐答案
删除行
import android.R;
和导入R代表相应的包
在此行
setContentView(R.layout.activity_main);
删除到的setContentView整条生产线和类型(R并给予Ctrl +空格键,你会要求进口几包其中你需要导入其中包含项目名称(而不是android.R)包
remove the entire line and type till setContentView(R and give a ctrl+space . You will asked to import few packages among which you need to import a package which contains your project name ( and not android.R)
否则删除线进口android.R;简单地清理项目并构建它
or else remove the line import android.R; and simply clean the project and build it
这篇关于如何解决这些错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!