求高手帮忙解决:为什么我就是不能创建realized状态的Processor
import java.awt.*;import javax.media.protocol.*;
import javax.media.*;
import javax.swing.*;
import javax.media.control.*;
import java.awt.event.*;
import javax.media.util.*;
import javax.media.format.*;
import java.io.*;
class Myframe extends Frame
{ Processor player=null; Panel p1,p2;
ProcessorModel pm;
Component c1,c2;
CaptureDeviceInfo device;
MediaLocator locator;
Format[] fm;
ContentDescriptor cd;
String st="vfw:Microsoft WDM Image Capture (Win32):0";
DataSink sink;
MediaLocator dest;
Myframe(String s)
{super(s);
device=CaptureDeviceManager.getDevice(st);
locator=device.getLocator();fm=new Format[]{new VideoFormat(VideoFormat.RGB)};
cd=new ContentDescriptor(ContentDescriptor.RAW_RTP);pm=new ProcessorModel(locator,fm,cd);
try
{
player=Manager.createRealizedProcessor(pm);
dest = new MediaLocator("file://E:\\newfile.MPEG");
sink = Manager.createDataSink(player.getDataOutput(), dest);
sink.open();
sink.start();
player.start();
c1=player.getVisualComponent();
c2=player.getControlPanelComponent();
}catch(Exception e){};
setBounds(100,100,500,500);
setVisible(true);
setLayout(null);
p1=new Panel();
p1.setBounds(0,0,500,400);
p1.add(c1); //此行老报错,说什么引用了尚无开辟内存空间的对象
p2=new Panel();
p2.setBounds(0,400,500,100);p2.add(c2);
add(p1);add(p2);
this.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
}
}
public class Test5
{
public static void main(String[] args)
{ new Myframe("大家好");
}
}
为什么总抛出:Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Myframe.(init)(Test5.java:47)
搜索更多相关的解决方案:
null
----------------解决方案--------------------------------------------------------