Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:13:04+00:00 2026-06-12T05:13:04+00:00

I tried to create a timer and a timertask but I can’t get it

  • 0

I tried to create a timer and a timertask but I can’t get it to work 🙁

“Your post does not have much context to explain the code sections; please explain your scenario more clearly.”?

Error

Timer.sched(TimerTask, long, long) line: not available
Source not found.

Exception in thread "main" java.lang.NullPointerException
at java.util.Timer.sched(Unknown Source)
at java.util.Timer.schedule(Unknown Source)
at Game.<init>(Game.java:42)
at Game.main(Game.java:25)

Game.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.*;
import java.util.Timer;
import java.util.TimerTask;
import java.lang.Runnable;

public class Game implements ActionListener {

private static Game hosmos2;
private JFrame frmMain;
private AntiCheat holyanticheat;
private Dimension screen;
//private Engine holyengine;
private int sx, sy;
private Timer timCheat; // My Timer
private TimerTask tmtCheat; // My TimerTask

public static void main(String[] args) throws FileNotFoundException, InterruptedException {

    hosmos2 = new Game();
}

private Game() throws FileNotFoundException, InterruptedException {

    frmMain = new JFrame("Hosmos 2");
    frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmMain.setSize(1366, 768);
    screen = Toolkit.getDefaultToolkit().getScreenSize();
    sx = (int) ((screen.getWidth() - frmMain.getWidth()) / 2);
    sy = (int) ((screen.getHeight() - frmMain.getHeight()) / 2);
    frmMain.setLocation(sx, sy);
    holyanticheat = new AntiCheat();
    //holyengine = new Engine();
    timCheat = new Timer(); // Creates my timer
    //frmMain.add(holyengine);
    frmMain.setVisible(true);
    timCheat.schedule(tmtCheat, 500); // Schedule my TimerTask
    Thread.sleep(1000);
    timCheat.cancel();
}

public void actionPerformed(ActionEvent e) {


}

public void tmtCheat() throws IOException { // Void for my TimerTask

    holyanticheat.Detect(); // Runs Detect() in AntiCheat.java
}

}

AntiCheat.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.util.*;

public class AntiCheat {

private BufferedReader highscore;
private DataInputStream dis;
private FileInputStream fis;
private InputStreamReader isr;
private String userscore, realscore;

public static void main(String[] args) {


}

public AntiCheat() throws FileNotFoundException {

    fis = new FileInputStream("data/highscore.hs2");
    dis = new DataInputStream(fis);
    isr = new InputStreamReader(dis);
    highscore = new BufferedReader(isr);
}

public void Detect() throws IOException { // Checks if you have cheated your score

    userscore = highscore.readLine();
    if (!userscore.equals("If you touch this then you won't be able to play noob ;)")) {

        for (int i = 0; i < 1000; i++) {

            realscore = Integer.toString(i);
            for (int j = 0; j < 173; j++) {

                realscore = Integer.toString(realscore.hashCode());
            }
            if (userscore == realscore) {

                break;
            }
            if (i == 999) {

                JOptionPane.showMessageDialog(null, "Du är lika fattig som Malcolm lol.");
                System.exit(0);
            }
        }
    }
    highscore.close();
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:13:06+00:00Added an answer on June 12, 2026 at 5:13 am

    You are not initializing your TimerTask variable tmtCheat, hence the NullPointerException.

    If you want to execute the method called tmtCheat on your Timer, you could use an anonymous class, or create one that extends TimerTask.

    timCheat.schedule(new TimerTask() {
      public void run() {
        // your code
      }
    }, 500);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried create this table, but nothing I have tried works from FKs.
I have tried to create countdown timer from database. I have sent deltaTimeServer to
I have problem that I need to create timer but I want to pass
I need to create a schedule service in android with java. I have tried
I tried create simple class which can slide a JPanel like this: +----------+ +------+---+
I'm trying to have a Timer that schedules a TimerTask for successive executions. I
I tried to create a code that adds 2 percent each time a component
I'm trying to create a table and I've tried so many times to figure
Tried to create a mobile navigation using dataview or outline and the view renders
I tried to create base controller and write in it: Ext.define('My.Users.controller.Role', { extend :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.