Results 1 to 9 of 9
  1. #1
    kask382 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Main method not found in class

    I am new to all of this and really only have a basic understanding of coding in general.

    I am actually trying to use a java code that was published in ChemMedChem (dx.doi.org/10.1002/cmdc.200900317 in the supporting information)

    i have all the appropriate programs/jar files they use (from ChemAxon)

    i am able to copy the code and convert it to a class file with no issues:

    javac -classpath C:\jarfolder\MarvinBeans-plugin.jar;C:\jarfolder\MarvinBeans.jar; MQN.java

    Then when it try to run the class file (the input file is supposed to a virtual chemical input as a smiles code):

    java -classpath C:\jarfolder\MarvinBeans-plugin.jar;C:\jarfolder\MarvinBeans.jar; MQN test.smiles

    i get:
    Error: Main method not found in class MQN, please define the main method as:
    public static void main(String[] args)

    below you will find the code that i used, any help would be much appreciated

    Thanks!

    Java Code:
    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[][] sssr = m.getSSSR(); 
            for (int i = 0; i < sssr.length; i++) { 
                switch (sssr[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[][] sssre = m.getSSSRBonds(); 
            int[] brc = new int[m.getBondCount()]; 
            for (int j = 0; j < sssre.length; j++) { 
                for (int k = 0; k < sssre[j].length; k++) { 
                    brc[sssre[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 
        } 
    }
    Last edited by JosAH; 02-13-2013 at 08:20 PM. Reason: fixed the [code] ... [/code] tags

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Main method not found in class

    you need to add put it all in a method called

    public static void main(String[] args) this is what the compiler will search for to run your program.

  3. #3
    kask382 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Re: Main method not found in class

    When i put that at the very begining:

    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 String calculateMQN(Molecule m) {

    etc...}

    i get:
    MQN.java:1: error: class, interface, or enum expected
    public static void main(String args[])
    ^
    MQN.java:257: error: class, interface, or enum expected
    }
    ^
    2 errors

    if i put it after the class MQN ie:

    import chemaxon.calculations.TopologyAnalyser;
    import chemaxon.marvin.calculations.HBDAPlugin;
    import chemaxon.struc.MolAtom;
    import chemaxon.struc.MolBond;
    import chemaxon.struc.Molecule;
    class MQN {
    public static void main(String args[])
    {
    TopologyAnalyser ta = new TopologyAnalyser();
    HBDAPlugin hbda = new HBDAPlugin();
    public String calculateMQN(Molecule m) {

    etc...}

    i get:
    MQN.java:11: error: illegal start of expression
    public String calculateMQN(Molecule m) {
    ^
    MQN.java:11: error: ';' expected
    public String calculateMQN(Molecule m) {
    ^
    MQN.java:11: error: ';' expected
    public String calculateMQN(Molecule m) {
    ^
    3 errors

    and when i add the appropriate ; to where it asks i just a bunch more errors telling me to put more :

  4. #4
    kask382 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Re: Main method not found in class

    and that error is when i try to go from the .java to .class

  5. #5
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Main method not found in class

    Quote Originally Posted by kask382 View Post
    and that error is when i try to go from the .java to .class
    its (String[] args)

    not (String args[])

  6. #6
    kask382 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Re: Main method not found in class

    i must have tryped it in here wrong, i did (String[] args) again in both places and got the same error

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: Main method not found in class

    You don't wrap the entire file in main().
    main() is a method, and needs to be inside the class definition.

    I think you need to have a read of the tutorial.
    Specifically the Getting Started one and the Learning the Java Language one.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,535
    Blog Entries
    7
    Rep Power
    20

    Default Re: Main method not found in class

    Quote Originally Posted by monkeyjr97 View Post
    its (String[] args)

    not (String args[])
    It doesn't matter; Java understands both forms.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    lenois is offline Member
    Join Date
    Feb 2012
    Posts
    59
    Rep Power
    0

    Default Re: Main method not found in class

    Quote Originally Posted by JosAH View Post
    It doesn't matter; Java understands both forms.

    kind regards,

    Jos
    Yep, it is to keep those C++ people happy. Among other languages.

Similar Threads

  1. Replies: 8
    Last Post: 11-22-2012, 07:16 AM
  2. No main class found
    By kkid in forum New To Java
    Replies: 1
    Last Post: 10-17-2012, 01:46 AM
  3. main method not found error in class . wat s the error?
    By kirankumaragnihotram in forum New To Java
    Replies: 10
    Last Post: 06-29-2012, 11:26 AM
  4. Main Method not found in class
    By HinaKhan in forum New To Java
    Replies: 6
    Last Post: 06-22-2012, 02:34 PM
  5. main method not found in class
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •