Java duplicate class main

Вопрос №8985 от пользователя Игорь Гордеев в уроке «Модуль 3. Урок 3. Уровни методов в Java.», курс «Введение в Java»

Здравствуйте. Выдаёт ошибку в файлах main. Я их не изменял. Трогал только файлы, описанные в readme. Своими силами проблему решить не удаётся.

P.S. ещё файл «./Player.java» дополнял, поскольку сначала компилятор ругался на него.

День добрый, что бы точно понять в чем ошибка нужно увидеть остальные файлы (включая Player.java) можете сокпировать их сюда (с сохранением форматрирования, это можно сделать обрамляя код в «`).

«./src/Main.java»

 final MoveController mc = new MoveController(); mc.applyFigure(field, p, "X"); final WinnerController wc = new WinnerController(); final String winner = wc.getWinner(field); if (!winner.equals("X")) < throw new RuntimeException(String.format("WinnerController returns %s, instead of X", winner)); >> > 

«CurrentMoveController.java»

package io.hexlet.xo.controllers; // BEGIN (write your solution here) import io.hexlet.xo.model.Field; // END public class CurrentMoveController  // BEGIN (write your solution here) Field field = new Field(); public String currentMove(Field field)  return "X"; > // END > 

«MoveController.java»

package io.hexlet.xo.controllers; // BEGIN (write your solution here) import io.hexlet.xo.model.Field; import io.hexlet.xo.model.Point; // END public class MoveController  // BEGIN (write your solution here) Field field = new Field(); Point point = new Point(); public void applyFigure(Field field, Point point, String figure) <> // END > 

«WinnerController.java»

package io.hexlet.xo.controllers; // BEGIN (write your solution here) import io.hexlet.xo.model.Field; // END public class WinnerController  // BEGIN (write your solution here) Field field = new Field(); public String getWinner(Field field)  return "X"; > // END > 
package io.hexlet.xo.model; public class Field  public String f00; public String f01; public String f02; public String f10; public String f11; public String f12; public String f20; public String f21; public String f22; // BEGIN (write your solution here) Point point = new Point(); public int getSize()  return 3; > public String getFigure(Point point)  return null; > public void setFigure(Point point, String figure) <> // END > 

«ConsoleView.java»

package io.hexlet.xo.view; // BEGIN (write your solution here) import io.hexlet.xo.model.Game; // END public class ConsoleView  // BEGIN (write your solution here) Game game = new Game(); public void show(Game game) <> public boolean move(Game game)  return false; > // END > 

И на всякий случай OUTPUT с сохранения форматирования:

 sources.txt javac @sources.txt -sourcepath src -d out -cp out ./Main.java:2: error: duplicate class: Main public class Main < ^ ./src/Main.java:13: error: cannot find symbol player.name = "Slava"; ^ symbol: variable name location: variable player of type Player ./src/Main.java:14: error: cannot find symbol player.figure = "X"; ^ symbol: variable figure location: variable player of type Player ./src/Main.java:17: error: incompatible types: Player cannot be converted to io.hexlet.xo.model.Player game.player1 = new Player(); ^ ./src/Main.java:18: error: incompatible types: Player cannot be converted to io.hexlet.xo.model.Player game.player2 = new Player(); ^ 5 errors Makefile:2: recipe for target 'test' failed make: Leaving directory '/usr/src/app' make: *** [test] Error 1 

немного странно что есть 2 Main, один в папке src, другой в корневой папке, так же есть строгое ощущение что у Вас два класса Player (один в корне проекта а воторой в нужном пакете). Попробуйте сделать вот что:

  • скопировать ваши изменения из классов куда-то
  • сбросить д/з
  • заново вставить изменения

Класс Player должен находится в нужном пакете а не просто в корне, иначе компилироваться не будет. Так же добавьте к каждому полю класса Player идентификтора доступа public .

Сброс не помог. Всё равно остаются "./Player.java" и "./Main.java".

enter image description here

Поэтому я попробовал удалил через терминал эти два файла и. всё скомпилировалось. Это можно считать за решение? Потому что эти два файла даже не указаны в sources.txt.

да, это судя по всему бага была =)

Источник

Java: "duplicate class" and Mismatched File Name Error

Developers who are new to Java can sometimes have trouble with class and package naming. In fact, the introductory Java forums are filled with threads starting with questions about these areas of Java. In this blog post, I look at some of these errors and some of the causes of these errors.

One of the more obvious errors occurs when a public Java class is named differently than the file that contains the class definition.

This is demonstrated in the next screen snapshot. In this example, a class was declared as public with the name Person , but was saved in a file called Person2.java . The error message is pretty explicit: "class Person is public, should be declared in a file named Person.java"

The "duplicate class" error can sometimes be a little more tricky to resolve. One situation in which this occurs is when two source code directories include the same class with the same package structure. This error looks like that shown in the next screen snapshot.

As the above screen snapshot indicates, the class dustin.examples.Person exists in both the src2 directory and (not shown here) in the src directory ("duplicate class: dustin.examples.Person"). Indeed, these are duplicate classes, at least in terms of package and class name.

The "duplicate class" error can also occur when the class is named the same with the same package naming hierarchy, even if one of the classes exists in a directory structure with directory names different than the package names. This is shown in the next screen snapshot.

This screen snapshot demonstrates that the "duplicate error" occurs when the class names and declared package names match even if the source file exists in directories with different names (different even than the declared package structure). What this implies is that if a particular class was copied to another directory without changing the package statement and the new directory was in the source path for javac, the "duplicate class" error will occur.

Another interesting observation from the last example is that javac uses the package statement to decide where to build the .class file rather than using the source file's location in a directory structure.

In the blog post Java duplicate class error, Morgy describes a situation in which he ran into the "duplicate class" error message (he had neglected to place the class's package declaration at the top of the class).

In this post, I have attempted to show some common causes of errors that can be troublesome for those new to Java. Specifically, I have demonstrated some of the common causes of the "duplicate class" error and of the public class not matching its file name.

This story, "Java: "duplicate class" and Mismatched File Name Error" was originally published by JavaWorld .

Next read this:

Dustin Marx is a principal software engineer and architect at Raytheon Company. His previous published work for JavaWorld includes Java and Flex articles and "More JSP best practices" (July 2003) and "JSP Best Practices" (November 2001).

Copyright © 2010 IDG Communications, Inc.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Intellij IDEA 12: Duplicate class error for generated classes #423

Intellij IDEA 12: Duplicate class error for generated classes #423

Comments

I just upgraded to Intellij IDEA 12 Community Edition. On compiling my project I have started getting a duplicate class error on all annotated classes. For ex:

java: activities/BaseMapActivity_.java:16: duplicate class: activities.BaseMapActivity_

I do not get the warning as mentioned in this report on the JetBrains bug tracker: http://youtrack.jetbrains.com/issue/IDEA-94150. I removed the generated source folder from the source path but no luck. I get a no symbol found error then.

The text was updated successfully, but these errors were encountered:

Btw. I haven't switched to 2.7 yet. Still on 2.6.

This issue may be resolved by 2.7, it would be nice if you could try to use it 🙂 . At least as a test.

Sure. Back on Idea 11 to get a minor release out. Will give IDEA 12 a shot
with 2.7 in a couple of days.

On Thu, Dec 6, 2012 at 6:10 PM, Pierre-Yves Ricau
notifications@github.comwrote:

This issue may be resolved by 2.7, it would be nice if you could try to
use it 🙂 . At least as a test.


Reply to this email directly or view it on GitHubhttps://github.com//issues/423#issuecomment-11083879.

Hate to say: But I have the same problem with IDEA 11 as well. With «mvn clean» as a good workaround.

Strange thing: I never actually found the 2nd class file.

Ok. Tried with Idea 12 again and AA 2.7. These are my steps:

  1. Go to Settings > Annotation Processors
  2. Enable annotation processing
  3. Add androidannotations-2.7.jar in processor path
  4. Production sources directory: aa-gen
  5. Test sources directory: aa-gen-tests
  6. Store generated sources relative to: Module content root/Module output directory (tried both)
  7. Include androidannotations-api-2.7.jar in the main module as a dependency
  8. Add aa-gen as a Source in the module settings. (tried compiling without it)
  9. Re-build project

I get a "cannot find symbol" error for all AA classes. The aa-gen folder is empty.

Problem is that I don't have maven set up with this project due to issues with library projects with NDK dependencies earlier. I can't use something like mvn clean.

Let me know if I am going wrong somewhere. This setup works with Idea 11 so am guessing something changed with Idea itself.

I can confirm this bug with AA 2.7, Idea 12 and Maven. mvn clean didn't help. This might sound silly but I got it working by removing the @EActivity annotation from the main (and removing _ from the activity name in AndroidManifest file). Ran it once, changed back to AA again. But then, if you rebuild, it breaks again. Weird.

Finally got it working! The problem is not with AA but with how you setup your sources directory. I spent a lot of hours setting up Android with Maven + ActionBarSherlock + Roboelectric + AndroidAnnotations with IntelliJ IDEA 12. I've written a long blog post (with code snippets and screenshots) on how to setup everything from scratch here - http://www.ashokgelal.com/2012/12/setting-up-intellij-idea-12-with-maven-actionbarsherlock-roboelectric-androidannotations/.

Hopefully, it will be useful for others.

@ashokgelal Thanks! Looks great. I'll try setting up Maven here again.

If anyone has had success without using Maven, please let me know!

i've also written up a small stackoverflow answer on this issue and my experiences (i'm not using maven, just AA and ActionBarSherlock + EventBus). The only problem I have is that everytime i change a source which uses AA, and just "run" my project (or first make my main module), is that it will crash because of an NPE (of an added @bean) in a superclass of that edited source (which also uses AA). So i have to rebuild my entire project every time i want to test something. My main guess is that I don't see any AA output when I make my main module, so i guess AA is only run on a rebuild.

However I don't have success with either solution. Apparently the build system was replaced in v12.

Источник

Читайте также:  Caused by java lang illegalargumentexception baseurl must end in
Оцените статью