INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

compiled, will not execute, it did last year

compiled, will not execute, it did last year

(OP)
I am an experienced programmer in several other languages but seem to have mixed experiences in java.  Attached is a program screen of compilation and attempted execution with an error.

This is program executed in the past but now gives me an error on 3 different systems using the same java release from before. I don't understand the message at execution time. Another similar program has the same problem.

Any suggestion?  Where & how should I get more detailed info on error messages?

Thanks in advance
From Sparks
--------------------------------------------------------------
command line:

f:\JAVA_RUN\bin>f:\JAVA_run\bin\javac.exe     f:\JAVA\Inv_rpt.java
(no error)
f:\JAVA_RUN\bin>f:\JAVA_run\bin\java.exe     f:\JAVA\Inv_rpt
Exception in thread "main" java.lang.NoClassDefFoundError: f:\JAVA\Inv_rpt

I have tried with -classpath parameter with no difference.


--------------------------------------------------------------
Program:

//********************************************************************
//  INVENTORY REPORT PROGRAM IN JAVA    Author: Prof. Morris Sparks
//
//  DEMONSTRATES THE READING OF A CHARACTER TEXT FILE
//  USING A STANDARD INPUT DATA STREAM.
//********************************************************************
//  THE INPUT DATA RECORD FORMAT IS:
//  ---------------------------------
//  part_id        from actual input columns  1- 6   start relative  0
//  part_desc      from actual input columns  7-26   start relative  6
//  unit_cost      from actual input columns 27-30   start relative 26
//  unit_sell      from actual input columns 31-34   start relative 30
//  on_hand        from actual input columns 35-38   start relative 34
//  on_order       from actual input columns 39-42   start relative 38
//  order_point    from actual input columns 43-46   start relative 42
//
//  THE OUTPUT PRINT RECORD FORMAT IS:
//  ----------------------------------
//  part_id        from input record
//  part_desc      from input record
//  on_hand        from input record
//  on_order       from input record
//  order_point    from input record
//  unit_cost      from input record
//  unit_sell      from input record
//  total_cost     from calculation on_hand * unit_cost
//  total_sell     from calculation on_hand * unit_sell
//  order_amount   from calculation order_point - (on_hand + on_order)
//                 with selection (on_hand + on_order)/order_point>.50
//  profit_ratio   from calculation unit_sell / unit_cost
//                 with selection of < 1.32
//*********************************************************************
import java.io.*;
import java.util.StringTokenizer;
import java.util.Date;
import java.text.DecimalFormat;
//import java.util.Calendar;

