在类/表达式的非法开始中找不到主要方法
Posted
技术标签:
【中文标题】在类/表达式的非法开始中找不到主要方法【英文标题】:Main method not found in class/illegal start of expression 【发布时间】:2013-01-29 13:30:48 【问题描述】:我对这一切都很陌生,实际上对编码只有基本的了解。
我实际上是在尝试使用在 ChemMedChem 中发布的 java 代码(支持信息中的 dx.doi.org/10.1002/cmdc.200900317)
我有他们使用的所有适当的程序/jar 文件(来自 ChemAxon)
我可以复制代码并将其编译为类文件,没有任何问题:
javac -classpath C:\jarfolder\MarvinBeans-plugin.jar;C:\jarfolder\MarvinBeans.jar; MQN.java
虽然我得到了:
Note: MQN.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
然后当它尝试运行类文件时(输入文件应该是一个虚拟化学输入作为微笑代码):
java -classpath C:\jarfolder\MarvinBeans-plugin.jar;C:\jarfolder\MarvinBeans.jar; MQN test.smiles
我明白了:
Error: Main method not found in class MQN, please define the main method as:
public static void main(String[] args)
我试图将代码包含在
中public static void main(String[] args)
然后我得到错误:
>MQN.java:10: error: illegal start of expression
public String calculateMQN(Molecule m)
^
>MQN.java:10: error: ';' expected
public String calculateMQN(Molecule m)
^
>MQN.java:10: error: ';' expected
public String calculateMQN(Molecule m)
^
>MQN.java:255: error: reached end of file while parsing
^
4 errors
您将在下面找到我使用的代码(在添加 public static void main(String[] args) 之前),任何帮助将不胜感激
谢谢!
Java 代码:
import chemaxon.calculations.TopologyAnalyser;
import chemaxon.marvin.calculations.HBDAPlugin;
import chemaxon.struc.MolAtom;
import chemaxon.struc.MolBond;
import chemaxon.struc.Molecule;
public class MQN
TopologyAnalyser ta = new TopologyAnalyser();
HBDAPlugin hbda = new HBDAPlugin();
public String calculateMQN(Molecule m)
if (!m.dearomatize())
System.out.println("DEAROMATIZE ERROR");
ta.setMolecule(m);
//Classic descriptors
try
hbda.setMolecule(m);
hbda.run();
catch (Exception e)
System.err.println("HBDA ERROR");
int hbd = hbda.getDonorAtomCount();
int hbdm = hbda.getDonorCount();
int hba = hbda.getAcceptorAtomCount();
int hbam = hbda.getAcceptorCount();
/*Reymond style Rot bond count*/
int rbc = ta.rotatableBondCount();
for (int i = 0; i < m.getBondCount(); i++)
if (m.getBond(i).getType() == 3)
rbc--;
if (rbc < 0)
rbc = 0;
//Ring properties / ring sizes count
int r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, rg10 = 0;
int[][] ss-s-r = m.getSs-s-r();
for (int i = 0; i < ss-s-r.length; i++)
switch (ss-s-r[i].length)
case 3:
r3++;
break;
case 4:
r4++;
break;
case 5:
r5++;
break;
case 6:
r6++;
break;
case 7:
r7++;
break;
case 8:
r8++;
break;
case 9:
r9++;
break;
default:
rg10++;
break;
//Atom properties
int c = 0, f = 0, cl = 0, br = 0, I = 0, thac = 0, asv = 0, adv = 0, atv = 0, aqv = 0,
cdv = 0, ctv = 0, cqv = 0, p = 0, s = 0, posc = 0, negc = 0,
afrc = 0, cn = 0, an = 0, co = 0, ao = 0;
for (int i = 0; i < m.getAtomCount(); i++)
MolAtom at = m.getAtom(i);
boolean isRingAt = ta.isRingAtom(i);
if (at.getAtno() != 1)
thac++;
//element counts
switch (at.getAtno())
case 1:
case 2:
case 3:
case 4:
case 5:
break;
case 6:
c++;
break;
case 7:
if (isRingAt)
cn++;
else
an++;
break;
case 8:
if (isRingAt)
co++;
else
ao++;
break;
case 15:
p++;
break;
case 16:
s++;
break;
case 9:
f++;
break;
case 17:
cl++;
break;
case 35:
br++;
break;
case 53:
I++;
break;
//valency count
switch (at.getBondCount())
case 0:
System.out.println("ATOM WITH NO BONDS");
break;
case 1:
asv++; //single valent can only be acyclic
break;
case 2:
if (isRingAt)
cdv++;
else
adv++;
break;
case 3:
if (isRingAt)
ctv++;
else
atv++;
break;
case 4:
if (isRingAt)
cqv++;
else
aqv++;
break;
if (ta.ringCountOfAtom(i) > 1)
afrc++;
//Bond properties
int csb = 0, cdb = 0, ctb = 0, asb = 0, adb = 0, atb = 0, bfrc = 0;
for (int i = 0; i < m.getBondCount(); i++)
MolBond bd = m.getBond(i);
if (ta.isRingBond(i))
switch (bd.getType())
case 1:
csb++;
break;
case 2:
cdb++;
break;
case 3:
ctb++;
break;
default:
System.out.println("UNKNOWN CYCLIC BOND TYPE " + bd.getType());
break;
else
switch (bd.getType())
case 1:
asb++;
break;
case 2:
adb++;
break;
case 3:
atb++;
break;
default:
System.out.println("UNKNOWN ACYCLIC BOND TYPE " + bd.getType());
break;
//bond's fused ring count
int[][] ss-s-re = m.getSs-s-rBonds();
int[] brc = new int[m.getBondCount()];
for (int j = 0; j < ss-s-re.length; j++)
for (int k = 0; k < ss-s-re[j].length; k++)
brc[ss-s-re[j][k]]++;
for (int j = 0; j < brc.length; j++)
if (brc[j] > 1) //if bond's ring count > 1
bfrc++; //increase fused ring bonds count
for (int i = 0; i < m.getAtomCount(); i++)
int crg = m.getAtom(i).getCharge();
if (crg > 0)
posc += crg;
if (crg < 0)
negc += Math.abs(crg);
return //CLASSIC PROPERTIES
hbd + ";" //hydrogen bond donor atom count 1
+ hbdm + ";" //HBD with multivalency 2
+ hba + ";" //hydrogen bond acceptor atom count 3
+ hbam + ";" //HBA with multivalency 4
+ rbc + ";" //rotatable bond count 5
//RING PROPERTIES
+ r3 + ";" + r4 + ";" + r5 + ";" + r6 + ";" + r7 + ";" + r8 + ";" + r9 + ";" + rg10 + ";"
//RingSize Counts 6-13
//ATOM PROPERTIES
+ thac + ";"//total heavy atom count (= everything else than H D T) 14
+ c + ";" //carbon count 15
+ p + ";"//phosphorus 16
+ s + ";"//sulfur atom count 17
+ f + ";" //fluor atom count 18
+ cl + ";" //chlorine atom count 19
+ br + ";" //bromine atom count 20
+ I + ";" //iodine atom count 21
+ cn + ";" //cyclic nitrogen count 22
+ an + ";" //acyclic nitrogen count 23
+ co + ";" //cyclic oxygen count 24
+ ao + ";" //acyclic oxygen count 25
+ asv + ";"//acyclic single valent atom count 26
+ adv + ";"//acyclic double valent atom count 27
+ atv + ";"//acyclic triple valent atom count 28
+ aqv + ";"//acyclic quart valent atom count 29
+ cdv + ";"//cyclic double valent atom count 30
+ ctv + ";"//cyclic triple valent atom count 31
+ cqv + ";"//cyclic quart valent atom count 32
+ afrc + ";"//atoms-in-fused-ring count 33
+ posc + ";" // Positive charges 34
+ negc + ";" // Negative charges 35
//BOND PROPERTIES
+ csb + ";"//cyclic single bonds 36
+ cdb + ";"//cyclic double bonds 37
+ ctb + ";"//cyclic triple bonds 38
+ asb + ";"//acyclic singe bonds 39
+ adb + ";"//acyclic double bonds 40
+ atb + ";"//acyclic triple bonds 41
+ bfrc + ";"//bonds-in-fused-ring count 42
+ m.toFormat("smiles:q");//END 43
【问题讨论】:
这个jar文件不能作为独立应用运行,只能作为库使用。 文件末尾缺少右括号 。 嗯,也许我只是迷路了,但我认为我正在创建和运行一个类文件而不是 jar 文件? 我明白程序也需要一个输入文件,这就是为什么我输入“MQN test.smiles”,其中 test.smiles 是程序应该分析的输入文件 【参考方案1】:像这样添加main
...............................
...............................
public class MQN
TopologyAnalyser ta = new TopologyAnalyser();
HBDAPlugin hbda = new HBDAPlugin();
public static void main(String [] args)
// This is where the execution of the program will begin
public String calculateMQN(Molecule m)
if (!m.dearomatize())
System.out.println("DEAROMATIZE ERROR");
.............
..............
如果您仍然遇到编译器错误,请在此处发表评论
【讨论】:
谢谢,不再出现错误但我也没有得到任何输出,很可能还有其他一些重要的事情我没有得到这个代码,不幸的是代码的原始作者还没有回来我。感谢您的所有帮助!【参考方案2】:您的类确实不包含必须遵循此签名的main
方法:
public static void main(String[] args)
这个方法是你程序的入口点,应该调用其他方法,创建对象等。
【讨论】:
当我添加即:import chemaxon.calculations.TopologyAnalyser; import chemaxon.marvin.calculations.HBDAPlugin; import chemaxon.struc.MolAtom; import chemaxon.struc.MolBond; import chemaxon.struc.Molecule; class MQN TopologyAnalyser ta = new TopologyAnalyser(); HBDAPlugin hbda = new HBDAPlugin(); public static void main(String[] args) public String calculateMQN(Molecule m)
我得到上面提到的第二个错误
@kask382 答案是正确的。但是您不能将一种方法放在另一种方法中。 main
方法应该在声明 calculateMQN()
之前关闭。
@user000001 那么我需要将哪一部分包含在主要方法中?当我将它放在 MQN 类之后并在公共字符串之前关闭它时,当我尝试编译时,我得到错误找不到符号 ta、hbda 等。
@kask382 我添加了一个示例作为单独的答案以上是关于在类/表达式的非法开始中找不到主要方法的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot + Kotlin + Gradle - 错误:在类中找不到主要方法
在类中找不到 main(String[]) 方法:TapeDeck。主要方法在运行程序的另一个类中
错误:在类计算中找不到主方法,请将主方法定义为:public static void main(String[] args) [重复]
错误: 在类 Main 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args) 否则 JavaFX 应用程序类必须