Java me 无法在j2me中打开三星手机上的摄像头
我已经写了下面的代码。它用于创建摄影机播放器。我在诺基亚手机上测试了它。它的工作很好,我能够看到相机和使用它的功能 但问题是,当代码在三星手机上测试时,会引发媒体异常,最终不得不退出应用程序。由于此代码,我的内置摄像头功能(即在三星手机上)也停止工作。那是什么原因呢Java me 无法在j2me中打开三星手机上的摄像头,java-me,midp,mmapi,Java Me,Midp,Mmapi,我已经写了下面的代码。它用于创建摄影机播放器。我在诺基亚手机上测试了它。它的工作很好,我能够看到相机和使用它的功能 但问题是,当代码在三星手机上测试时,会引发媒体异常,最终不得不退出应用程序。由于此代码,我的内置摄像头功能(即在三星手机上)也停止工作。那是什么原因呢 public void startCamera() { try { try { // if player==null play
public void startCamera()
{
try
{
try
{
// if player==null
player = createPlayer();
}
catch (Exception ex)
{
ex.printStackTrace();
ErrorDialog.show(ex, "We are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
try
{
player.realize();
player.prefetch();
}
catch (MediaException ex)
{
ex.printStackTrace();
ErrorDialog.show(ex, "We are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
//Grab the video control and set it to the current display.
videoControl = (VideoControl)(player.getControl("VideoControl"));
if (videoControl == null)
{
//discardPlayer();
stopCamera();
ErrorDialog.show("Unsupported:\n"+
"Can't get video control\n"+
"We are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
mediaComponent = new MediaComponent(player);
mediaComponent.setFocusable(false);
m_cameraScreen.showCamera(mediaComponent);
start();
}
catch(Exception ex)
{
ex.printStackTrace();
//discardPlayer();
stopCamera();
ErrorDialog.show("Sorry,Resources unavailable.\nWe are exiting the application.",
"Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
public void actionPerformed() {
m_objMIDlet.exitApp();
}
});
}
}
}第一件事首先,您必须意识到,除非您使用的是Symbian手机,否则
printStackTrace()
在emulator之外几乎毫无用处
您还可以使用java.lang.Throwable
而不是分隔异常
和错误
您可以通过将信息收集为字符串
并在测试时将其附加到简单的lcdui表单
来准确了解发生了什么:
try {
// do something that could potentially fail
} catch (Throwable th) {
myDebugLcduiForm.append("potential failure number xx." + th + th.getMessage());
// if necessary, throw a new RuntimeException
}
一旦您确切地知道哪行代码引发了什么异常,您可能需要更新/重新发布您的问题 那么,你有什么例外?你应该研究你的异常处理方法…这就是我所说的异常处理。。。您甚至无法确定异常发生的位置(可能是
如果(mPlayer==null)
?我收到一个媒体异常,声明“抱歉,资源不可用。我们正在退出应用程序”。使用三星手机时,它抛出IO异常“data source not found”,这是名为Manager.createPlayer的重载方法之一?
try {
// do something that could potentially fail
} catch (Throwable th) {
myDebugLcduiForm.append("potential failure number xx." + th + th.getMessage());
// if necessary, throw a new RuntimeException
}