Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Y is this showing a error???

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Y is this showing a error???

    Y DOES THIS CODE SHOW ERROR ?????????

    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.awt.image.ImageObserver;
    import java.io.BufferedInputStream;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;

    import javax.swing.JFrame;


    public class Axis implements Runnable {
    private static final long serialVersionUID = 1L;
    public boolean useMJPGStream = true;
    public String jpgURL = "http://ip here/video.cgi/jpg/image.cgi?resolution=640×480";
    public String mjpgURL = "http://ip here /video.cgi/mjpg/video.cgi?resolution=640×480";
    DataInputStream dis;
    private BufferedImage image = null;
    public Dimension imageSize = null;
    public boolean connected = false;
    private boolean initCompleted = false;
    HttpURLConnection huc = null;
    Component parent;

    /** Creates a new instance of AxisCamera */
    public Axis(Component parent_) {
    parent = parent_;
    }

    public void connect() {
    try {
    URL u = new URL(useMJPGStream ? mjpgURL : jpgURL);
    huc = (HttpURLConnection) u.openConnection();

    // System.out.println(huc.getContentType());
    InputStream is = huc.getInputStream();

    connected = true;
    BufferedInputStream bis = new BufferedInputStream(is);
    dis = new DataInputStream(bis);
    if (!initCompleted)
    initDisplay();
    } catch (IOException e) { // incase no connection exists wait and try
    // again, instead of printing the error
    try {
    huc.disconnect();
    Thread.sleep(60);
    } catch (InterruptedException ie) {
    huc.disconnect();
    connect();
    }
    connect();
    } catch (Exception e)
    {
    ;
    }
    }

    public void initDisplay() { // setup the display
    if (useMJPGStream)
    readMJPGStream();
    else {
    readJPG();
    disconnect();
    }
    imageSize = new Dimension(image.getWidth(), image.getHeight());
    parent.setPreferredSize(imageSize);
    parent.setSize(imageSize);
    parent.validate();
    initCompleted = true;
    }

    public void disconnect() {
    try {
    if (connected) {
    dis.close();
    connected = false;
    }
    } catch (Exception e) {
    ;
    }
    }

    public void paint(Graphics g) { // used to set the image on the panel
    if (image != null)
    g.drawImage(image, 0, 0, (ImageObserver) this);
    }

    public void readStream() { // the basic method to continuously read the
    // stream
    try {
    if (useMJPGStream) {
    while (true) {

    readMJPGStream();
    parent.repaint();
    }
    } else {
    while (true) {
    connect();
    readJPG();
    parent.repaint();
    disconnect();

    }
    }

    } catch (Exception e) {
    ;
    }
    }

    public void readMJPGStream() { // preprocess the mjpg stream to remove the
    // mjpg encapsulation
    readLine(3, dis); // discard the first 3 lines
    readJPG();
    readLine(2, dis); // discard the last two lines
    }

    public void readJPG() { // read the embedded jpeg image
    try {


    // JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis);
    //image = decoder.decodeAsBufferedImage();

    } catch (Exception e) {
    e.printStackTrace();
    disconnect();
    }

    }

    public void readLine(int n, DataInputStream dis) { // used to strip out the
    // header lines
    for (int i = 0; i < n; i++) {
    readLine(dis);
    }
    }

    public void readLine(DataInputStream dis) {
    try {
    boolean end = false;
    String lineEnd = "\n"; // assumes that the end of the line is marked
    // with this
    byte[] lineEndBytes = lineEnd.getBytes();
    byte[] byteBuf = new byte[lineEndBytes.length];

    while (!end) {
    dis.read(byteBuf, 0, lineEndBytes.length);
    String t = new String(byteBuf);
    System.out.print(t); // uncomment if you want to see what the
    // lines actually look like
    if (t.equals(lineEnd))
    end = true;
    }
    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    public void run() {
    System.out.println("in Run...................");
    connect();
    readStream();
    }

    @SuppressWarnings("deprecation")
    public static void main(String[] args) {


    JFrame jframe = new JFrame();
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
    Axis axPanel = new Axis(jframe);

    new Thread(axPanel).start();
    jframe.add(axPanel); //code shows error here
    jframe.pack();
    jframe.show();
    }
    }


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Y is this showing a error???

    I don't see an error! Post the exact stack trace and use code tags.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Y is this showing a error???

    1.jpg

    hers the snapshot with error

  4. #4
    Junior Member
    Join Date
    Apr 2013
    Location
    Philippines
    Posts
    19
    My Mood
    Dead
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Y is this showing a error???

    maybe the method doesnt have a parameter.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Y is this showing a error???

    See the API for the method you are using. What does it say? What does it accept as a parameter (s)? Are you passing an instance(s) of that type?

    FYI, please wrap your code in the code tags, please copy and paste errors rather than screen shots, and please use proper grammar

Similar Threads

  1. JScrollPane not showing up
    By mwardjava92 in forum AWT / Java Swing
    Replies: 2
    Last Post: February 27th, 2013, 03:27 PM
  2. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  3. Why it is showing error??
    By Sreejith63 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 12th, 2012, 12:16 AM
  4. Showing JPanel error
    By Fermen in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 20th, 2011, 12:12 PM
  5. Label not showing up.
    By joshft91 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 1st, 2011, 03:36 PM