Results 1 to 4 of 4
  1. #1
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    177
    Rep Power
    2

    Angry trouble creating jar

    My .class and manifest are in my bin folder. my manifest says

    Manifest-Version: 1.0
    Created-By: Daryn
    Main-Class: walkingTurtle.class

    I created a jar using command jar cfvm turtleWalker.jar manifest.txt walkingTurtle/* walkingTurtle.class App.class
    my file walkingTurtle contains pictures.
    then when i run java -jar turtleWalker.jar I get: Error: Could not load or find main class walkingTurtle.class.
    What am i doing wrong? I always seem to have a problem creating jars. I have never been able to do it succesfully.

    I can run java walkingTurtle with no errors
    Java Code:
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    
    public class walkingTurtle extends JFrame{
    
    	public static void main(String[] args){
    		JFrame frame = new JFrame("Walking Turtle");
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(400,300);
    		App mapController = new App();
    		mapController.init();
    		frame.add(mapController);
    		frame.setVisible(true);
    	}
    }
    class App extends JApplet implements KeyListener{
    	ImageIcon backgroundImg =new ImageIcon("C:/Program Files/Java/jdk1.7.0_45/bin/walkingTurtle/background.jpg");
    	ImageIcon spriteImg = new ImageIcon("C:/Program Files/Java/jdk1.7.0_45/bin/walkingTurtle/sprite.jpg");
    	JPanel background = new JPanel();
    	JPanel sprite = new JPanel();
    	JLabel spriteLbl = new JLabel(spriteImg);
    	JLabel backgroundLbl = new JLabel(backgroundImg);
    	int[] cright=new int[7];
    	int[] cleft=new int[7];
    	int[] ctop= new int[7];
    	int[] cbottom=new int[7];
    	int x=0,y=0,backgroundSizeX=639,backgroundSizeY=507;
    	int spriteX=176,spriteY=212,spriteWidth=44,spriteHeight=34;
    	boolean collision=false;
    	public void init(){
    		cleft[0]=0;
    		cright[0]=184;
    		cleft[1]=83;
    		cright[1]=638;
    		cleft[2]=591;
    		cright[2]=638;
    		cleft[3]=261;
    		cright[3]=507;
    		cleft[4]=0;
    		cright[4]=168;
    		cleft[5]=402;
    		cright[5]=591;
    		cleft[6]=141;
    		cright[6]=478;
    		ctop[0]=0;
    		cbottom[0]=160;
    		ctop[1]=0;
    		cbottom[1]=63;
    		ctop[2]=63;
    		cbottom[2]=510;
    		ctop[3]=135;
    		cbottom[3]=308;
    		ctop[4]=231;
    		cbottom[4]=429;
    		ctop[5]=377;
    		cbottom[5]=545;
    		ctop[6]=504;
    		cbottom[6]=510;
    		setFocusable(true);
    	    addKeyListener(this);
    		setLayout(null);
    		background.setBounds(x,y,backgroundSizeX,backgroundSizeY);
    		sprite.setBounds(spriteX,spriteY,spriteWidth,spriteHeight);
    		background.add(backgroundLbl);
    		sprite.add(spriteLbl);
    		this.add(sprite);
    		this.add(background);
    	}
    	public boolean collisionLeft(){
    		for(int i=0;i<7;i++){
    			if(spriteX==cright[i]+x&&spriteY+spriteHeight<=cbottom[i]+y&&spriteY+spriteHeight>=ctop[i]+y||spriteX==cright[i]+x&&spriteY>=ctop[i]+y&&spriteY<=cbottom[i]+y){
    				 System.out.println(i);
    				 return true;
    			}
    		}
    		return false;
    	}
    	public boolean collisionRight(){
    		for(int i=0;i<7;i++){
    			if(spriteX+spriteWidth==cleft[i]+x&&spriteY+spriteHeight<=cbottom[i]+y&&spriteY+spriteHeight>=ctop[i]+y||spriteX+spriteWidth==cleft[i]+x&&spriteY>=ctop[i]+y&&spriteY<=cbottom[i]+y){
    				 System.out.println(i);
    				 return true;
    			}
    		}
    		return false;
    	}
    	public boolean collisionTop(){
    		for(int i=0;i<7;i++){
    			if(spriteY==cbottom[i]+y&&spriteX+spriteWidth<=cright[i]+x&&spriteX+spriteWidth>=cleft[i]+x||spriteY==cbottom[i]+y&&spriteX<=cright[i]+x&&spriteX>=cleft[i]+x){
    				 System.out.println(i);
    				 return true;
    			}
    		}
    		return false;
    	}
    	public boolean collisionBottom(){
    		for(int i=0;i<7;i++){
    			if(spriteY+spriteHeight==ctop[i]+y&&spriteX+spriteWidth<=cright[i]+x&&spriteX+spriteWidth>=cleft[i]+x||spriteY+spriteHeight==ctop[i]+y&&spriteX>=cleft[i]+x&&spriteX<=cright[i]+x){
    				 System.out.println(i);
    				 return true;
    			}
    		}
    		return false;
    	}
        public void keyPressed(KeyEvent e){
    			if(e.getKeyCode()==KeyEvent.VK_RIGHT){
    				if(collisionRight()==false){
    					x--;
    					System.out.println("X: "+x);
    					background.setBounds(x,y,backgroundSizeX,backgroundSizeY);
    					this.add(background);
    				}
    			}
    			else if(e.getKeyCode()==KeyEvent.VK_LEFT){
    				if(collisionLeft()==false){
    					x++;
    					background.setBounds(x,y,backgroundSizeX,backgroundSizeY);
    					this.add(background);
    				}
    			}
    			else if(e.getKeyCode()==KeyEvent.VK_UP){
    				if(collisionTop()==false){
    					System.out.println("Y: "+x);
    					y++;
    					background.setBounds(x,y,backgroundSizeX,backgroundSizeY);
    					this.add(background);
    				}
    			}
    			else if(e.getKeyCode()==KeyEvent.VK_DOWN){
    				if(collisionBottom()==false){
    					System.out.println("Y: "+x);
    					y--;
    					background.setBounds(x,y,backgroundSizeX,backgroundSizeY);
    					this.add(background);
    				}
    			}
    
    	}	
    	public void keyReleased(KeyEvent e){
    	}
    	public void keyTyped(KeyEvent e){
    	}
    
    
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: trouble creating jar

    You don't need the .class part when specifying the main class. You just need the class name (include package information if your main class is inside a package).
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    177
    Rep Power
    2

    Default Re: trouble creating jar

    Its not in a package though
    With the right know how, anything is possible

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: trouble creating jar

    Quote Originally Posted by Daryn View Post
    Its not in a package though
    That's why I said "if". You still don't need the .class part.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 1
    Last Post: 03-05-2013, 04:39 PM
  2. Replies: 17
    Last Post: 03-28-2012, 08:29 AM
  3. trouble creating stack using array
    By shashankc in forum New To Java
    Replies: 5
    Last Post: 01-20-2011, 12:49 PM
  4. Trouble creating object that includes array
    By Desdenova in forum New To Java
    Replies: 7
    Last Post: 05-18-2010, 07:33 PM
  5. Trouble with creating TreeSet
    By MrKP in forum New To Java
    Replies: 1
    Last Post: 12-27-2009, 02:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •