Note that there are some explanatory texts on larger screens.

plurals
  1. POcannot start swing timer
    text
    copied!<p>I'm trying to make a Swing Timer that is executes when I press a button but never starts. My code is:</p> <pre><code>public class prueba extends JFrame { java.util.Date date= new java.util.Date(); private JPanel contentPane; Timer timero; ........ public prueba() { .......... timero = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("otra vez....uauuauauaua"); } }); btnIniciar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { timero.start(); ............... </code></pre> <p>Could you help me please? Thanks and sorry for my english!</p> <p>When I do these I have an error:</p> <pre><code>public class prueba extends JFrame { java.util.Date date= new java.util.Date(); private JPanel contentPane; Timer timero; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { prueba frame = new prueba(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public prueba() { final WebManager web = new WebManager("user","pass","http://www.spanishtracker.com/login.php"); //web.EnableDebug(); web.doLogin(); web.getCookies; ..... contentPane.add(txtSalida, gbc_txtSalida); timero.start(); </code></pre> <p>it gives me an error:</p> <pre><code>java.lang.NullPointerException at prueba.&lt;init&gt;(prueba.java:216) at prueba$1.run(prueba.java:56) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$400(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) These lines are: 216 timero.start(); 56 prueba frame = new prueba(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload