为什么不运行?

时间:2013-11-27 16:03:16

标签: java arraylist

这是我的大学任务,这是一个mp3目录。但我不知道它为什么不运行。错误是main方法中存在错误。有人可以帮忙吗?如果有人能告诉我如何在他的目录中添加“重新订购”功能,我们将不胜感激。非常感谢

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;

public class mp3catalogue
{
    // An ArrayList for storing the file names of music files.
    private ArrayList<String> tracks;
    //public mp3catalogue();
    public static void main(String[] args) {
    }

    {
        tracks = new ArrayList<String>();
        Random randomtrack = new Random();
        System.out.println("Music library loaded.");
        System.out.println();
    }

    //Next: File number to be added
    public void addNumber(int filename){
        int x = 0;
    }

    {
        Scanner in = new Scanner (System.in);
        System.out.print("Number of track?");
        int x;
        int number = x;
        while (number <= 1);
        String number1 = in.nextLine();
    }

    //Next: File name to be added
    public void addFile(String filename)
    {
        tracks.add(filename);
        Scanner in = new Scanner(System.in);
        System.out.print("Name of the track?");
        String name = in.nextLine();
    }

    //Next: Artist to be added
    public void addArtist(String filename){
        Scanner in1 = new Scanner(System.in);
        System.out.print("Track artist?");
        Scanner in;
        String name1 = in.nextLine();
    }

    //Next: Duration to be added
    public void addDuration(double filename)
    {
        Scanner in = new Scanner (System.in);
        System.out.println("Track duration?");
        String name = in.nextLine();
    }

    // Next: Deleting a track
    public void removeFile(int index)
    {
        if(index >= 0 && index < tracks.size()) {
            tracks.remove(index);}
    }

    // Next: Shuffle the tracks.
    public void randomAllTracks(int index)
    {
        int trackNumber = getNumberOfFiles();
        int index1 = Random.nextInt(trackNumber);
        if(indexValid(index1)) 
        {
        }
    }

    // Next: Search for a track.
    public static int binarySearch (int[] list, int listlength, int searchItem){
        int first = 0;
        int last = listlength - 1;
        int mid;
        boolean found = false;
        while (first <= last &&!found){
        }
        return searchItem;
    }

    private int getNumberOfFiles() {
        return 0;
    }

    private boolean indexValid(int index) {
        return false;
    }
}

2 个答案:

答案 0 :(得分:2)

因为,你没有在main方法中调用任何东西。

答案 1 :(得分:1)

您的主要方法是空的。该块仅在下一行关闭。

public static void main(String[] args) {
}

{
tracks = new ArrayList<String>();
Random randomtrack = new Random();
System.out.println("Music library loaded.");
System.out.println();
}

我认为,应该删除花括号?

接下来,我的日食会抛出错误,接下来就是:

while (number <= 1);

这是一个无限循环。

并且有很多空块,这是非常完整的代码吗?