2017-05-29 7 views
1

メソッドの名前が重複していないことを確認しましたが、問題を検索しようとしましたが、出力が何か類似していると言っても、みんなの問題は私と比べて違うようです。タイプ "mp3_organizer"に "rf"という名前のメソッドのオーバーロードがありません

コード:

import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileReader; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.InputStreamReader; 



/** 
* 
* C:\Users\Red\Music\Alan Walker - Hope.mp3 
*/ 

public class mp3_organizer 
{ 

static BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); 
static final int max = 50; 
static final String file = "songlist.txt"; 

//rf stands for readfile 
public static void rf (String[] songname, String[] songpath, String[] artist, String[] genre, int[] count, String file) throws FileNotFoundException, IOException 
{ 
    BufferedReader reader = new BufferedReader (new FileReader (file)); 

    String temp, line = null; 

    while ((line = reader.readLine()) != null) 
    { 
     songname [count [0]] = line; 
     songpath [count [0]] = reader.readLine(); 
     artist [count [0]] = reader.readLine(); 
     genre [count [0]] = reader.readLine(); 
     count [0]++; 
    } 


    reader.close(); 
} 


public static void newsong (String file) throws IOException 
{ 
    BufferedWriter writer = new BufferedWriter (new FileWriter (file, true)); 
    System.out.println ("[ADDING songS] \n"); 
    System.out.println ("Enter the name of the song"); 
    String name = stdin.readLine(); 
    System.out.println ("Enter a file address of song"); 
    String filePath = stdin.readLine(); 
    System.out.println ("Enter the artist's name or put N/A if unknown"); 
    String songArtist = stdin.readLine(); 
    System.out.println ("Enter the genre"); 
    String songGenre = stdin.readLine(); 

    writer.write (""); 
    writer.newLine(); 
    writer.write (name); 
    writer.newLine(); 
    writer.write (filePath); 
    writer.newLine(); 
    writer.write (songArtist); 
    writer.newLine(); 
    writer.write (songGenre); 
    writer.newLine(); 
    writer.close(); 
} 


static void sort (String[] songname, String[] artist, String[] genre, int count) throws IOException 
{ 
    BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); 
    boolean swapped = false; 
    String temp; 
    int select; 

    System.out.println ("What would you like to sort the database by?\n(1) song Title\n(2) Artist \n(3) Genre"); 
    do 
    { 
     select = Integer.parseInt (stdin.readLine()); 
     switch (select) 
     { 
      case 1: 
       for (int i = 0 ; i < (count - 1) ; i++) 
       { 
        swapped = false; 
        for (int j = 0 ; j < ((count - 1) - i) ; j++) 
        { 
         if (songname [j].compareTo (songname [j + 1]) > 0) 
         { 
          temp = songname [j]; 
          songname [j] = songname [j + 1]; 
          songname [j + 1] = temp; 

          temp = artist [j]; 
          artist [j] = artist [j + 1]; 
          artist [j + 1] = temp; 

          temp = genre [j]; 
          genre [j] = genre [j + 1]; 
          genre [j + 1] = temp; 
          swapped = true; 
         } 
        } 
        if (!swapped) 
        { 
         i = count; 
        } 
       } 
       break; 
      case 2: 
       for (int i = 0 ; i < (count - 1) ; i++) 
       { 
        swapped = false; 
        for (int j = 0 ; j < ((count - 1) - i) ; j++) 
        { 
         if (artist [j].compareTo (artist [j + 1]) > 0) 
         { 
          temp = songname [j]; 
          songname [j] = songname [j + 1]; 
          songname [j + 1] = temp; 

          temp = artist [j]; 
          artist [j] = artist [j + 1]; 
          artist [j + 1] = temp; 

          temp = genre [j]; 
          genre [j] = genre [j + 1]; 
          genre [j + 1] = temp; 
          swapped = true; 
         } 
        } 
        if (!swapped) 
        { 
         i = count; 
        } 
       } 
       break; 
      case 3: 
       for (int i = 0 ; i < (count - 1) ; i++) 
       { 
        swapped = false; 
        for (int j = 0 ; j < ((count - 1) - i) ; j++) 
        { 
         if (genre [j].compareTo (genre [j + 1]) > 0) 
         { 
          temp = songname [j]; 
          songname [j] = songname [j + 1]; 
          songname [j + 1] = temp; 

          temp = artist [j]; 
          artist [j] = artist [j + 1]; 
          artist [j + 1] = temp; 

          temp = genre [j]; 
          genre [j] = genre [j + 1]; 
          genre [j + 1] = temp; 
          swapped = true; 
         } 
        } 
        if (!swapped) 
        { 
         i = count; 
        } 
       } 
       break; 
      default: 
       System.out.print ("\nPlease enter a valid option: "); 
       break; 
     } 
    } 
    while (select != 1 && select != 2 && select != 3); 
} 



