Reflections invoke NoSuchMethodException help

Hello everyone,
I've been reading a lot about reflections on the forum lately, and figured it was the perfect way to dynamically call a method based on string input. However, while I can get the SampleInvoke program that is in the reflections tutorial to work, I can't seem to invoke a method that I write myself. I think I'm close, but there must just be a little something wrong...could anyone lend me a hand?
   public void foo()
        System.out.println("Worked!");
   } // end foo
   public void bar()
        Class c = this.getClass();
        Class[] params = new Class[] { null };
        Object[] args = new Object[] { null };
        Method m;
           try {
               m = c.getMethod("foo", params);
              m.invoke(c, args);
             } catch (NoSuchMethodException e) {
                 System.out.println(e);
             } catch (IllegalAccessException e) {
                 System.out.println(e);
             } catch (InvocationTargetException e) {
                 System.out.println(e);
   }What I'm getting is:
java.lang.NoSuchMethodException: SampleInvoke.foo(null)
But it's clearly in the class...
Any help is appreciated,
Joe

enlightenment
Try
m = c.getMethod("foo", null);
Oh! Okay, if I do that on both the c.getMethod line
AND the m.invoke line, it works, however, both show
up as warnings, "Varargs arguments null should be
cast to Class[] when passed to the method
getMethod..."
or
"Varargs arguments null should be cast to Object[]
when passed to the method invoke..."
However, when I attempt to cast them, it goes back to
NoSuchMethodException output. I guess I'm willing to
live with a bunch of warnings, but I wonder why?Try to feed them "new Class[0]" and "new Object[0]". Haven't dealt with varargs yet, so I can't help you with that.