public class Inv_rpt
{
   //-----------------------------------------------------------------
   //  Reads data about a store inventory from an input file,
   //  creating an array of InventoryItem objects, then prints them.
   //-----------------------------------------------------------------
   public static void main (String[] args)
   {

// **********************************************
// * Define the required variables & work areas *
// **********************************************

   String          Myfile = "\\JAVA\\inv_rpt.txt";
   String          line;
   String          part_id, part_desc, unit_cost, unit_sell;
   String          on_hand, on_order, order_point;
   String          Print_work, hold;
   String          work_pad = "               ";
   int             uct, ust, oht, oot, opt, oh, oo, op;
   int             page_num = 1;
   int             work_length, work_size;
   DecimalFormat   fmt1, fmt2, fmt3, fmt4;
   float           total_cost = 0, total_sell = 0;
   float           final_cost = 0, final_sell = 0;
   float           uc, us, profit_ratio, order_amount, per_cent;
   float           work1, work2, work3, work4, work5;
   float           page_total_cost = 0, page_total_sell = 0;
   float           final_total_cost = 0, final_total_sell = 0;
   Date            current_time;

// set up hex-char strean to printer for landscape mode  - 27 38 108 49 79
// set up hex-char strean to printer from landscape mode - 27 38 108 48 79
//   byte            b1 = 27, b2 = 38, b3 = 108, b4 = 49, b5 = 79;
   byte            b1 = 0x1B, b2 = 0x26, b3 = 0x6C, b4 = 0x31, b5 = 0x4F;

   fmt1         = new DecimalFormat("####");
   fmt2         = new DecimalFormat("#0.00");
   fmt3         = new DecimalFormat("##,###,##0.00");
   fmt4         = new DecimalFormat("0.00");
   current_time = new Date();

   work_size = work_pad.length();

// **********************************************
// * DEFINE & OPEN THE INVENTORY DATA FILE.     *
// **********************************************

      try
      {
         FileReader fr = new FileReader (Myfile);
         BufferedReader inFile = new BufferedReader (fr);
         line = inFile.readLine();
// **********************************************
// * PRINT REPORT HEADINGS ON FIRST PAGE.       *
// **********************************************

//         System.out.print(b1 + b2 + b3 + b4 + b5);
         System.out.print("                                   ");
         System.out.print("      SPARKS CORP.");
         System.out.println(" ");


         System.out.print("                                   ");
         System.out.print("INVENTORY STATUS REPORT");
         System.out.println("                            PAGE " + page_num);

         System.out.print("                                ");
         System.out.print(" " + current_time);
         System.out.println(" ");

         System.out.print  ("===================================================");
         System.out.println("=============================+======================");
         System.out.print(" PART  PART                ");
         System.out.print("  ON   ON   ORDER   UNIT   UNIT");
         System.out.println("          TOTAL         TOTAL ORDER PROFIT");

         System.out.print("  NO   DESCRIPTION         ");
         System.out.print(" HAND ORDER POINT   COST   SELL");
         System.out.println("           COST          SELL POINT  RATIO");
         System.out.print  ("===================================================");
         System.out.println("==============================+=====================");

// ************************************************
// * LOOP PROCESS TO READ EACH INPUT DATA RECORD. *
// ************************************************
         while (line != null)
         {
            try
            {
              part_id     = line.substring( 0, 6);
              part_desc   = line.substring( 6,26);

              unit_cost   = line.substring(26,30);
              uct         = Integer.parseInt(unit_cost);
              work1       = uct;
              work1       = work1 / 100;

              unit_sell   = line.substring(30,34);
              ust         = Integer.parseInt(unit_sell);
              work2       = ust;
              work2       = work2 / 100;

              on_hand     = line.substring(34,38);
              oht         = Integer.parseInt(on_hand);
              work3       = oht;

              on_order    = line.substring(38,42);
              oot         = Integer.parseInt(on_order);
              work4       = oot;

              order_point = line.substring(42,46);
              opt         = Integer.parseInt(order_point);
              work5       = opt;

              total_cost       = work1 * work3;
              page_total_cost  = page_total_cost + total_cost;
              final_total_cost = final_total_cost + total_cost;

              total_sell       = work2 * work3;
              page_total_sell  = page_total_sell + total_sell;
              final_total_sell = final_total_sell + total_sell;

              final_cost  = final_cost + total_cost;
              final_sell  = final_sell + total_sell;

              order_amount = opt - (oht + oot);
              per_cent     = ((work3 + work4) * 100) / work5;

              profit_ratio = work2 / work1 ;
//*********************************************************************
              System.out.print(part_id + " ");
              System.out.print(part_desc + " ");

              Print_work = fmt1.format(oht);
              hold       = work_pad + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-5+1,work_size);
              System.out.print(Print_work + "  ");

              Print_work = fmt1.format(oot);
              hold       = work_pad + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-5+1,work_size);
              System.out.print(Print_work + "  ");

              Print_work = fmt1.format(opt);
              hold       = work_pad + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-5+1,work_size);
              System.out.print(Print_work + "  ");

              Print_work = fmt2.format(work1);
              hold       = work_pad + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-6+1,work_size);
              System.out.print(Print_work + "  ");

              Print_work = fmt2.format(work2);
              hold       = work_pad + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-6+1,work_size);
              System.out.print(Print_work + "  ");
//*********************************************************************
              Print_work = fmt3.format(total_cost);
              hold       = work_pad + "$" + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-14+1,work_size);
              System.out.print(Print_work + " ");
//*********************************************************************
              Print_work = fmt3.format(total_sell);
              hold       = work_pad + "$" + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-14+1,work_size);
              System.out.print(Print_work + "  ");