static void search (String[] songname, String[] songpath, String[] artist, String[] genre, int count) throws IOException 
{ 
    BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); 
    String search; 
    boolean find = false; 
    int select; 

    System.out.println ("Please select what category you wish to search by:\n(1) song\n(2) Artist\n(3) Genre\n(4) Song Path\n(0) Cancel"); 
    do 
    { 
     select = Integer.parseInt (stdin.readLine()); 

     switch (select) 
     { 
      case 1: 
       System.out.print ("Please enter the name of the song to search for: "); 
       search = stdin.readLine(); 
       for (int i = 0 ; i < count ; i++) 
       { 
        if (songname [i].equalsIgnoreCase (search)) 
        { 
         find = true; 
        } 
       } 
       if (find) 
       { 
        System.out.println ("song\tsong\tArtist\tGenre"); 
        for (int i = 0 ; i < count ; i++) 
        { 
         if (songname [i].equalsIgnoreCase (search)) 
         { 
          System.out.println (songname [i] + "\t" + songpath [i] + "\n" + artist [i] + "\t" + genre [i]); 
         } 
        } 
       } 
       else 
       { 
        System.out.println (search + " not found."); 
       } 
       break; 

      case 2: 
       System.out.print ("Please enter the name of the artist to search for: "); 
       search = stdin.readLine(); 
       for (int i = 0 ; i < count ; i++) 
       { 
        if (artist [i].equalsIgnoreCase (search)) 
        { 
         find = true; 
        } 
       } 
       if (find) 
       { 
        System.out.println ("song\tsongpath\tArtist\tGenre"); 
        for (int i = 0 ; i < count ; i++) 
        { 
         if (artist [i].equalsIgnoreCase (search)) 
         { 
          System.out.println (songname [i] + "\t" + songpath [i] + "\n" + artist [i] + "\t" + genre [i]); 
         } 
        } 
       } 
       else 
       { 
        System.out.println ("Artist not found"); 
       } 
       break; 

      case 3: 
       System.out.print ("Please enter the genre to search for: "); 
       search = stdin.readLine(); 
       for (int i = 0 ; i < count ; i++) 
       { 
        if (genre [i].equalsIgnoreCase (search)) 
        { 
         find = true; 
        } 
       } 
       if (find) 
       { 
        System.out.println ("song\tsongpath\tArtist\tGenre"); 
        for (int i = 0 ; i < count ; i++) 
        { 
         if (genre [i].equalsIgnoreCase (search)) 
         { 
          System.out.println (songname [i] + "\t" + songpath [i] + "\n" + artist [i] + "\t" + genre [i]); 
         } 
        } 
       } 
       else 
       { 
        System.out.println (search + " cannot be found."); 
       } 
       break; 

      case 4: 
       System.out.print ("Please enter the file address of the song to search for: "); 
       search = stdin.readLine(); 
       for (int i = 0 ; i < count ; i++) 
       { 
        if (songname [i].equalsIgnoreCase (search)) 
        { 
         find = true; 
        } 
       } 
       if (find) 
       { 
        System.out.println ("song\tsongpath\tArtist\tGenre"); 
        for (int i = 0 ; i < count ; i++) 
        { 
         if (songname [i].equalsIgnoreCase (search)) 
         { 
          System.out.println (songname [i] + "\t" + songpath [i] + "\n" + artist [i] + "\t" + genre [i]); 
         } 
        } 
       } 
       else 
       { 
        System.out.println ("File address not found."); 
       } 
       break; 

      case 0: 
       break; 

      default: 
       System.out.println ("Please enter a valid option: "); 
     } 
    } 


    while (select > 3); 
    System.out.println(); 
} 


public static void backup (String file, int count, String[] songname, String[] songpath, String[] artist, String[] genre) throws IOException 
{ 
    BufferedWriter writer = new BufferedWriter (new FileWriter ("backup.txt")); 
    for (int i = 0 ; i < count ; i++) 
    { 
     writer.write (songname [i]); 
     writer.newLine(); 
     writer.write (songpath [i]); 
     writer.newLine(); 
     writer.write (artist [i]); 
     writer.newLine(); 
     writer.write (genre [i]); 
     writer.newLine(); 
    } 


    writer.close(); 
} 


public static void printlist (int count, String[] songname, String[] songpath, String[] artist, String[] genre) 
{ 
    for (int i = 0 ; i < count ; i++) 
    { 
     System.out.println (songname [i] + "\n" + songpath [i] + "\n" + artist [i] + "\n" + genre [i]); 
    } 
} 


public static void test() 
{ 
    File songlist = new File ("songlist.txt"); 

    System.out.println (System.getProperty ("user.dir")); 

    if (songlist.exists()) 
    { 
     if (songlist.canRead()) 
     { 
      System.out.print ("file can be read"); 
     } 

     else 
     { 
      System.out.print ("File cannot be read"); 
     } 
    } 


    else 
    { 
     System.out.println ("file does not exist"); 
    } 
} 


public static void main (String str[]) throws FileNotFoundException, IOException 
{ 
    boolean reset = true; 

    test(); 

    do 
    { 

     int count = 0; 
     String[] songname = new String [max]; 
     String[] songpath = new String [max]; 
     String[] artist = new String [max]; 
     String[] genre = new String [max]; 

     rf (songname, songpath, artist, genre, count, file); 

     BufferedReader reader = new BufferedReader (new FileReader ("songlist.txt")); 
     System.out.println ("[OPTIONS] \n" + 
       "1) Print the song list \n" + 
       "2) Add a song to list \n" + 
       "3) Search for a song \n" + 
       "4) Sort the song list \n" + 
       "5) Create a backup of the song lsit \n" + 
       "6) Delete a song from the collection \n" + 
       "7) Create a new profile"); 

     System.out.println ("Enter a option"); 
     int choice = Integer.parseInt (stdin.readLine()); 

     switch (choice) 
     { 
      case 1: 
       System.out.println ("[PRINTING song LIST] \n"); 
       printlist (count, songname, songpath, artist, genre); 
       break; 

      case 2: 
       System.out.println ("[ADDING SONG]"); 
       newsong (file); 
       break; 

      case 3: 
       System.out.println ("[SONG SEARCH]"); 
       search (songname, songpath, artist, genre, count, file); 
       break; 

      case 4: 
       System.out.println ("[SONGLIST SORT]"); 
       sort (songname, artist, genre, count); 
       break; 

      case 5: 
       System.out.println ("[CREATING BACKUP OF SONGLIST"); 
       backup (file, count, songname, songpath, artist, genre); 
       break; 

      case 6: 
       System.out.println ("[REMOVE SONG FROM LIST]"); 
       break; 

      case 7: 
       System.out.println ("[CREATE NEW PROFILE]"); 
       break; 
     } 
    } 
    while (reset == true); 
} 
} 

出力:

No applicable overload for the method named "rf" was found in type 
"mp3_organizer". Perhaps you wanted the overloaded version "void rf(java.lang.String[] songname, java.lang.String[] 
songpath,java.lang.String[] artist, java.lang.String[] genre, int[] count,java.lang.String file) throws java.io.FileNotFoundException, 
java.io.IOException;" instead? 

答えて

1

問題はここにある:あなたが6つのパラメータとint cuunt[]を持っている

public static void rf (String[] songname, String[] songpath, String[] artist, String[] genre, int[] count, String file){ 
    //... 
} 

は、あなたのメソッドの実装では配列です。

しかし、あなたは6つの引数を渡すが、可変として数メソッドを呼び出すとき:このを解決するために

rf (songname, songpath, artist, genre, count, file); 

あなたが一致するための変数としてカウント渡す方法をオーバーロードする必要がありますメソッドの実装。あなたが唯一の変数として渡したい場合はそうでないarray.Likeにこの変更:

//method count array 
public static void rf (String[] songname, String[] songpath, String[] artist, String[] genre, int[] count, String file) throws FileNotFoundException, IOException 
{ 
    BufferedReader reader = new BufferedReader (new FileReader (file)); 

    String temp, line = null; 

    while ((line = reader.readLine()) != null) 
    { 
     songname [count [0]] = line; 
     songpath [count [0]] = reader.readLine(); 
     artist [count [0]] = reader.readLine(); 
     genre [count [0]] = reader.readLine(); 
     count [0]++; 
    } 


    reader.close(); 
} 

//overloaded six parameter method 
//without count array. count variable 
public static void rf (String[] songname, String[] songpath, String[] genre, int count, String file) throws FileNotFoundException, IOException 
    { 
     BufferedReader reader = new BufferedReader (new FileReader (file)); 

     String temp, line = null; 

     while ((line = reader.readLine()) != null) 
     { 
      songname [count [0]] = line; 
      songpath [count [0]] = reader.readLine(); 
      artist [count [0]] = reader.readLine(); - remove this line 
      genre [count] = reader.readLine();//change this too, genre [count[0]] 
      count++;//since this is not a array change to count[0]++. 
     } 


     reader.close(); 
    } 

をまた、あなたはsearch()をオーバーロードする必要があります。

static void search (String[] songname, String[] songpath, String[] artist, String[] genre, int count) 

(実装でfileパラメータではない)呼び出し元の関数と一致しませんでした:

search (songname, songpath, artist, genre, count, file); 

UPDATE:

これらはまたあなたの上記の実装に応じて変更する必要があります。

songname [count [0]] = line; 
songpath [count [0]] = reader.readLine(); 
artist [count [0]] = reader.readLine(); 
genre [count [0]] = reader.readLine(); 
count [0]++; 

私はむしろ、これらのすべてを変更するよりも、あなたがrf()search()に配列としてcountパラメータを渡すことができると思います。それ以外の場合は、プログラム全体を変更する必要があります。これを行う方法を考えている人はあなたです。

続きを読むmethod overloadingを読んでください。

関連する問題