Results 1 to 4 of 4

Thread: Throwing Execptions

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Smile

    How's everybody doing tonight!
    This is probably an easy question for some
    of you to answer but im not sure of what to do.
    If i compile this class i keep getting an "unreported
    execption java.io.IOExecption; must be caught or
    declared to be thrown.
    while((character = bufferedinputstream.read()) != -1)

    ok fine i understand that but if i change my main to
    public static void main(String[] args) throws IOExecption{
    i get cannot resolve symbol.






    import java.io.*;


    class htmlparser{
    public static void main(String[] args){

    int character;
    int k = 0;
    int i = 0;
    byte[] hold = "Hello my name is brandon".getBytes();
    char[] htmltagholder;
    htmltagholder = new char[hold.length]; // htmltagholder array size is set to hold's size


    ByteArrayInputStream in = new ByteArrayInputStream(hold);
    BufferedInputStream bufferedinputstream = new BufferedInputStream(in);

    while((character = bufferedinputstream.read()) != -1) {
    if (hold[i] == '<') {
    do{
    System.arraycopy(hold,i,htmltagholder,k,1);
    i++;
    k++;
    }while(hold[i] != '>');
    } // the if statement
    }

    System.out.println(" The tags in your HTML file are: ");
    for(int x = 0; x < htmltagholder.length; x++){
    System.out.print(htmltagholder[x]);
    }
    }
    }

  2. #2
    Guest
    Your posted code compiles with the following 3 changes:

    public static void main(String[] args) throws IOException{

    if (hold[0] == '<') {

    }while(hold[0] != '>');

    The index "0" for the "hold" byte array was just for a test. Check your logic for what it should be. I tried "character", but the index was out of bounds.

    I'm also interested in writing a simple browser. Do you have thoughts on how to render images and text once the tags are known?

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Hey thanks VirtuallyVB! maybe you should start charging
    be by the post. {{{laughing}}} Yeah that code is just for some stupid project our teacher wants us to do to parse
    out html tags from an incoming file. I could do it i 2
    seconds in vb but in java im having trouble. Im not to sure how to render text and images once the tasgs are know. But i would like to find out....

  4. #4
    Guest

    Thumbs up

    That would be cool if you asked your teacher how to render them. I think I had the answer, but never tried it, so I don't know. I was concerned about placement (and maybe that needs further parsing of the tags with their placement fields within the tags).

    Another thing, ask how to create a hyperlink in Java.

    Perhaps we can take a Panel (named pagePanel) and add Labels for tags with text, but I still wonder if the alignment in the text tag (from additional parsing) would be sufficient to use as the alignment in a Label. I guess I have to code it to find out. Also an image tag could be the info for adding a Panel per image to the main Panel (pagePanel).

    I'm starting to get motivated. I just can't think of how to add a hyperlink--wait--MouseOver event for a Label perhaps. Sswweeeet.

    If you make the parser, let me know. I think I'll play with this within the next two weeks.

    My idea is to make a browser that I can trust (unlike Commercial Browsers) and also a relay/proxy type browser.

    Yeah, let me know if your parsing works out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width