2017-08-08 10 views
0

コマンドラインから同じパッケージのクラスを実行する方法を探していますが、コンパイルに成功しても " "エラー。私はパスとクラスパスを自分が必要とするものに変更しただけでなく、私が使っているパッケージ( "com.company")という名前のサブフォルダを作成しようとしましたが、役に立たなかった。 コマンドラインからJavaパッケージを使用する - メインを見つけることができないまたはロードすることができない

>java com.company.myclassname 
>java myclassname 
>java com\company\myclassname 
>java -cp . com.company.myclassname 

すべて

が同じ「エラーで私を残しています:それ以上のパッケージという名前のサブフォルダのディレクトリだけでなく、フォルダ内にいる間、私は、コマンドラインで、次の試してみた見つけるか、メインクラスをロードできませんでした。 "

この時点で、私は繰り返し質問するのを避けるために、StackOverflowの質問とチュートリアルを3時間にわたって熟視してきましたが、私は絶望的です。私はこの宿題を2時間以内にする必要があります。それは私のIDEの中でうまく動作し、私のバックアップベータIDEでもコマンドラインではなくても動作します。誰も私のためにこれにいくつかの光を発することができますか?

編集:ソースコード:

package com.company; 

import static com.company.myclassname.quantInput; 
import static com.company.myclassname.costInput; 

public class GroceryList {//This is the parent class for the program. 
private static int counter = 0;//Used to ensure that the number of items is limited to ten. 
private static GroceryList[] List = new GroceryList[10];//Used to hold the first ten grocery items in the add method. 


public GroceryList(){//Basic constructor 
} 

....プラスいくつかのメソッド。

クライアントコード:

package com.company; 

import java.io.File; 
import java.io.FileNotFoundException; 
import java.text.DecimalFormat; 
import java.util.Scanner; 

public class myclassname { 

private static String[] nameInput = new String[10];//for holding names from each line, then gets sent to constructor by index 
public static int[] quantInput = new int[10];//for holding quantity from each line, then gets sent to constructor by index 
public static double[] costInput = new double[10];//for holding price from each line, then gets sent to constructor by index 
public static GroceryItemOrder[] GIOList = new GroceryItemOrder[10];//for holding GroceryItemOrder objects, then gets sent to toString() for printing 
public static double TotalCost = 0;//initializes total cost variable 
public static DecimalFormat f = new DecimalFormat("#####0.00");//Ensures proper output format for doubles 
private static int counter;//Used for indexing 
private static String target;//File path 

public static void main(String[] args) throws FileNotFoundException, NullPointerException { 
    target = args[0];//User-supplied file path is assigned to variable "target" 
    try {//protects against NullPointerException 
     input();//Sends file path to input method, which sends that data to all other relevant methods and classes 
     System.out.printf("%-20s", "Item");//These lines provide headers for output message 
     System.out.printf("%-10s", "Quantity"); 
     System.out.printf("%-10s", "Price"); 
     System.out.printf("%-12s", "Total Price"); 
     System.out.println(); 
     for (int i = 0; i < counter; i++) {//Ensures only correct objects are printed to user 
      System.out.println(GIOList[i].toString());//public object array sends data to the toString() method, which 
      //then prints formatted output string, limited by counter in order to ensure only proper data prints 
     }if (counter<10){//If the file contains under 11 items, this prints to the user 
     System.out.println("Total cost: $" + f.format(TotalCost));} 
     else{//if the file contains 11 or more lines, this statement makes clear that only the first 10 items 
      //will be included in the total cost. 
      System.out.println("Total cost of the first ten items in your file: $" + f.format(TotalCost)); 
     } 
    } catch (NullPointerException e){//safeguard against printing null strings to user 
    } 
} 

プラス入力方法

+0

あなたは 'JavaのCOMを実行しています。 company.myclassname'は 'com'の親ディレクトリからですか?あなたのIDEはおそらく、使用されたjavaコマンドを印刷するべきであり、参照として使用することができます。また、 'com.company.myclassname'クラスが' public static void main(String [] args) 'メソッドを持っていることを確認してください。 – Beginner

+0

'myclassname.java'のソースコードを投稿してください。最も重要なことは、そのファイルにパッケージ名を表示し、そのJavaファイルを格納するためにどこのディレクトリ構造を使用しているかを教えてください。ほとんどの場合、ちょっとした間違いがあります。 –

+0

私はディレクトリツリーを上下にしてきました。親フォルダは違いはありません。 – CodeBlue04

答えて

-1

このクイック回避策を試してみてください。

フォルダ階層com \ companyまたはcom/companyを作成します(OSによって異なります)。

myclassname.classファイルをcom \ companyフォルダ内に配置します。 (COMフォルダと同じレベルにある)トップレベルのフォルダから

Javaのcom.company.myclassnameを実行

よろしく、 ラヴィ

+0

運がありません。デフォルトのフォルダにはcom/company階層があり、パッケージ名を使ってサブフォルダを構築しようとする前に、その両方を試してみました。私は同じ結果でもう一度試しました。 – CodeBlue04

+0

それは私のために働く。 –

+0

私の教授のためにうまくいけばうれしいです。答えをありがとう!たとえそれが私のために働かないとしても、それが彼のために働くならば、それはすべて重要です。 – CodeBlue04

関連する問題