Anything wrong with the code to call method of an external class ??

I have written this code to invoke metod1 in MethodList.java. :
import java.io.File;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import com.sun.org.apache.bcel.internal.util.ClassLoader;
public class RunMthdRef
public static void main(String[] args)
URLClassLoader loader = null;
     File file = new File("C:\\Documents and Settings\\227951\\workspace\\Methodcaller\\");
     String classpath = System.getProperty("java.class.path") + System.getProperty("path.separator") + file.getPath();
     System.setProperty("java.class.path",classpath);
     try
loader = new URLClassLoader(new URL[]{file.toURL()});
     catch (MalformedURLException e)
// TODO Auto-generated catch block
e.printStackTrace();
     Thread.currentThread().setContextClassLoader(loader);
     try
          Class B=loader.loadClass("MethodCaller.MethodList");
          Object objectInstance = B.newInstance();
          Method startup =B.getMethod("Method1", null);
startup.invoke(objectInstance,null);
     catch (Exception e)
          e.printStackTrace();
I want to invoke the Method1 in this class present in the same project :
public class MethodList {
     // declaring method 1
     public void Method1()
          Method2();
          Method4();
     // declaring method 2
     public void Method2()
          Method3();
//     declaring method 2
     public void Method3()
          System.out.println("End of method list");
     // declaring method 4
     public void Method4()
          Method3();
     * @param args
}

I have written this code to invoke metod1 in MethodList.java. :Why?
import com.sun.org.apache.bcel.internal.util.ClassLoader;Why?
     System.setProperty("java.class.path",classpath);That won't work. It's read-only, and too late to set it anyway.
          Class B=loader.loadClass("MethodCaller.MethodList");If 'MethodCaller' is the name of a package you need to study the standard Java coding conventions. Google will find them.
          Object objectInstance = B.newInstance();
          Method startup =B.getMethod("Method1", null);
startup.invoke(objectInstance,null);Do you really have to do all this reflectively?
I want to invoke the Method1 in this class present in the same project :If it's in the same project why do you need reflection? and dynamic class-loading?