Similar Messages

  • IBM JDK 6 32bit & 64bit Reflection Invoke issue on Weblogic 10.3

    We just found a issue on Weblogic 10.3 with IBM JDK 6 32bit, which calls different method during reflection invoke with that been processed under 64bit JDK, here is my source code:
    public class ButtonTag extends InputTag {
    private boolean checkNotNull = false;
    public void setCheckNotNull(Object checkNotNull) {
    public void setCheckNotNull(boolean checkNotNull) {
    this.checkNotNull = checkNotNull;
    this.setUserSetCheckNotNull(true);
    Under 64bit, reflection invoke will call setCheckNotNull(boolean checkNotNull), however under 32bit, it will call setCheckNotNull(Object checkNotNull), actually 32bit version is doing something wrong, we are not sure it is a issue of weblogic or IBM JDK, pls refer the information below for details, Thanks
    OS: AIX 5.3
    AIX@ /usr/java6/bin./java -version
    java version "1.6.0"
    Java(TM) SE Runtime Environment (build pap3260sr2-20080818_01(SR2))
    IBM J9 VM (build 2.4, J2RE 1.6.0 IBM J9 2.4 AIX ppc-32 jvmap3260-20080816_22093 (JIT enabled, AOT enabled)
    J9VM - 20080816_022093_bHdSMr
    JIT - r9_20080721_1330ifx2
    GC - 20080724_AA)
    JCL - 20080808_02
    AIX@ /usr/java6_64/bin./java -version
    java version "1.6.0"
    Java(TM) SE Runtime Environment (build pap6460sr6-20090925_01(SR6))
    IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 AIX ppc64-64 jvmap6460sr6-20090923_42924 (JIT enabled, AOT enabled)
    J9VM - 20090923_042924
    JIT - r9_20090902_1330ifx1
    GC - 20090817_AA)
    JCL - 20090924_01
    AIX server107 3 5 00CE9E7B4C00

    The problem was the name of the Seam EJB module. Changing the jar to jboss-seam.jar, everything worked. This issue does not appear on JBoss 4.2.3.GA, where I also tested.
    Edited by: deadlock_gr on Jun 10, 2010 9:55 AM
    Edited by: deadlock_gr on Jun 10, 2010 9:56 AM

  • Reflective invoke of variable-argument method?

    I'm having trouble reflectively invoking a variable-argument method. Can anyone provide a code snippet that does it? Here's my test, with the output below:
    package comet.pod;
    import java.lang.reflect.Method;
    public class Test
       public void doSomething (Object... args)
          System.out.println ("hello world");
       public void test()
          Method method = null;
          try
             Class<?> c = Test.class;
             Class[] argTypes = new Class[] { Object[].class };
             method = c.getMethod ("doSomething", argTypes);
             System.out.println ("is VarArgs? " + method.isVarArgs());
          catch (Exception x) { System.err.println (x); }
          try
             method.invoke (this, (Object[]) null);
          catch (Exception x) { System.err.println (x); }
          try
             method.invoke (this, new Object());
          catch (Exception x) { System.err.println (x); }
          try
             method.invoke (this, new Object[] { "arg" });
          catch (Exception x) { System.err.println (x); }
       public static void main (final String[] args)
          new Test().test();
    }is VarArgs? true
    java.lang.IllegalArgumentException: wrong number of arguments
    java.lang.IllegalArgumentException: argument type mismatch
    java.lang.IllegalArgumentException: argument type mismatch

    You need something like:
    method.invoke(this, new Object[] { new Object[] { "arg1", "arg2" } });To see why, consider what you would do if your method was:
    public void doSomething (Object a1, Object a2, Object... aVar)Alex

  • Reflection problem - NoSuchMethodException

    Dear all,
    I am trying to use java reflection based on an article http://developer.java.sun.com/developer/qow/archive/86/ with non-default constructor example
    I have a method I'd like to call on runtime :
    loadProjects(String[] fields, String sWhereClause, String sOrderBy) throws ServerException, ...
    Without reflection I do the following :
    //without reflection
    GlobalObjectManager gom = session.getGlobalObjectManager();
    gom.loadProjects(new String[] { "ObjectId", "Name"},null,null);
    With reflection I tried the following :
    //with reflection
    GlobalObjectManager gom = session.getGlobalObjectManager();
    String objectName = "Projects"; //could be "Resources", "Others", ...
    String methodName = "load" + objectName;
    Class[] constructorArgumentTypes = { String[].class, String.class, String.class };
    Constructor classConstructor = gom.getClass().getConstructor(constructorArgumentTypes);
    Method classMethod = gom.getClass().getMethod(methodName, null);
    Object[] constructorArgs = { new String[] { "ObjectId", "Name" }, null, null };
    Object dynamicObject = classConstructor.newInstance(constructorArgs);
    classMethod.invoke(dynamicObject, null);
    I get the NoSuchMethodException error :
    java.lang.NoSuchMethodException: com.primavera.integration.client.GlobalObjectManager.<init>([Ljava.lang.String;, java.lang.String, java.lang.String)
         at java.lang.Class.getConstructor0(Class.java:1769)
         at java.lang.Class.getConstructor(Class.java:1002)
         at net.primafrance.reflect.InstantiateRuntimeClass.main(InstantiateRuntimeClass.java:50)
    Any comment will be appreciated.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Dear all,
    I am trying to use java reflection based on an article
    http://developer.java.sun.com/developer/qow/archive/86/
    with non-default constructor example
    I have a method I'd like to call on runtime :
    loadProjects(String[] fields, String sWhereClause,
    String sOrderBy) throws ServerException, ...
    Without reflection I do the following :
    //without reflection
    GlobalObjectManager gom =
    session.getGlobalObjectManager();
    gom.loadProjects(new String[] { "ObjectId",
    "Name"},null,null);
    With reflection I tried the following :
    //with reflection
    GlobalObjectManager gom =
    session.getGlobalObjectManager();
    String objectName = "Projects"; //could be
    "Resources", "Others", ...
    String methodName = "load" + objectName;
    Class[] constructorArgumentTypes = { String[].class,
    String.class, String.class };
    Constructor classConstructor =
    gom.getClass().getConstructor(constructorArgumentTypes)
    Method classMethod =
    gom.getClass().getMethod(methodName, null);
    Object[] constructorArgs = { new String[] {
    "ObjectId", "Name" }, null, null };
    Object dynamicObject =
    classConstructor.newInstance(constructorArgs);
    classMethod.invoke(dynamicObject, null);
    I get the NoSuchMethodException error :
    java.lang.NoSuchMethodException:
    com.primavera.integration.client.GlobalObjectManager.<i
    it>([Ljava.lang.String;, java.lang.String,
    java.lang.String)
         at java.lang.Class.getConstructor0(Class.java:1769)
         at java.lang.Class.getConstructor(Class.java:1002)
    at
    net.primafrance.reflect.InstantiateRuntimeClass.main(I
    stantiateRuntimeClass.java:50)
    Any comment will be appreciated.
    Your problem here is that you are constructing your object via reflection, which is not necessary.Look at what you are doing in your non-reflection code...From the session, get the GlobalObjectManager. Then call loadProjects( String[ sa, String s1, String s2) on that object.All you need to do in your reflection is replace the explicit call to loadProjects with the reflection equivalent...
    GlobalObjectManager gom = session.getGlobalObjectManager();
    //** Now we do the reflection
    Class gomClass = gom.getClass();
    Class[] paramTypes = { String[].class, String.class, String.class };
    Object paramValues = { { new String[] { "ObjectId", "Name" }, null, null };
    Method loadProjectsMethod = gomClass.getMethod( "loadProjects", paramTypes );
    loadProjectsMethod.invoke( gom, paramValues );What you were doing wrong was you were retrieving the gom as before but then trying to construct another one using the parameters expected for the loadProjects method.

  • NoSuchMethodException help

    I am using the following code to load a class dynamically. However, I have two parameters which are of type String[][] but it seems to not like that type and I get an exception.
    Class tClass = Class.forName("com.myproject.app.client.laws." + getState() + "Laws");
    Method m = tClass.getDeclaredMethod("applyRules", new Class[] {DetailLine.class, Integer.class, String[][].class, String[][].class});
    Object iClass = tClass.newInstance();
    Object[] args = {bl,line,historyManager.getHistoryArray(),historyManager.getTransArray()};
    Object r = m.invoke(iClass, args);I get the following error when I try to run it:
    java.lang.NoSuchMethodException: com.myproject.app.client.laws.PALaws.applyRules(com.myproject.app.client.api.tables.objects.core.bill.DetailLine, java.lang.Integer, [[Ljava.lang.String;, [[Ljava.lang.String;)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    georgemc wrote:
    4) This whole thing would be solved much more neatly with an interface than reflectionYeah, you should just create an interface that has a applyRules(...) method, then just have all your "com.myproject.app.client.laws.*Laws" classes implement it. That way, you wouldn't need to use reflection:
    Law law;
    if (getState().equals("PA")){
       law = new PALaws();
    law.applyRules(...);But looking at your error message, my first thought would be to double check your method signature. Can you post it here just so we can be sure that that's not the problem?

  • Reflection: invoke(obj, args) - args not returned with any change?

    All,
    I'm trying to invoke Method.invoke(obj, args) with an array of args that I'd like to be returned by reference (i.e. the method I'm invoking is changing the values within the array). For some reason, even though the method alters the values, they don't seem to be returned with any change?
    FYI - the obj returned from the method is fine (i.e. For ret = Method.invoke(obj,args) the ret object is valid and works like a treat).
    Any help on this would be appreciated.
    Kind regards,
    Matthew

    this is how it should be defined:
    target method:
    public type [] targetMethod(type[] arg) {
    //modify array 'arg'
    return arg;
    reflection code:
    modifiedArray = (type [])targetMethod.invoke(targ, args);
    Do you understand what I am saying? When your target method receives an argument that it must modify, it must return that array so that the modified values are available to the calling Object. Other wise, the values are only modified within the scope of the target method.
    Reflection is great for gaining an insight into classes and invoking methods that provide an insight into Object instances for things like a debugging utility, but it does not perform well, so you may want to avoid it if your only need is to modify runtime values.... ... hope this helps.

  • Heading style customizations not reflected in HTML Help file

    I wanted to share a solution I found for a problem with heading styles. I am using RoboHelp 9 for Word with Office 2010 and generating an HTMLHelp .chm file. When I migrated from Office 2003 to 2010 and RoboHelp 8 to 9, I customized the RoboHelp.docm template file to change the heading styles to have an orange border line over the header. (I had made the customizations in RH 8 for Word, but couldn't transfer the customization to the new template, so I did it by hand). The border line came out black in the header file in most of my topics in the .chm help file. I found one Word doc had topics with the orange line displayed correctly in the help and discovered that that heading style had Style Type = Linked, so I went to each of my Word docs and changed my Heading 1 style to use that style type and it fixed it for all my heading styles.
    In Word 2010, you can change this from the Home tab, Styles ribbon. Rt-click on the Heading 1 style and choose Modify. In the Modify Style dialog set Style type to Linked (paragraph and character).

    Thanks for sharing!
    Greet,
    Willam

  • Invoking Help thro WINDOWS API

    hi folks,
    i have created a simple windows help using robohelp classic, when i tried to invoke the help file
    using the windows API. the help pops up but, it doesnt go the particular topic which i had created.
    i have written the following code in KEY_HELP trigger at form level:
    BEGIN
    WIN_API_SHELL.WINHELP('C:\EMP\EMP.HLP','3',WIN_API.HELP_CONTEXT,FALSE);
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         NULL;
    END;
    pl asvise how to go about further.
    thanks in advance !
    - senthil

    jsthomas,
    According to the Call DLL.vi shipping example that comes with LabVIEW 7 Express (I wrote that one), it will be much better to use a cluster in LabVIEW with some embedded clusters to get the memory to work out right. With the array, LabVIEW sends an additional 4 bytes of data for the array length that is getting passed and that is why the function is not working. I have modified your VI and it should work fine for you know. Refer to that shipping example for more information on what I have done. You should be able to modify the rest of your code upon inspection.
    Randy Hoskin
    Applications Engineer
    National Instruments
    http://www.ni.com/ask
    Attachments:
    Scrollbar.vi ‏152 KB

  • Can anyone help me get reflections right in AE CS6? Details inside.

    Hello
      I'm using CS6's new Raytrace 3D feature, and I want to make a nice, glassy, reflective material for some puzzle pieces. I have most of it taken care of, but the surface doesn't look very good.
      The comp is here:
    http://i.imgur.com/fxo6c.png
      The reflection map is here:
    http://i.imgur.com/VRfEu.jpg
      What can I improve in order to get a nice hi-con glassy surface? Are there any good tips or tricks for doing this?
    Thanks

    Material options. That's your key. Reflection Intensity and specular intensity. Adjusting these can take you from a mirror to no reflections. Try typing ray trace reflections into the help field in the top right corner and look at the top item in the list. That will point you in the right direction. Then take a look at item 3.
    It's amazing how many resources are a question and a couple of clicks away.
    I'm not sure how happy you're going to be with your reflection map though. There are not many interesting features in it to add interest to a basically flat scene with a whole lot flat text over it.

  • Java help dialog invoked from modal dialog with webstart

    Hi,
    we have an application where we invoke a Help window from a modal dialog. It works fine if ran from IDE but doesn't work if ran from a webstart loader. The problem is to be able to set decorations (exit/minimize) for this help window but since this window is null (from printouts) it never goes to lines where decorations are set. The help dialog is displayed by calling super.setDisplayed(true) but it is not setting variables "frame" or "dialog" of DefaultHelpBroker class.
    I am sure it doesn't sound very clear but if you had a similar problem with web start messing up something please let me know.
    thanks.
    private static void initHelp()
        ClassLoader loader = HelpFactory.class.getClassLoader();
        try
          URL url = HelpSet.findHelpSet(loader, HELPSETNAME);
          helpSet = new HelpSet(loader, url);
          helpBroker = new DefaultHelpBroker(helpSet)
            public void setActivationWindow(Window window)
              if (window instanceof Dialog)
                Dialog d = (Dialog) window;
                if (d.isModal())
                  super.setActivationWindow(window);
                  return;
              super.setActivationWindow(null);
            public void setDisplayed(boolean b)
              //no exception here and shows dialog with no decorations
              super.setDisplayed(b);
              System.out.println("d: " + dialog);//prints null here
              System.out.println("d: " + frame); //prints null here
              if (b)
                if (dialog != null)//since this is true, it never sets decorations
                  dialog.hide();             
                  dialog.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
                  dialog.show();
          helpBroker.setFont(new Font("Verdana", Font.PLAIN, 12));
          helpListener = new HelpListener(helpBroker);
        catch (HelpSetException e)
          e.printStackTrace();
      }

    sorry guys, i should've posted it either in the web-start or on javahelp forums. I'll do it right now.
    never mind :-)

  • Invoke jar main method in java code

    hi
    i have a jar that has a usage like this
    java -jar helper.jar arg1 arg2 etc...i want to invoke this helper main method in my java code.i've tried using reflection but it didn't quite work...
    String[] args = new String[]{"arg1","arg2"};
    Class c = Class.forName("com.helper.MainClass");
    Method mainMethod = c.getMethod("main", args.getClass());
    int mods = mainMethod.getModifiers();
    if(mainMethod.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) {
         throw new NoSuchMethodException("main");
    mainMethod.invoke(null, args);
    Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at Test.callJarMain(Test.java:50)
    at Test2.main(Test.java:34)thoughts???

    phychem wrote:
    i want to use this jar in a non-static way.
    public void useJar(String args[]){
    //somehow invoke jar method here...
    Sorry, I still don't get it. I don't know what you mean by a non-static way of using jars. The main method for launching an application is static so if you call that method, you will be using a static method. I don't know what you mean by a "jar method" either. Methods are inside classes. So far, all I can guess is you want to invoke a method in a class that happens to be inside a jar. Since people do this all the time without reflection, I don't see the problem.

  • Invoke sql

    I am a new comer to IDM and I am starting a little RnD in Sun Java Identity Manager for an up and coming project. I am creating a rule using Business Process Editor (BPE). I am trying the invoke �<invoke name='sql' class='com.waveset.util.JdbcUtil'>� method with the Map constructor method. ../javadoc/com/waveset/util/JdbcUtil.html#sql(java.util.Map). All I am trying to do below is insert a row into a mysql DB with 4 bind parameters. I have successfully inserted a row with one bind parameter but when I add 2-4 bind parameters it always bombs on me and gives the output below. I can assure you all my values are set including arg 2. Any help would be appreciated.
    Also I have turned logging on in MySQL and honestly it is no help because I can only see the prepare statement in the logs. I assume that the exception occurs before the execution.
    --Snippet of Error�
    XPRESS <invoke> exception:
    com.waveset.util.WavesetException: Can't call method sql on class com.waveset.util.JdbcUtil
    ==> com.waveset.util.WavesetException:
    ==> java.sql.SQLException: Statement parameter 2 not set.
    at com.waveset.util.Reflection.invoke(Reflection.java:895)
    at com.waveset.util.Reflection.invoke(Reflection.java:833)
    at com.waveset.expression.ExInvoke.evalInternal(ExInvoke.java:171)
    at com.waveset.expression.ExNode.eval(ExNode.java:79)
    at com.waveset.expression.ExNode.evalToObject(ExNode.java:498)
    at com.waveset.object.Rule.eval(Rule.java:933)
    at com.waveset.ui.editor.rule.RuleTester.execute(RuleTester.java:268)
    at com.waveset.ui.editor.rule.ExpressionEvaluator$10.invoke(ExpressionEvaluator.java:597)
    at com.waveset.ui.editor.util.SwingUtil$InvokableWrapper.run(SwingUtil.java:1555)
    at com.waveset.ui.editor.util.ProgressDialog$2.run(ProgressDialog.java:101)
    Wrapped exception:
    Snippet of Rule
    <invoke name='sql' class='com.waveset.util.JdbcUtil'>
    <map>
    <s>type</s>
    <ref>type</ref>
    <s>driverClass</s>
    <ref>driverClass</ref>
    <s>driverPrefix</s>
    <ref>driverPrefix</ref>
    <s>url</s>
    <ref>url</ref>
    <s>host</s>
    <ref>host</ref>
    <s>port</s>
    <ref>port</ref>
    <s>database</s>
    <ref>database</ref>
    <s>user</s>
    <ref>user</ref>
    <s>password</s>
    <ref>password</ref>
    <s>sql</s>
    <s>insert into waveset.form (firstname, lastname, email, phone) value (?,?,?,?)</s>
    <s>arg1</s>
    <ref>firstname</ref>
    <s>arg2</s>
    <ref>lastname</ref>
    <s>arg3</s>
    <ref>email</ref>
    <s>arg4</s>
    <ref>phone</ref>
    </map>
    </invoke>

    Tip 1 : turn on tracing for the class com.waveset.util.JdbcUtil (I'm assuming you know how to do this)
    Tip 2 : instead of arg1, arg2, etc. try :
    <s>parameters</s>
    <list>
      <s>john</s>
      <s>smith</s
      <s>[email protected]</s>
      <s>1234</s
    </list>

  • Error while invoking Java Program in BPEL

    When I'm invoking a simple "Hello World" Java Program from BPEL it is working fine but while invoking a Java Program which is downloading some data from a website I'm getting the following error:
    Faulted while invoking operation "Helper" on provider "CMP_GBL_IN_URL_Download"
    <messages><input><Invoke_Helper_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload"><payload xmlns:ns1="http://www.arrow.com/CMP_GBL_IN_Exchange_Rate_Interface_Controller">
    <ns1:input/>
    </payload>
    </part></Invoke_Helper_InputVariable></input><fault><bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="summary"><summary>[email protected]0 : Could not invoke 'Helper'; nested exception is:
         org.collaxa.thirdparty.apache.wsif.WSIFException: No method named 'Helper' found that match the parts specified</summary>
    </part><part name="detail"><detail>org.collaxa.thirdparty.apache.wsif.WSIFException: No method named 'Helper' found that match the parts specified</detail>
    </part></bindingFault></fault></messages>
    Can anybuddy please help me on this.

    In what way do you invoke the Java program?
    Riko

  • Need Help in iPhoto '11 Help??

    Hi, i have updated my iPhoto '11 to Version 9.2.1 (628). And had to lookup a topic in iPhoto '11 Help, and it says "To see all iPhoto Help, you must be connected to the Internet". Then I tested Browse Help topics, and the result I get are all the same. So I quit the application. And restarted iPhoto '11. When into iPhoto '11 Help and pick any topic to test. The same "To see all iPhoto Help, you must be connected to the Internet". But I am connected to the Internet. Can somebody assist me.

    Hi & many thanks for the reply. I made sure that iPhoto is not running by looking ito Force Quit Applications window. I did 2nd time, as instructed. Just to inform you, i can see and have iCal Version 4.0.4 (1395.7) Help which connects to the internet when i invoke a help topic in iCal. I can see and have Aperture V3.2.1 Help open the Safari to connect to the Internet to show Help topics and solutions. I can access, read, and point at any Help Topics of every application i have installed and with internet connection. Maybe I maybe describing the problem as the computer says it.
    When I invoke iPhoto '11 Help, I can see the iPhoto '11 Help. But once I click say "Lesson 1..." I get the message of the Help on the right pane of the Help pane...

  • PaintComponent method refuses to be invoked.

    Hello All!
    I have a problem with graphics representation by swing. Namely I have an application based on Jframe object. It includes three Jpanel components. I need to map information from Jtable as diagram in the plotPanel. That�s code fragment I try to use:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JComponent.*;
    import java.lang.*;
    import java.io.*;
    * @author  Administrator
    public class ROC extends javax.swing.JFrame{
    public ROC() {
            initComponents();
    /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            menuPanel = new javax.swing.JPanel();
            openButton = new javax.swing.JButton();
            tablePanel = new javax.swing.JPanel();
            pointsTable = new javax.swing.JTable();
            generateButton = new javax.swing.JButton();
            plotPanel = new javax.swing.JPanel();
            plotPanel.add(new PlotArea(), java.awt.BorderLayout.CENTER);
    ������ //This is a piece of code to initialize other components
            plotPanel.setLayout(new java.awt.BorderLayout());
            plotPanel.setBackground(java.awt.Color.white);
            plotPanel.setPreferredSize(new java.awt.Dimension(600, 380));
            plotPanel.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
            plotPanel.addContainerListener(new java.awt.event.ContainerAdapter() {
                public void componentAdded(java.awt.event.ContainerEvent evt) {
                    plotPanelComponentAdded(evt);
            getContentPane().add(plotPanel, java.awt.BorderLayout.CENTER);
            pack();
    ������  // Different functions (such as loading data from the file to JTable i.e.)
           public static void main(String args[]) {
            System.out.println("Application starts");
            new ROC().show();
        // Variables declaration - do not modify
        private javax.swing.JPanel menuPanel;
        private javax.swing.JButton openButton;
        private javax.swing.JPanel tablePanel;
        private javax.swing.JTable pointsTable;
        private javax.swing.JButton generateButton;
        private javax.swing.JPanel plotPanel;
        // End of variables declaration
    public class PlotArea extends javax.swing.JComponent{
        /** Creates new plotPanel */
        public PlotArea() {
            System.out.println("PlotArea has been created");
            setPreferredSize(new java.awt.Dimension(600, 380));
            setMinimumSize(new java.awt.Dimension(200, 100));
            super.setBorder(BorderFactory.createLineBorder(Color.red, 5));
            repaint();
        public void paintComponent(java.awt.Graphics g) {
            System.out.println("PaintComponent method has been invoked");
            Graphics2D g2d = (Graphics2D)g;
    ������ // this is the code to implement custom painting
    }The trouble is that PaintComponent method hasn�t been invoked. Help me please. What should I do to cause PaintComponent to be performed?

    You might want to ensure your "plotPanel" uses a BorderLayout if you're specifying a constraint:
    plotPanel = new javax.swing.JPanel(new BorderLayout());
    plotPanel.add(new PlotArea(), java.awt.BorderLayout.CENTER);You shouldn't need to call "repaint" in the constructor of PlotArea, either. I doubt it'll make any difference.
    Hope this helps.

Maybe you are looking for

  • Is it possible to have two different back ups for my iPhone 4S? One in my laptop and one in iCloud?

    I want to restore my iphone 4S with a back up present in my laptop since I want to retrieve a file from that restore point. But first, I want to back up the current state of my phone to iCloud, thinking that it may be possible, so that I can retrieve

  • CS5 no longer shows up under all documents in vista??

    As of today my photoshop desktop icon diappeared and when I open "all programs" under start Photoshop shows up like this instead of just photoshop: However, in Programs & Features it shows as Adobe Photoshop. Any help to fix this would be greatly app

  • "Save as pdf" button from InDesign

    Is it possible to make a "save as pdf" button from InDesign ? Best regards, Mette Louise

  • Cannot connect to db using toad

    hi , I get the following error while I try to connect my db using toad and windows sql ========================================================= Fatal OSN connect error 12203, connecting to: (DESCRIPTION=(CONNECT_DATA=(SID=INS)(CID=(PROGRAM=TOAD.exe)

  • Can't open Pagemaker 7 in InDesign 2

    Hi, When I try to open a Pagemaker 7 file in Adobe InDesign 2, I keep getting a message that says "Cannot open Adobe inDesign may not support the file format or a plug-in may be missing. The reason I am trying to convert the file to InDesign is becau