printing arrays in java: a quick note

  • From: "Michael Malver" <mmalver@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 22 Mar 2011 15:30:33 -0500

Are you familiar with java's for each construct:
Syntax is
For (type <var> : array)
System.out.print(var)

Note: This syntax only works for reading through arrays, and other
containers, but it is easy to code, and doesn't require you to know the
length of the array or container.


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Littlefield,
Tyler
Sent: Tuesday, March 22, 2011 3:21 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: java jar file/manifest question

Hello all:
After the last discussion, I started tearing pieces out of the design 
and making them into their own objects, the biggest being the board 
object. So far I have a bit of code that initializes and shows the board 
on screen, as well as a build script to make this into a jar file.
I want to be able to learn to package this because eventually I'd like 
to be able to distribute a program. Here is the code, I've just written 
#file where file is the file name.
#Board.java
public class Board
{
private String[] board;
public Board()
{
int i;
board = new String[9];
for (i = 0; i < 9; i++)
{
board[i] = " ";
}
}
public void printBoard()
{
int i,j;
System.out.println("|-|-|-|");
for (i = 0; i < 3; i++)
{
System.out.print("|");
for (j = 0; j < 3; j++)
{
System.out.print(board[i]+"|");
}
System.out.println("\n|-|-|-|");
}
}
#ttt.java
public class ttt
{
public static void main(String[] args)
{
Board b = new Board();
b.printBoard();
}
}

}
#ttt.manifest
Main-Class: ttt

#build.bat
@echo off
echo compiling:
javac ttt.java Board.java
echo "packaging:
jar cmf ttt.manifest ttt.jar ttt.class Board.class
echo removing unwanted files:
del /q ttt.class
del /q Board.class
when I run with:
java ttt
I get:
Exception in thread "main" java.lang.NoClassDefFoundError: ttt
Caused by: java.lang.ClassNotFoundException: ttt
         at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: ttt.  Program will exit.
Help here is appreciated, I'm baffled why it fails when that class is 
clearly defined.

-- 

Thanks,
Ty

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: