Error related to arguments in a method

so i'm getting this error java compiler: method readMessages in class Main cannot be applied to given types; required: no arguments found: java.lang.String,Message[] reason: actual and formal argument lists differ in length but i my readMessages method doesn't require any arguments
14 Replies
JavaBot
JavaBot4w ago
This post has been reserved for your question.
Hey @akuma! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
akuma
akumaOP4w ago
also that error is when codegrade runs it, if i run the code myself, it runs fine What can be the issue? Thank you in advance to anyone who decides to help
JavaBot
JavaBot4w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
akuma
akumaOP4w ago
For now I'm gonna go to bed since it's midnight here almost so I won't be able to respond to texts immediately
dan1st
dan1st4w ago
Can you show the relevant code?
JavaBot
JavaBot4w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
akuma
akumaOP4w ago
import java.util.*;
import java.io.*;

public class Main {
public static String[] messages;
public static void main(String[] args) {
readMessages();
writeConversation();
}
import java.util.*;
import java.io.*;

public class Main {
public static String[] messages;
public static void main(String[] args) {
readMessages();
writeConversation();
}
uh hold on i'll send the methods
public static void readMessages() {
try {
Scanner reader1 = new Scanner(new File("Person1.txt"));
Scanner reader2 = new Scanner(new File("Person2.txt"));
String[] messages1 = new String[10];
String[] messages2 = new String[10];
int i = 0;
int j = 0;

while (reader1.hasNextLine()) {
messages1[i] = reader1.nextLine();
i++;
}

while (reader2.hasNextLine()) {
messages2[j] = reader2.nextLine();
j++;
}

reader1.close();
reader2.close();

messages = new String[i + j];
for (int k = 0; k < i; k++) {
messages[k] = messages1[k];
}

for (int k = 0; k < j; k++) {
messages[i + k] = messages2[k];
}

for (int k = 0; k < messages.length; k++) {
for (int l = k + 1; l < messages.length; l++) {
int firstWhiteSpace = messages[k].indexOf(" ");
int secondWhiteSpace = messages[k].indexOf(" ", firstWhiteSpace + 1);
int thirdWhiteSpace = messages[k].indexOf(" ", secondWhiteSpace + 1);
DateTime first = new DateTime(messages[k].substring(firstWhiteSpace + 1, thirdWhiteSpace));

int firstWhiteSpace2 = messages[l].indexOf(" ");
int secondWhiteSpace2 = messages[l].indexOf(" ", firstWhiteSpace2 + 1);
int thirdWhiteSpace2 = messages[l].indexOf(" ", secondWhiteSpace2 + 1);
DateTime second = new DateTime(messages[l].substring(firstWhiteSpace2 + 1, thirdWhiteSpace2));

public static void readMessages() {
try {
Scanner reader1 = new Scanner(new File("Person1.txt"));
Scanner reader2 = new Scanner(new File("Person2.txt"));
String[] messages1 = new String[10];
String[] messages2 = new String[10];
int i = 0;
int j = 0;

while (reader1.hasNextLine()) {
messages1[i] = reader1.nextLine();
i++;
}

while (reader2.hasNextLine()) {
messages2[j] = reader2.nextLine();
j++;
}

reader1.close();
reader2.close();

messages = new String[i + j];
for (int k = 0; k < i; k++) {
messages[k] = messages1[k];
}

for (int k = 0; k < j; k++) {
messages[i + k] = messages2[k];
}

for (int k = 0; k < messages.length; k++) {
for (int l = k + 1; l < messages.length; l++) {
int firstWhiteSpace = messages[k].indexOf(" ");
int secondWhiteSpace = messages[k].indexOf(" ", firstWhiteSpace + 1);
int thirdWhiteSpace = messages[k].indexOf(" ", secondWhiteSpace + 1);
DateTime first = new DateTime(messages[k].substring(firstWhiteSpace + 1, thirdWhiteSpace));

int firstWhiteSpace2 = messages[l].indexOf(" ");
int secondWhiteSpace2 = messages[l].indexOf(" ", firstWhiteSpace2 + 1);
int thirdWhiteSpace2 = messages[l].indexOf(" ", secondWhiteSpace2 + 1);
DateTime second = new DateTime(messages[l].substring(firstWhiteSpace2 + 1, thirdWhiteSpace2));

if (first.compareTo(second) > 0) {
String temp = messages[k];
messages[k] = messages[l];
messages[l] = temp;
}
}
}
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
if (first.compareTo(second) > 0) {
String temp = messages[k];
messages[k] = messages[l];
messages[l] = temp;
}
}
}
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
public static void writeConversation() {
try {
PrintWriter writer = new PrintWriter("Conversation.txt");
for (String message : messages) {
writer.println(message);
}
writer.close();
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
}
public static void writeConversation() {
try {
PrintWriter writer = new PrintWriter("Conversation.txt");
for (String message : messages) {
writer.println(message);
}
writer.close();
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
}
and i am aware that here's probably more optimized ways i can write the code but i'm very new to java so i'm not that good
dan1st
dan1st4w ago
Can you try compiling that with from the command-line? Did you actually save the file?
akuma
akumaOP4w ago
yes, it is running smoothly on my own computer, but when codegrade runs it, it gives me the error i got above not sure how to do that, sorry
dan1st
dan1st4w ago
I guess the specification requires the method to look like that? Did you maybe get a project template or similar?
akuma
akumaOP4w ago
we only got basic instructions on which classes to create, what each class is supposed to have and one by one i fixed all the errors that popped up in codegrade then i landed on that one if you want, i can also send a screenshot of the instructions given to us
dan1st
dan1st4w ago
Well I guess these instructions said what the methods should look like
akuma
akumaOP4w ago
yeah and apparently the readMessages method is supposed to have no arguments in the end i just submitted as it is since i racked my brain the whole day and couldn't figure out the issue
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?