Link to home
Start Free TrialLog in
Avatar of jpetter
jpetter

asked on

Problem -- 'No main classes found' error trying to run program

Hi,

I was trying to, hoping to, test out a small program and while it compiles and builds okay, I cannot run it. When I try to run it, a dialog box pops up saying "No main classes found", and I am suppose to select a class from the list, but the list is empty.

I'm using the NetBeans 5.0 IDE
class name is SNMPTest
filename is SNMPTest.java

While searching for a solution on the web, I found a Sun tech note that discussed this and described how to set a main class through the project properties. I tried that, I receive an error stating it cannot find the class.

Being new to Java I must have something boned up in my code, but I can't find it.

I have successfully compiled and run a number of programs in the NetBeans IDE, and I stared and compared those that worked with this, and really can't find any major differences.

I would appreciate it if anyone could help me resolve this. - code below

Thanks,
Jeff

package SNMPTest.snmp4j.org;
import java.io.IOException;
import java.util.Vector;
import org.snmp4j.*;
import org.snmp4j.mp.*;
import org.snmp4j.security.*;
import org.snmp4j.smi.*;
import org.snmp4j.transport.*;
import org.snmp4j.util.*;
import org.snmp4j.event.ResponseEvent;
import java.util.StringTokenizer;
import org.snmp4j.log.LogFactory;
import org.snmp4j.log.Log4jLogFactory;
import org.snmp4j.asn1.BER;

/**
 *
 * @author
 */
public class SNMPTest {
    CommunityTarget     target = new CommunityTarget();
    Address             address = GenericAddress.parse("105.37.49.14/161");
    OctetString         community = new OctetString("public");
    PDU                 pdu = new PDU();
    int                 version = SnmpConstants.version2c;
    int                 retries = 1;
    int                 timeout = 3000;
    int                 pduType = PDU.GET;
    int                 maxRepitions = 10;
    int                 nonRepeaters = 0;
   
       
    /** Creates a new instance of SNMPTest */
    public SNMPTest() {
        TransportMapping    transport;
        Snmp                snmp;
       

        setTarget();
        setPDU();        
       
        try{
            transport = new DefaultUdpTransportMapping();
            snmp = new Snmp(transport);
            snmp.listen();
            ResponseEvent response = snmp.send(pdu, target);
            PDU responsePDU = response.getResponse();
            Address peerAddress = response.getPeerAddress();
            System.out.println(responsePDU);
        }
        catch (IOException e){
            System.out.println(e.getMessage());
        }
    }
   
    public void setTarget(){
        //setup the target
        target.setVersion(SnmpConstants.version2c);
        target.setAddress(address);
        target.setRetries(1);
        target.setTimeout(3000);        
    }
   
    public void setPDU(){
        //setup the PDU ==> the payload
        pdu.setType(PDU.GET);
        pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
        pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.1.0")));
       
    }
   
    public static void main() {
        SNMPTest    snmptest = new SNMPTest();
     }
       
}
ASKER CERTIFIED SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry - didn't refresh
Avatar of jpetter
jpetter

ASKER

Many thanks to all....that worked like a charm.

Thanks again,
Jeff
I am now receiving the same error. I am using v6.5.1 with jdk1.6 on xpsp3. The code was working fine and then next day when running the debugger got same message. Snippet is attached. I am new to netbeans (using for 3 months) but not IDE's or Java. There is definetly something funky going on here.
package com.utc.pw.z515;
 
/**
 * Declare Main class
 *
 * This main class entry point is just an unobfuscated proxy
 */
public class Main
{
 
  /**
   * Main Method
   *
   * @param args Command line arguments
   * @throws java.lang.Throwable
   */
  public static void main(String[] args) throws Throwable
  {
    com.utc.pw.z515.core.Nexus.main(args);
  }
}

Open in new window

I can only guess, but can it be that the class com.utc.pw.z515.core.Nexus has no method declared as
  public static void main(String[] ...)

and can You post an exact exception text You are getting?
Solution is incorrect. NetBeans has a bug in it the appears sporadically. I founf a quick woraround. If you create a new project from a sample for instance. build and run it and it works.
It will "automagically" correct your faulty project. Netbeans developers should detrmine the root cause for the bug becuase it is real and apparently elusive (or hard to repeat). My code is proprietary so they will nee to look elsewhere as to how the error gets induced. Perhaps by understnding how creating a new project in the IDE corrects the faulty project they can work in reverse.