gpt4 book ai didi

java-me - 无法在j2me中打开三星手机上的相机

转载 作者:行者123 更新时间:2023-12-02 16:17:22 26 4
gpt4 key购买 nike

我写了下面的代码。它用于创建相机播放器。我在诺基亚手机上测试过。它工作正常,我能够看到相机并使用其功能。

但问题是,当代码在三星手机上测试时,它会抛出媒体异常,最终必须退出应用程序。由于此代码,我的内置相机功能(即三星手机上)也停止工作。那么这是什么原因呢?

    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();
}
});
}

}

    private Player createPlayer()throws MediaException, Exception 
{
Player mPlayer = null;
// try capture://image first for series 40 phones
try
{
mPlayer = Manager.createPlayer("capture://image");
}
catch (Exception e)
{
e.printStackTrace();
}
catch (Error e)
{
e.printStackTrace();
}

// if capture://image failed, try capture://video
if (mPlayer == null)
{
try
{
mPlayer = Manager.createPlayer("capture://video");
}
catch (Exception e)
{
e.printStackTrace();
throw new MediaException("Sorry,Resources unavailable.");
}
}

if(mPlayer == null)
throw new Exception("Sorry,Resources unavailable.");

return mPlayer;

}

最佳答案

首先,您必须认识到 printStackTrace() 在模拟器之外几乎没有任何用处,除非您使用的是 Symbian 手机。

您还可以使用java.lang.Throwable来代替分隔ExceptionError

在测试时,您可以通过将信息收集为 String 并将其附加到简单的 lcdui Form 来准确了解会发生什么:


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
}

一旦您确切地知道哪行代码引发了什么异常,您可能想要更新/重新发布您的问题。

关于java-me - 无法在j2me中打开三星手机上的相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10549762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com