My Game keeps crashing

Mow I’m even more confused

The issue was the same
just in different classes

I assume this code was from a tutorial? I’d suggest scrapping it and creating something from scratch, bare bones JFrame, KeyListener, and paint() method. It’s much easier.

I just dont know how to and I expanded my code from this tutorial on my own and stopped following it

I made the pause, the menu, and im working on the audio on my own

About your pastebin: you got halfway there. You posted it, you just had to replace your code with the link to the pastebin (it gives you a public link above the code).

http://pastebin.java-gaming.org/a62da5f6a341a
Here’s the link

Now just put that in the original post and you can get rid of those 1400 lines of code.

Thank you but I still haven’t figured out my problem

Like I’ve said before, try something like this instead of this monster amount of code.

Disclaimer: I know, there’s better ways to do it.


public class Game extends KeyAdapter {

    public static void main(String[] args) {
           JFrame frame = new JFrame();
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setSize(640, 480);
           frame.setTitle("Some game");
           frame.setResizable(false);
           frame.setLocationRelativeTo(null);
           frame.setVisible(true);

           frame.addKeyListener(this);
           frame.setFocusable(true);
    }


    public void paint(Graphics g) {
    // Draw things
    }

    public void keyPressed(KeyEvent e) {
           int keyCode = e.getKeyCode();
           if (keyCode == KeyEvent.VK_[whatever]) {
           // Do something
           }
    }
}

It’ll flicker, but it’s better than where you are right now.

thanks I will tell you if it works
Im just wondering if it will stop crashes

Don’t see any errors :frowning:

except small warning but its not error because

public class Handler 
{
 ...
   public void render(Graphics g)
   {
      for( int i = 0; i < object.size(); i++ )
      {
         GameObject TempObject = object.get(i);
         //object.get(i).render(g);
         TempObject.render(g);
      }
   }

get in range size
if get out of range size its multy thread problem but i don’t think that you using many threads)
so don’t know
current code != error that you print (or multy thread error)
+
in code 2 dublicate Handlers ^^

package com.GamerC4.main;;
public class Handler 

up: lol i understand )
its realy multy thread error
1 sec

public void render(Graphics g)

is Render java AWT thread
and

public void clearEnemys()

+etc is main game thread

so you need use like this


 public void render(Graphics g)
{
	synchronized(object){
		for( int i = 0; i < object.size(); i++ )
		{
		  GameObject TempObject = object.get(i);
		  object.get(i).render(g);
		}
	}
}
public void addObject(GameObject object)
{
//and rename object to someting not so same as this.object for obj etc
	synchronized(this.object){
		  this.object.add(object);
	}
} 

+else places with object same make synchronized(object) - before any using it

I apologize but could you rephrase that

add synchronized(this.object){
before

for( int i = 0; i < object.size(); i++ )

synchronized(this.object){
this.object.remove

synchronized(this.object){
this.object.add(object);

and all other places which using this object

https://docs.oracle.com/javase/tutorial/essential/concurrency/sync.html
https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html

I have figured out the problem
It has somethign to do with the menu particle effect
It think it is causing the crashing because I am thinking back to before i had this issue

ok)
then problem not in multy threads ^^
(don’t see that Game render in run ^^)

[spoiler]current code != error ::)[/spoiler]

I think you fixed it
and I understand my mistake
Thank you so much

I don’t think that I fix it…
but who cares : its work, and that what important :wink: