Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: [Problem] What's wrong with my code

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [Problem] What's wrong with my code

    I'm doing the modification of MOSS operating system simulator for scheduling part. I add a class for creating threads and display the thread name and priority. When i want to run the code it comes out the error" Exception occurred executing command line.
    Cannot run program "C:\Program Files\Java\jre6\bin\javaw.exe" (in directory "C:\Users\Sing\workspace\Moss"): CreateProcess error=740, The requested operation requires elevation"

    Code:
    package sched;
     
    // This file contains the main() function for the Scheduling
    // simulation.  Init() initializes most of the variables by
    // reading from a provided file.  SchedulingAlgorithm.Run() is
    // called from main() to run the simulation.  Summary-Results
    // is where the summary results are written, and Summary-Processes
    // is where the process scheduling summary is written.
     
    // Created by Alexander Reeder, 2001 January 06
     
    import java.io.*;
    import java.util.*;
    import java.lang.*;
     
    public class Scheduling {
     
      private static int processnum = 5;
      private static int meanDev = 1000;
      private static int standardDev = 100;
      private static int runtime = 1000;
      private static Vector processVector = new Vector();
      private static Results result = new Results("null","null",0);
      private static String resultsFile = "Summary-Results";
     
     
      private static void Init(String file) {
        File f = new File(file);
        String line;
        String tmp;
        int cputime = 0;
        int ioblocking = 0;
        double X = 0.0;
     
        try {   
          //BufferedReader in = new BufferedReader(new FileReader(f));
          DataInputStream in = new DataInputStream(new FileInputStream(f));
          while ((line = in.readLine()) != null) {
            if (line.startsWith("numprocess")) {
              StringTokenizer st = new StringTokenizer(line);
              st.nextToken();
              processnum = Common.s2i(st.nextToken());
            }
            if (line.startsWith("meandev")) {
              StringTokenizer st = new StringTokenizer(line);
              st.nextToken();
              meanDev = Common.s2i(st.nextToken());
            }
            if (line.startsWith("standdev")) {
              StringTokenizer st = new StringTokenizer(line);
              st.nextToken();
              standardDev = Common.s2i(st.nextToken());
            }
            if (line.startsWith("process")) {
              StringTokenizer st = new StringTokenizer(line);
              st.nextToken();
              ioblocking = Common.s2i(st.nextToken());
              X = Common.R1();
              while (X == -1.0) {
                X = Common.R1();
              }
              X = X * standardDev;
              cputime = (int) X + meanDev;
              processVector.addElement(new sProcess(cputime, ioblocking, 0, 0, 0));          
            }
            if (line.startsWith("runtime")) {
              StringTokenizer st = new StringTokenizer(line);
              st.nextToken();
              runtime = Common.s2i(st.nextToken());
            }
          }
          in.close();
        } catch (IOException e) { /* Handle exceptions */ }
      }
     
      private static void debug() {
        int i = 0;
     
        System.out.println("processnum " + processnum);
        System.out.println("meandevm " + meanDev);
        System.out.println("standdev " + standardDev);
        int size = processVector.size();
        for (i = 0; i < size; i++) {
          sProcess process = (sProcess) processVector.elementAt(i);
          System.out.println("process " + i + " " + process.cputime + " " + process.ioblocking + " " + process.cpudone + " " + process.numblocked);
        }
        System.out.println("runtime " + runtime);
      }
     
    (Begining of the part i modify)
      public static class StartThread extends Thread
      {
    	  Thread t;
    	  public void startThread()
    	  {
    		  System.out.println("Starting the child thread");
    		  start();
    	  }
     
    public void run()
      {
    	  t = Thread.currentThread();
    	  System.out.println(Thread.currentThread());
    	  System.out.println("Name of the thread is:" + t.getName());
    	  System.out.println("Priority of the thread is:" + t.getPriority());
    	  System.out.println("The current thread is alive:" + t.isAlive());
    	  t.setName("First");
    	  t.setPriority(10);
    	  //After change thread name and priority
    	  System.out.println("Thread name after changed:" + t.getName());
    	  System.out.println("Thread priority after changed:" + t.getPriority());
    	  t.stop();
    	  System.out.println("Thread alive status:" + t.isAlive());
     
      }
      static class DisplayThread extends Thread
      {
      public static void main(String args[]) {
    	  StartThread ob = new StartThread();
    	  System.out.println("Main thread name:" + Thread.currentThread().getName());
    	  ob.startThread();
    	  Thread maint = Thread.currentThread();
    	  System.out.println("Thread alive status:" + maint.isAlive());
    	  System.out.println(System.getProperty("user.dir"));
     
    (End of the part i modify)
        int i = 0;
     
        if (args.length != 1) {
          System.out.println("Usage: 'java Scheduling <INIT FILE>'");
          System.exit(-1);
        }
        File f = new File(args[0]);
        if (!(f.exists())) {
          System.out.println("Scheduling: error, file '" + f.getName() + "' does not exist.");
          System.exit(-1);
        }  
        if (!(f.canRead())) {
          System.out.println("Scheduling: error, read of " + f.getName() + " failed.");
          System.exit(-1);
        }
        System.out.println("Working...");
        Init(args[0]);
        if (processVector.size() < processnum) {
          i = 0;
          while (processVector.size() < processnum) {       
              double X = Common.R1();
              while (X == -1.0) {
                X = Common.R1();
              }
              X = X * standardDev;
            int cputime = (int) X + meanDev;
            processVector.addElement(new sProcess(cputime,i*100,0,0,0));          
            i++;
          }
        }
        result = SchedulingAlgorithm.Run(runtime, processVector, result);    
        try {
          //BufferedWriter out = new BufferedWriter(new FileWriter(resultsFile));
          PrintStream out = new PrintStream(new FileOutputStream(resultsFile));
          out.println("Scheduling Type: " + result.schedulingType);
          out.println("Scheduling Name: " + result.schedulingName);
          out.println("Simulation Run Time: " + result.compuTime);
          out.println("Mean: " + meanDev);
          out.println("Standard Deviation: " + standardDev);
          out.println("Process #\tCPU Time\tIO Blocking\tCPU Completed\tCPU Blocked");
          for (i = 0; i < processVector.size(); i++) {
            sProcess process = (sProcess) processVector.elementAt(i);
            out.print(Integer.toString(i));
            if (i < 100) { out.print("\t\t"); } else { out.print("\t"); }
            out.print(Integer.toString(process.cputime));
            if (process.cputime < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); }
            out.print(Integer.toString(process.ioblocking));
            if (process.ioblocking < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); }
            out.print(Integer.toString(process.cpudone));
            if (process.cpudone < 100) { out.print(" (ms)\t\t"); } else { out.print(" (ms)\t"); }
            out.println(process.numblocked + " times");
          }
          out.close();
        } catch (IOException e) { /* Handle exceptions */ }
      System.out.println("Completed.");
      }
    }
      }
     
    }
    [#][/#]

    Is there something wrong in the code?


  2. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [Problem] What's wrong with my code

    Ok. I have fix the error. But i still cant run the thing as it gives me the error message of "java.lang.NoSuchMethodError: main
    Exception in thread "main" . I have the main method, but why i still receiving such error?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: [Problem] What's wrong with my code

    I have the main method
    Where is the main() method in the code you posted?

    How are you trying to execute the posted code?

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [Problem] What's wrong with my code

    look carefully, there is a main method there

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: [Problem] What's wrong with my code

    Quote Originally Posted by Javanoo89 View Post
    Ok. I have fix the error. But i still cant run the thing as it gives me the error message of "java.lang.NoSuchMethodError: main
    Exception in thread "main" . I have the main method, but why i still receiving such error?
    Most probably you are trying to run the other class which doesn't have main().

Similar Threads

  1. what is wrong with my code?
    By bmb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 7th, 2011, 09:03 AM
  2. what's wrong with this code
    By gcsekhar in forum Java Networking
    Replies: 5
    Last Post: July 21st, 2011, 06:01 AM
  3. what's wrong with my code
    By gcsekhar in forum Java Networking
    Replies: 2
    Last Post: July 19th, 2011, 09:31 AM
  4. What's wrong with my code?
    By lindmando in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 7th, 2011, 11:13 PM
  5. What's wrong with my code
    By javapenguin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 10th, 2010, 03:24 PM