//*********************************************************************
              if (per_cent > 50.0)
                 {System.out.print("       ");}
                     else
                 {Print_work = fmt1.format(order_amount);
                  hold       = work_pad + Print_work;
                  work_size = hold.length();
                  Print_work = hold.substring(work_size-5+1,work_size);
                  System.out.print(Print_work + "  ");
                  System.out.print(" ");
                 }
//*********************************************************************
              if (profit_ratio < 1.32)
                 {System.out.print(fmt4.format(profit_ratio) + " ");}
                     else
                 {System.out.print("     ");}
//*********************************************************************
              System.out.println(" *");

            }
               catch (NumberFormatException exception)
            {
               System.out.println ("Error in input. Line ignored:");
               System.out.println (line);
            }
            line = inFile.readLine();
         }

//*********************************************************************
//  print page totals
         System.out.print("                                         ");
         System.out.print("PAGE TOTALS  =>    ");
              Print_work = fmt3.format(page_total_cost);
              hold       = work_pad + "$" + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-14+1,work_size);
              System.out.print(Print_work + " ");
              Print_work = fmt3.format(page_total_sell);
              hold       = work_pad + "$" + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-14+1,work_size);
              System.out.print(Print_work + "  ");
         System.out.println(" ");
//*********************************************************************
//  print final totals
         System.out.print("                                         ");
         System.out.print("FINAL TOTALS =>    ");
              Print_work = fmt3.format(final_total_cost);
              hold       = work_pad + "$" + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-14+1,work_size);
              System.out.print(Print_work + " ");

              Print_work = fmt3.format(final_total_sell);
              hold       = work_pad + "$" + Print_work;
              work_size = hold.length();
              Print_work = hold.substring(work_size-14+1,work_size);
              System.out.print(Print_work + "  ");
         System.out.println(" ");

         inFile.close();

      }
      catch (FileNotFoundException exception)
      {
         System.out.println ("The file " + Myfile + " was not found.");
      }
      catch (IOException exception)
      {
         System.out.println (exception);
      }
   }
}
 

Computer thought: I teach a lot of programming so I can learn. You can never learn it all.  

RE: compiled, will not execute, it did last year

I'd try

CODE

f:\JAVA>f:\JAVA_run\bin\javac.exe   Inv_rpt.java
f:\JAVA>f:\JAVA_run\bin\java.exe    Inv_rpt

Cheers,
Dian

RE: compiled, will not execute, it did last year

(OP)
To Diancecht,

I installed java in a folder JAVA_RUN so that appl programs would be in the JAVA folder.

The set up works perfectly for other programs. I have checked "case" spelling and tried different combinations of name structure. The program & naming worked earlier & now I am at a loss. The problem is I do not know what the error

f:\JAVA_RUN\bin>f:\JAVA_run\bin\java.exe     f:\JAVA\Inv_rpt
Exception in thread "main" java.lang.NoClassDefFoundError: f:\JAVA\Inv_rpt

is telling me. He finds the compiler, the class file but has problems in the execution sequence.

Sparkie

Computer thought: I teach a lot of programming so I can learn. You can never learn it all.  

RE: compiled, will not execute, it did last year

You don't need the .exe, just if there is a .bat or .com with the same name in your PATH before the exe.

For java, you call a class by its name, not by it's path. Part of its name is a package-declaration, if any. Here is none.

The class is searched for in the directories and jars of the classpath, if such is defined, and the current directory.

CODE

f:\JAVA_RUN\bin>f:\JAVA_run\bin\java -cp f:\JAVA Inv_rpt

java -help will tell you what you need. It is very brief, but very accurate in its briefness.
 

don't visit my homepage: http://home.arcor.de/hirnstrom/minis/index.html

RE: compiled, will not execute, it did last year

(OP)
To Stefanwagner & To Diancecht,

Stef & Dian your lines helped - The default folders last must have been different. I was sure that by fully qualifying each file then I would override any defaults. I was wrong - Thanks tons.

The -help wasn't much help but the rest was super.

Keep up the good work.

Sparkie

Computer thought: I teach a lot of programming so I can learn. You can never learn it all.  

RE: compiled, will not execute, it did last year

(OP)
To Stefanwagner & To Diancecht,

Please look at my other post of executing an application as an Applet.

Again thanks.

Sparkie

 

Computer thought: I teach a lot of programming so I can learn. You can never learn it all.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close