录音机程序问题
java吧
全部回复
仅看楼主
level 5
chaunc♤ 楼主
求解这句话哪里错了 startRecord = (Button)findViewById(R.id.startRecord)
2014年07月14日 01点07分 1
level 5
chaunc♤ 楼主
刚学andriod开发
2014年07月14日 01点07分 2
level 7
这句话神也救不了你...把异常logcat贴上来就OK了
2014年07月14日 03点07分 3
startRecord = (Button)findViewById(R.id.startRecord); startRecord.setText(R.string.startRecord); 后面都是什么startrecord ,startstop有问题。都是类似的问题。
2014年07月14日 07点07分
回复 liuchangnan789 :ID也有问题
2014年07月14日 07点07分
level 12
你的button定义了吗?R文件有那个id了吗?
2014年07月14日 03点07分 4
level 5
chaunc♤ 楼主
button定义了。我看一下id
2014年07月14日 03点07分 5
level 5
chaunc♤ 楼主
好的一回回去发
2014年07月14日 03点07分 6
level 5
chaunc♤ 楼主
package com.example.test1;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private static final String LOG_TAG = "AudioRecordTest";
//语音文件保存路径
private String FileName = null;
//界面控件
private Button startRecord;
private Button startPlay;
private Button stopRecord;
private Button stopPlay;
//语音操作对象
private MediaPlayer mPlayer = null;
private MediaRecorder mRecorder = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//开始录音
startRecord = (Button)findViewById(R.id.startRecord);
startRecord.setText(R.string.startRecord);
//绑定监听器
startRecord.setOnClickListener(new startRecordListener());
//结束录音
stopRecord = (Button)findViewById(R.id.stopRecord);
stopRecord.setText(R.string.stopRecord);
stopRecord.setOnClickListener(new stopRecordListener());
//开始播放
startPlay = (Button)findViewById(R.id.startPlay);
startPlay.setText(R.string.startPlay);
//绑定监听器
startPlay.setOnClickListener(new startPlayListener());
//结束播放
stopPlay = (Button)findViewById(R.id.stopPlay);
stopPlay.setText(R.string.stopPlay);
stopPlay.setOnClickListener(new stopPlayListener());
//设置sdcard的路径
FileName = Environment.getExternalStorageDirectory().getAbsolutePath();
FileName += "/audiorecordtest.3gp";
}
//开始录音
class startRecordListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(FileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
}
}
//停止录音
class stopRecordListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
//播放录音
class startPlayListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mPlayer = new MediaPlayer();
try{
mPlayer.setDataSource(FileName);
mPlayer.prepare();
mPlayer.start();
}catch(IOException e){
Log.e(LOG_TAG,"播放失败");
}
}
}
//停止播放录音
class stopPlayListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mPlayer.release();
mPlayer = null;
}
}
}
2014年07月14日 07点07分 7
level 5
chaunc♤ 楼主
2014年07月14日 07点07分 8
level 7
把鼠标移到红字上看什么提示
2014年07月14日 09点07分 9
id can not be resolved or it is not a file.
2014年07月14日 09点07分
回复 liuchangnan789 :你的R文件在不在?
2014年07月14日 09点07分
回复 stan895 :R文件在啊。但是里面没有关于那几个变量的地址。是直接把代码粘贴复制到MainActivity里就行嘛?[狂汗]。。。
2014年07月14日 09点07分
回复 liuchangnan789 额...你有没有布局文件啊!?
2014年07月14日 09点07分
1