Similar Messages

  • What's wrong with the code?

    public void run()
    try
    {     for(;;)
         mgr = (RTPManager)RTPManager.newInstance();
         mgr.addSessionListener(this);
         mgr.addReceiveStreamListener(this);
         try{  /*****port1 = port2 = 29261, which port is only used in here
         localAddr = new SessionAddress(InetAddress.getLocalHost(), port1);
         destAddr = new SessionAddress(ipAddr, port2);
         }catch(Exception e)
              System.out.println(e + " 4");
         try{
         mgr.initialize(localAddr);
         }catch(Exception e)
         System.out.println(e + " 5");
         //set buffer
         bc = (BufferControl)mgr.getControl("javax.media.control.BufferControl");
         if (bc != null)
         bc.setBufferLength(20);
         try{
              mgr.addTarget(destAddr);
         }catch(Exception e)
         System.out.println(e + " 2");
    catch(Exception e)
         System.out.println(e+ " 3");
    the error when i run the code is like that:
    javax.media.rtp.InvalidSessionAddressException: Can't open local data port: 29261
    5
    java.io.IOException: Address already in use: Cannot bind 2
    which means there is error in :
    mgr.initialize(localAddr);
    mgr.addTarget(destAddr);
    But i don't know what's wrong with the code,
    can any one help me?

    I do not find any problem using the same ports for local and destination address with several unicasts. My problems are others.
    But note that the error is even at constructing the localAddress, I mean before trying the destinationAddress. Thus the reason cannot be the former is already in use. In fact I think the later belongs to a remote hosts. Likely, it is trying to access the destinationAddress through the localAddress, but this has not been constructed properly.

  • Red highlight next to code in dreamweaver. What is wrong with the code and is it affecting the websi

    What is wrong with the code and is it affecting the website?

    Line 107 looks dodgy to me and it won't have any effect on your code.  However, it is a good idea to post a complete link to your CSS for us to see it in full and to validate it using external tools.  In fact, you could validate the CSS (and HTML) yourself..
    <http://jigsaw.w3.org/css-validator/>
    Good luck.

  • I'm trying to add the system date with a Label. What is wrong with the code

    import java.util.*;
    import javax.swing.*;
    public class CurrentDateApplet extends JApplet
         Calendar currentCalendar = Calendar.getInstance();
         JLabel dateLabel = new JLabel();
         JPanel mainPanel = new JPanel();
         int dayInteger = currentCalendar.get(Calendar.DATE);
         int monthInteger = currentCalendar.get(Calendar.MONTH)+1;
         int yearInteger = currentCalendar.get(Calendar.YEAR);
         public void init()
              mainPanel.add(dateLabel);
              setContentPane(mainPanel);
              dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
                        (Calendar.MINUTE);
    }

    As for what's wrong with the code, it would be easier if you said: it doesn't show the date (it does this instead), it doesn't compile (I get this message) etc.
    Anyway I'll assume you want to display the time in a label...
    dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
    (Calendar.MINUTE);This won't compile: the parentheses are mismatched, and there is simply no such thing as append(). So we could trydateLabel.setText("" + currentCalendar.get(Calendar.HOUR) + currentCalendar.get(Calendar.MINUTE));This wroks, but looks pretty nasty and it's not how you are supposed to format dates and times. Here's the unofficial party line, nicked from one of jverd's posts:
    Calculating Java dates: Take the time to learn how to create and use dates
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format
    From those links you should be able to find those applicable to times like this: http://www.exampledepot.com/egs/java.text/FormatTime.html
    Using this approach you would end up with something like:import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CurrentDateApplet extends JApplet
        private Date date;
        private JLabel timeLabel;
        private JPanel mainPanel;
        public void init()
            mainPanel = new JPanel();
            timeLabel = new JLabel();
            mainPanel.add(timeLabel);
            setContentPane(mainPanel);
            date = new Date();
            Format formatter = new SimpleDateFormat("HH:ss a");
            timeLabel.setText(formatter.format(date));
    }

  • Whats wrong with the code?????

    Hi All
    Pls can anyone help me, what is wrong with the below code, when ever i tried giving 10 digit number to chk out whether it is prime or not it is giving an NumberFormatException to me, pls can anyone help me...
    class PrimeNo{
    public static void main(String args[])
    int a = Integer.parseInt(args[0]);
    int count=0;
    for(int i=2;i<a;i++){
    if(a%i==0)
    System.out.println(a+" is not a Prime Number");
    count = 1;
    break;
    if(count==0)
    System.out.println(a+" is a Prime Number");
    Thnx and rgrds
    Badri

    Just curious, since this has already been answered, but to simplify code, would it be possible to set it so that if the value is not a prime number, just do the value like so:
    if (//code determines it is prime)
    System.out.println ("prime number");
    else
    prime = !prime;
    if(!prime)
    System.out.println ("not a prime number");not really code there, more pseudocode, but you get my drift. Would this make sense to do?

  • Problems with webfonts in Dreamweaver - Is anything wrong with my code?

    I'm working on a site in DW and I'm having some issues with the webfonts I'm using. I'm new to the program, so I'm still working my way around, but I think it might be something with my code. Can you guys help me out?
    Background info:
    - The area affected is a three-column area of the main page.
    - I'm trying to use the webfonts so that the webfonts pop up as the text in all three columns.
    - The problem is that the webfonts are only being applied to one part of the text on one of the columns.
    - I'm using two webfonts on two parts of each column: One font for the title text, and one font for the main text.
    - The code is from the index.html script and was done with Dreamweaver CS6 on a Windows 7 PC.
    The code:
    <div id="overview">
        <span style="font-size: 32px; font-family: MuseoSlab;">Overview </span>
      <p>Roblox Networks Television Corporation, also known as Roblox Networks or RN, is the owner and operator of television properties broadcasting to the members of Roblox, an online game. Our properties include television channels such as RN1, interactive properties such as rnone.tk and rnanytime.tk, and studios and production facilities such as rnUS.</p></span>
      </div>
      <div id="viewers">
        <span style="font-size: 32px; font-family: MuseoSlab;">For viewers</span>
        <span style="font-family: MuseoSans;">
        <p>Viewers can access RN's consumer properties via the links below.</p>
        <p>RN1 Homepage</p>
        <p>RN Anytime Homepage</p>
        <p>RN1 TV Listings</p></span>
      </div>
      <div id="showchannelowners">
        <span style="font-size: 32px; font-family: MuseoSlab;">For program and network owners</span>
        <span style="font-family: MuseoSans;">
        <p>Program and network owners looking to broadcast with or become a partner of the Roblox Networks Television Corporation can contact RN by these methods:</p>
        <p>rnUS | Email | Roblox |</p>
        <p>rnUK | Email | Roblox | </p>
        </span>
      </div>
    Any way you guys can help?

    Update:
    Uploaded to a testing server at http://rntestsite.6te.net/ and the problem seems to be fixed. Maybe it's just an issue with the program.

  • What is wrong with the code? (JOptionpane)

    I tried to run the program "AddingNumbers.java", but i always get error message, can anyone tells me what is wrong?
    Here is the code:
    import javax.swing.JOptionpane;     //import class JOptionpane
    public class Addition {
    public static void main( String args[])
         String firstNumber, secondNumber;
         int number1, number2, sum;
         firstNumber =
         JOptionpane.showInputDialog( "Enter first integer");
         secondNumber =
         JOptionpane.showInputDialog( "Enter second integer");
         number1 = Integer.parseInt( firstNumber);
         number2 = Integer.parseInt( secondNumber);
         sum = number1 + number2;
         JOptionpane.showMessageDialog(
         null, "The sum is " + sum, "Results",
         JOptionpane.PLAIN_MESSAGE );
         System.exit( 0 );
    The error messages are:
    import javax.swing.JOptionpane; //import class JOptionpane
    ^
    AddingNumbers.java:12: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.showInputDialog( "Enter first integer");
    ^
    AddingNumbers.java:15: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.showInputDialog( "Enter second integer");
    ^
    AddingNumbers.java:24: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.PLAIN_MESSAGE );
    ^
    AddingNumbers.java:22: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.showMessageDialog(
    ^
    6 errors
    Thanks.

    Hi, noah.w: can you help me for this code? it has error, too.
    the code:
    import javax.swing.JOptionPane;
    public class Comparison {
    public static void main( String args[])
         String      firstNumber,
              secondNumber
              result;
         int number1,
         number2;
         firstNumber =
         JOptionPane.showInputDialog( "Enter first integer");
         secondNumber =
         JOptionPane.showInputDialog( "Enter second integer");
         number1 = Integer.parseInt( firstNumber);
         number2 = Integer.parseInt( secondNumber);
         result = " ";
         if (number1 == number2 )
         result = result + number1 + " == " + number2;
         if (number1 != number2 )
         result = result + number1 + " != " + number2;
         if (number1 < number2 )
         result = result + "\n" + number1 + " < " + number2;
         if (number1 > number2 )
         result = result + "\n" + number1 + " > " + number2;
         if (number1 <= number2 )
         result = result + "\n" + number1 + " <= " + number2;
         if (number1 >= number2 )
         result = result + "\n" + number1 + " >= " + number2;
         JOptionPane.showMessageDialog(
         null, result, "Comparison Results",
         JOptionPane.INFORMATION_MESSAGE );
         System.exit( 0 );
    the error is:
    result = result + "\n" + number1 + " <= " + number2;
    ^
    Comparison.java:40: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    result = result + "\n" + number1 + " <= " + number2;
    ^
    Comparison.java:43: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    result = result + "\n" + number1 + " >= " + number2;
    ^
    Comparison.java:43: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    result = result + "\n" + number1 + " >= " + number2;
    ^
    Comparison.java:46: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    null, result, "Comparison Results",
    ^
    15 errors
    How can i get the full screen of the messages? the DOS always shows the end part of the screen and i can't go back to take look the begainning of the errors.
    Thanks again.

  • Something's wrong with the code on my "educard".

    I recently bought one of those membership cards. I've entered my information, and I know the code I entered is right, but it keeps saying "The code you entered is invalid. Please try again."

    contact adobe support, http://www.adobe.com/support/chat/ivrchat.html

  • Still trying to center the text of the jTextP. What is wrong with the code?

    The Code:
    JTextPane jTextPane1 = new JTextPane();
    MutableAttributeSet mas;
    mas=new SimpleAttributeSet();
    StyleConstants.setAlignment (mas, StyleConstants.ALIGN_RIGHT);
    jTextPane1.setCharacterAttributes(mas,false);
    jTextPane1.setText("message");
    The code doesn't align the text.
    Please HELP MEEEEEE
    Thanks.

    I've found the solution!!!!!!!!!!!!!!!!!!!!!
    insted of:
    jTextPane1.setCharacterAttributes(mas,true);
    you have to use:
    jTextPane1.setParagraphAttributes(mas,true);
    yuhuuuuuuuuuuuuuuuuuuuuuu!!!!!!!

  • What is wrong with the code II?

    The code below did not display "test" as expected. Why and how
    to fix it? Thanks.
    import java.awt.*;
    import javax.swing.*;
    public class component extends JFrame
    public component()
    setTitle("add component test");
    Container c = getContentPane();
    ComboBoxTest cc = new ComboBoxTest("test");
    c.add(cc);
    setSize(200, 200);
    setLocation(400, 300);
    public static void main(String [] args)
    component c = new component();
    c.show();
    class ComboBoxTest extends Component
    public ComboBoxTest(String s)
    a = new Label(s);
    private Label a;

    The code below did not display "test" as expected. Why
    and how
    to fix it? Thanks.I assume you mean the Label that has the text, test. If that's right, there isn't any code in ComboBoxTest that causes the Label to be displayed. I think you should extend something like JPanel instead of Component and add a JLabel to the JPanel.

  • ITunes recently decided my debit card's security code in invalid.  But nothing is wrong with the code or my card.  how do I fix this?  Apple support doesn't have a clue what they are doing and will not call me to fix this.

    My bank sent me a new Debit card because of some security issue.  It has the same number as my previous card but new experation and new security code. It worked fine for months then all of a sudden Itunes decided the security code is invalid.  Now I can't even update my phone. 
    For the last week I have been going back and forth over email with apple support to fix it, but they keep telling me the same fix that doesn't work and frankly they are the worst support group I have ever worked with.  I can't even get anyone to answer a phone, its just back and forth by email everyday.

    Debit card? Are you sure?
    USA iTunes Store does not appear to accept debit cards - http://www.apple.com/legal/itunes/us/terms.html  "The iTunes Store, Mac App Store, App Store, and iBookstore services (“Services”) accept these forms of payment: credit cards issued by U.S. banks, payments through your PayPal account, iTunes Cards, iTunes Store Gift Certificates, Content Codes, and Allowance Account balances."

  • Anything wrong with my code???

    My code is listed as below:
    *Plug is an interface, implemented by all other plugins
    String plugName = request.getParameter("plugins");
    ClassLoader classLoader = new ClassLoader();
    Class c = classLoader.loadClass(plugName);
    Object obj =c.newInstance();
    Plug p =(Plug)obj;
    p.change(pixels,w,h);
    it can be complied, but it does not work properly for some reason. Why? thanks

    sorry, that is my fault not making it clear. ihave
    tried a
    out.println(plugName); and it returns the correct
    class name;
    and also, if i do like this
    ImagePlugin1 p = new ImagePlugin(); the wholething
    works;
    because this is a servlet, so when i said "it isnot
    working", it refers to nothing shows up in the
    screen, although i have try, catch.What is the value of plugName? "ImagePlugin"? It
    needs to be a real class name. Unless
    ImagePlugin doesn't belong to a package, that
    wouldn't be its real class name. It needs to be
    something like "some.package.name.ImagePlugin" - it
    has nothing to do with whether you've imported that
    package or not.
    As far as "nothing shows up in the screen" - that's
    still very vague. You're probably just eating the
    exception then (like catch(Exception e) {} ) ? Stop
    doing that. Either let the exception propogate up to
    the caller (the app server), or make it show the
    stack trace, by calling e.printStacktrace() in that
    catch block. Then you'd be in less of a pickle.
    You've shot yourself in the foot if you silently
    caught (ignored) exceptions.oh, yes, i forgot the package name, and now it is working with yours
    Class c = Class.forName(plugName);
    but mine
              MyClassLoader classLoader = new MyClassLoader();
              Class c = classLoader.loadClass(plugName);
    still not working, and very wierd, it does not show any exceptions although i have e.printStackTrace();

  • Anything wrong with the iPhone

    im thinking about getting an iphone, maybe around christmas but not now, but does anyone have any problems with it? bad internet connections? bad service from AT&T? is the phone lacking anything that would make it better? should i wait until a second iphone comes out or should i go ahead and get this one? any problems you have would help with my decision.

    Yes Nicole, that is right.... there are many Web 2.0 apps popping up on the internet, and daily. Some of them are useful (IM apps that allow iChat functionality), some are wacky and amusing, some are fun (games).
    I also don't send MMS picture txt messages. I'd rather email, personally
    It's difficult to say exactly how Apple will handle software updates, but yes, they will be free (they don't charge for these).
    Software updates may (i say 'may') bring functionality to the iPhone such as iChat or a new widget....or perhaps add featuers like cut/copy/paste or file storage or editing.
    3G is the latest FAST wireless network used by most cell carriers (or starting to be used by most carriers) for cell phones. The reason why Apple choose not to use 3G right now (Smart move, by the way), is because of power drain on the batter, design issues and the lack of 3G everywhere.
    Right now, the slower (yet perfectly usable) EDGE network, (sometimes referred to as 2.5G) is available just about anywhere you have AT&T (Cingular) coverage.
    I live in a big city and i have perfect coverage just about everwhere i go. If i'm stuck in traffic, i can pull up Google Maps/Traffic or open Safari and go to: sigalert.com and find a new route.
    If i need to lookup a business, i can use google maps and get the phone, address, web info and connect the phone call very easily.
    These are just a couple of the nice features
    Remember, do some homework and find out if you have good AT&T coverage in the areas you'll be using the iPhone, such as work, home, school, friends, public, highways, towns, etc.

  • Anything wrong with the latest amarok package?

    Hi,
    after the latest update amarok refuses to start. This is what the error message says:
    $ cd /pfad/zu/Amarok/Quellcode/
    $ su -c "make uninstall"
    $ cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` && su -c "make install"
    $ kbuildsycoca4 --noincremental
    $ amarok
    Is there something wrong the the package itself?

    Ok,
    with this PKGBUILD:
    pkgname=amarok
    replaces=('amarok-base' 'amarok-engine-xine' 'amarok-base-mysqlfree')
    pkgver=2.4.1
    pkgrel=2
    pkgdesc="The powerful music player for KDE"
    arch=("i686" "x86_64")
    url="http://amarok.kde.org"
    license=('GPL2' 'LGPL2.1' 'FDL')
    depends=('kdebase-runtime' 'mysql' 'qtscriptgenerator' 'taglib-extras'
    'liblastfm' 'ffmpeg' 'libofa' 'qjson')
    makedepends=('pkgconfig' 'automoc4' 'cmake' 'libgpod' 'libmtp' 'loudmouth'
    'libmygpo-qt')
    optdepends=("libgpod: support for Apple iPod audio devices"
    "libmtp: support for portable media devices"
    "loudmouth: backend needed by mp3tunes for syncing"
    "ifuse: support for Apple iPod Touch and iPhone"
    "libmygpo-qt: gpodder.net Internet Service")
    install="${pkgname}.install"
    source=("http://download.kde.org/stable/${pkgname}/${pkgver}/src/${pkgname}-${pkgver}.tar.bz2")
    md5sums=('4c65c5cd4d7bd267bdbef8e912fd6cb6')
    build() {
    cd ${srcdir}
    mkdir build
    cd build
    cmake ../${pkgname}-${pkgver} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr\
    -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix`
    make
    package(){
    cd ${srcdir}/build
    make DESTDIR=${pkgdir} install
    and this amarok.install
    post_install() {
    xdg-icon-resource forceupdate --theme hicolor &> /dev/null
    kbuildsycoca4 --noincremental
    post_upgrade() {
    post_install
    post_remove() {
    post_install
    I was able to build a working package.
    Maybe I should have tried it without a new amarok.install but I just made everything that was suggested in the error message

  • Anything wrong with the app wedict-pro 2.0.1 ?

    I just purchased that app. It supposed to have the Eng-Viet Viet-Eng dict and it does. But when I typed the word it only tranlated into Chinese and English. I also checked the setting and dictionaries and nothing wrong. I marked all the dictionnaries include the Eng-Viet Viet-Eng, so I don't know what's going on with that app , please help

    Either the app will give a website or other information about the developer (typically in settings for that app) or go to the App Store and it will give a website. If you go to your purchase history/receipt for that purchase it has instruction of who to contact abut problems.

Maybe you are looking for

  • Reporting Services Point - possibly permissions issue

    I'm having a really hard time configuring a working reporting services point in my test SCCM 2012 R2 environment and was hoping someone might be able to help me work out what's gone wrong. My servers are WS2008 R2.  SQL Server 2008 R2 is installed on

  • Missing media from itunes purchases

    I'm not sure what to do here. I have two Apple IDs and I can't remember one of them. If I search for it it only gives me the option of changing my password for the current one I do remember. I'm missing 8 seasons of a show that was linked to my Apple

  • Missing Cellular Data tab in iPhone 3G

    Hi everyone, Im just wondering why my iPhone 3G doesn't have the cellular data tab, not the cellular data network tab is there anyway i can bring this back? thanks!

  • Old iPhone sync at odds with other cloud devices?

    Hello My wife's "old" iphone 3g has iOS 4 that does not support iCloud, and I guess Apple won't update the iOS for that model anymore? All my other relevant devices and my main computer have been moved to iCloud and so my contacts etc are in the clou

  • CTS+ Transport Strategy

    Dear all, We are planning to setup CTS+ in our system landscape. Please provide your inputs, on the pros and cons of this strategy. Also direct me to links of CTS+ documents on SDN.  Thanks for the help. Regards, Younus