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 8956533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:48:29+00:00 2026-06-15T14:48:29+00:00

My code is this: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Font; import java.awt.Graphics;

  • 0

My code is this:

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.Font;
 import java.awt.Graphics;
 import java.net.URL;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 import java.io.*;
 import javax.swing.Timer;

 public class chromeNPlayerScreen extends JFrame implements ActionListener{
   DrawScreen dPnl = new DrawScreen(); 
   public void actionPerformed(ActionEvent e){
   }
   public void main(String[ ] args){
     this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     this.add(dPnl);
     this.setSize(600,600);;
     this.setVisible(true);
     this.setResizable(false);
     this.setLocation(200, 200);
   }  
 }

But when i run it…..

 java.lang.NullPointerException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

Could someone explain to me why this isnt working?

the DrawScreen code is

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font;
import java.awt.Graphics;
import java.net.URL;

public class DrawScreen extends JPanel {
  String picPath = "pictures/";
  ClassLoader cl = pokemonChromeNewPlayerScreen.class.getClassLoader();
  URL imgURL = cl.getResource(picPath+"welcomeBG.png"),imgURL2 = cl.getResource(picPath+"dialogBox.png"),
    imgURL3 = cl.getResource(picPath+"Professor.png");
  Toolkit tk = Toolkit.getDefaultToolkit();
  Image imgBG, imgDialog, imgProfessor;

  public void imgImport(){
    imgBG = tk.createImage(imgURL);
    imgDialog = tk.createImage(imgURL2);
    imgProfessor = tk.createImage(imgURL3);
  }
  public void paintComponent(Graphics g) {
      g.setColor(Color.BLACK);
      Graphics2D g2 = (Graphics2D)g;
      for(int x=0;x<=600;x+=25){
        g2.drawLine(x,0,x,600);
        g2.drawString(""+x,x+5,20);
      }
      for(int y=0;y<=600;y+=25){
        g2.drawLine(0,y,600,y);
        g2.drawString(" "+y,0,y+20);
      }
  }
}

This is the code for the DrawScreen, atm all it does it drag a grid but thats because i just started it and wanted the x,y values for different positions

  • 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-15T14:48:31+00:00Added an answer on June 15, 2026 at 2:48 pm

    I’m assuming this is something related to your IDE. Specifically, it’s looking for a non-static version of main().

    This:

    public void main(String[ ] args){
    
    }  
    

    Should actually be:

    public static void main(String[ ] args){
    
    }  
    

    … of course, this means the this reference no longer works – you’ll need to actually create a chromeNPlayerScreen first:

    public static void main(String[ ] args){
       chromeNPlayerScreen screen = new chromeNPlayerScreen();
       screen.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
       screen.add(dPnl);
       screen.setSize(600,600);;
       screen.setVisible(true);
       screen.setResizable(false);
       screen.setLocation(200, 200);
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple JComboBox filter code like this : import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent;
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
import javax.swing.*; // For JPanel, etc. import java.awt.*; // For Graphics, etc. import java.awt.geom.*;
Mostly everything is perfect with this code. import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import
in most code examples I see people doing this. import javax.swing.*; // for the
so I have some code that looks like this: import java.awt.BorderLayout; import java.awt.Component; import
When I run this code: import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import
This is my code: package hello.project; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLSurfaceView.Renderer;
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
This code compiles: import java.io.Serializable; import java.util.Arrays; class Test<T extends Arrays & Serializable> {

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.