Pagina 2 di 3 primaprima 1 2 3 ultimoultimo
Visualizzazione dei risultati da 11 a 20 su 30
  1. #11
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    Quote Originariamente inviata da giannino1995 Visualizza il messaggio
    Uffa ma nessuno riesce a trovare una soluzione al mio caso? Sono giorni che non leggo risposta... è una questione proprio banale per dei luminari come voi!!! ...

    sbagliato perchè per capire cosa succede significa debuggare tutto al posto tuo, non tutti c'hanno voglia/tempo di farlo.
    sbagliato perchè pur essendo banale, se qualcuno mi chiede qualcosa con quel tono per dispetto dico di no.
    sbagliato perchè non leggi l'errore

    Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
    at java.util.StringTokenizer.<init>(StringTokenizer.j ava:199)
    at java.util.StringTokenizer.<init>(StringTokenizer.j ava:236)
    at Esempio.update(Esempio.java:59)

    alla riga 59 di Esempio.java, cosa è null?
    RTFM Read That F*** Manual!!!

  2. #12
    questa riga di codice:

    codice:
    StringTokenizer st = new StringTokenizer(text);
    ma l'errore non è qua perché come ho già detto se scrivo:

    codice:
    text = "efvde kjh kjuhd suhdjuh  shjiuhu huj hjklh";
    al posto di:

    codice:
    text = getParameter("text");
    il programma funziona. In pratica è come getParameter() non facesse il suo sporco lavoro ma ti giuro che ho già provato a riscrivere l'html, ad accorciare la frase, a mettere tutto su di una riga ma nulla... è un problema semplice ma io non riesco proprio a vederlo... ho un nervoso che mi sta divorando...

    poi da quando ho iniziato a leggere il libro ho sempre avuto un problema fastidiosissimo che non sono mai riuscito a risolvere: tutte le volte che apro un'applet in java mi esce fuori un messaggio dove mi si chiede di accettare l'applicazione. Se realizzassi un sito web e il visitatore dovesse sempre premere su accetto si stuferebbe dopo la seconda volta... non è possibile eliminare questo problema? e poi il tag applet non è deprecato dall'html4? non ci sarà qualcosa di diverso con l'html5?

    sto cominciando a pensare che sia il mio linux il problema ma non ne sono sicuro perché le altre applet funzionano...
    Ultima modifica di giannino1995; 04-12-2013 a 11:04

  3. #13
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    scusa sei sicuro che

    codice:
    text = getParameter("text");
    non ti ritorni null? ci metti la mano sul fuoco?
    Io prima della tokenizzazione farei una roba simile

    codice:
    text = getParameter("text"); 
    System.out.println("text vale " + text); 
    StringTokenizer st = new StringTokenizer(text);
    o ancora più pulita

    codice:
    text = getParameter("text"); 
    if (text == null || text.trim().length() == 0){
       System.out.println("non sono riuscito a parsare l'html"); 
    }else{
       System.out.println("Spezzetto la riga " + text);  
       StringTokenizer st = new StringTokenizer(text); 
    }
    giusto per essere sicuri che è vero che ottieni qualcosa.

    se poi guardi le API di StringTokenizer (http://docs.oracle.com/javase/7/docs...a.lang.String) )
    noti anche che l'eccezione NullPointerException è ritornata se il parametro passato è null.

    detto questo, 99 su 100 text quando fai quella chiamata vale null.

    se tu volessi realizzare un sito web usando java, non usare le applet!!!
    Dovresti fare il sito in jsp (se ti vuoi far del male) o ci sono millemila framework che facilitano il lavoro.
    Ultima modifica di valia; 04-12-2013 a 11:11
    RTFM Read That F*** Manual!!!

  4. #14
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    Quote Originariamente inviata da giannino1995 Visualizza il messaggio
    questa riga di codice:
    sto cominciando a pensare che sia il mio linux il problema ma non ne sono sicuro perché le altre applet funzionano...
    in realtà no, linux non è il tuo problema
    RTFM Read That F*** Manual!!!

  5. #15
    Quote Originariamente inviata da valia Visualizza il messaggio
    in realtà no, linux non è il tuo problema

    Ottengo:

    non sono riuscito a parsare l'html

    nella console e sull'html il solito messaggio:

    IcedTea Tea Wb Plugin Click here for details. An exception has occurred

    se clicco mi si apre una nuova finestra con questo testo:

    The folloing exception has occured. For more information, try to launch the browser from the command line and examine the output.
    For even more information you can visit http://icedtea.classpath.org/wiki/IcedTea-Web and follow the steps described there on how to obtain necessary information to file bug

    Another available info:
    IcedTea-Web Plugin version: 1.4 (1.4-3ubuntu2)
    04/12/13 12.55
    Exception was:
    java.lang.NullPointerException
    at net.sourceforge.jnlp.NetxPanel.runLoader(NetxPanel .java:116)
    at sun.applet.AppletPanel.run(AppletPanel.java:380)
    at java.lang.Thread.run(Thread.java:724)

  6. #16
    P.S.: Sto leggendo un manuale e purtroppo mi devo assorbire il capitolo sulle applet! condivido con quello che dici...

  7. #17
    Nel tuo linguaggio: IMRTFM "I must read..."

  8. #18
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    in realtà se continui ad indagare (dall'errore che hai postato) noto che è quello che è successo qui (stackoverflow sempre mitico).

    http://stackoverflow.com/questions/1...its-class-name

    salvo casi strani le applet non vengono usate (si fanno le in altri modi molto migliori): cosa devi fare tu dopo aver finito il manuale?
    Perché credo che il capitolo sulle applet puoi saltarlo senza per questo avere una preparazione monca
    RTFM Read That F*** Manual!!!

  9. #19
    Ho seguito il tuo consiglio e ho corretto in questo modo:

    Esempio.java >> Esempio.class

    codice:
    // Demonstrate text alignment. 
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    /* <title>Text Layout</title>
       <applet code="Esempio" width=200 height=200>
       <param name="text" value="Output to a Java window is actually quite easy. 
          As you have seen, the AWT provides support for
          fonts, colors, text, and graphics. <P>  Of course,
          you must effectively utilize these items
          if you are to achieve professional results.">
        <param name="fontname" value="Serif">
        <param name="fontSize" value="14">
       </applet>
     */
    
     public class Esempio extends Applet {
      final int LEFT = 0;
      final int RIGHT = 1;
      final int CENTER = 2;
      final int LEFTRIGHT =3;
      int align;
      Dimension d;
      Font f;
      FontMetrics fm;
      int fontSize;
      int fh, bl;
      int space;
      String text;
    
      public void init() {
          try {
                System.setProperty("sun.java2d.opengl", "true");
            } catch (Exception e) {
                // System doesn't support opengl
            }
        setBackground(Color.white);
        text = getParameter("text");
        try {
          fontSize = Integer.parseInt(getParameter("fontSize"));}
        catch (NumberFormatException e) {
          fontSize=14;
        }
        align = LEFT;
        addMouseListener(new MyMouseAdapter(this));
      }
    
      public void paint(Graphics g) {
        update(g);
      }
    
      public void update(Graphics g) {
        d = getSize();
        g.setColor(getBackground());
        g.fillRect(0,0,d.width, d.height);
        if(f==null) f = new Font(getParameter("fontname"),
                                 Font.PLAIN, fontSize);
        g.setFont(f);
        if(fm == null) {
            fm = g.getFontMetrics();
            bl = fm.getAscent();
            fh = bl + fm.getDescent();
            space = fm.stringWidth(" ");
        }
    
        g.setColor(Color.black);
        StringTokenizer st = new StringTokenizer(text);
        int x = 0;
        int nextx;
        int y = 0;
        String word, sp;
        int wordCount = 0;
        String line = "";
        while (st.hasMoreTokens()) {
          word = st.nextToken();
          if(word.equals("<P>")) {
            drawString(g, line, wordCount,
                       fm.stringWidth(line), y+bl);
            line = "";
            wordCount = 0;
            x = 0;
            y = y + (fh * 2);
          }
          else {
            int w = fm.stringWidth(word);
            if(( nextx = (x+space+w)) > d.width ) {
              drawString(g, line, wordCount,
                         fm.stringWidth(line), y+bl);
              line = "";
              wordCount = 0;
              x = 0;
              y = y + fh;
            }
            if(x!=0) {sp = " ";} else {sp = "";}
            line = line + sp + word;
            x = x + space + w;
            wordCount++;
          }
        }
        drawString(g, line, wordCount, fm.stringWidth(line), y+bl);
      }
    
      public void drawString(Graphics g, String line,
                             int wc, int lineW, int y) {
        switch(align) {
          case LEFT: g.drawString(line, 0, y);
            break;
          case RIGHT: g.drawString(line, d.width-lineW ,y);
            break;
          case CENTER: g.drawString(line, (d.width-lineW)/2, y);
            break;
          case LEFTRIGHT:
            if(lineW < (int)(d.width*.75)) {
              g.drawString(line, 0, y);
            }
            else {
              int toFill = (int)((d.width - lineW)/wc);
              int nudge = d.width - lineW - (toFill*wc);
              int s = fm.stringWidth(" ");
              StringTokenizer st = new StringTokenizer(line);
              int x = 0;
              while(st.hasMoreTokens()) {
                String word = st.nextToken();
                g.drawString(word, x, y);
                if(nudge>0) {
                  x = x + fm.stringWidth(word) + space + toFill + 1;
                  nudge--;
                } else {
                  x = x + fm.stringWidth(word) + space + toFill;
                }
              }
            }
            break;
          }
    
      }
    
    }
    
    class MyMouseAdapter extends MouseAdapter {
      Esempio tl;
      public MyMouseAdapter(Esempio tl) {
        this.tl = tl;
      }
      public void mouseClicked(MouseEvent me) {
        tl.align = (tl.align + 1) % 4;
        tl.repaint();
      }
    }
    Gestione_Testo.html

    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
        <title>senza nome</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <meta name="generator" content="Geany 1.23.1" />
    </head>
    
    <body>
        
       <applet code="Esempio.class" width=200 height=200>
       <param name="text" value="Output to a Java window is actually quite easy. As you have seen, the AWT provides support for fonts, colors, text, and graphics. <P>  Of course, you must effectively utilize these items if you are to achieve professional results.">
        <param name="fontname" value="Serif">
        <param name="fontSize" value="14">
       </applet>
        
    </body>
    
    </html>
    Ho anche messo il contenuto tutto il contenuto su una riga nell'html come diceva l'altro forumista ma non funziona ugualmente.



    Sono proprio sfortunato...
    Ultima modifica di giannino1995; 04-12-2013 a 19:54

  10. #20
    Non funziona neppure su Windows 8... Nè Windows 8 nè Ubuntu 13.10... che nervoso... Windows non me la lascia avviare dice che non è sicura!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.