How to execute a class Indirectly
Hello All,
Is there a way to call a class indirectly? I tried Reflection but had no success. Below is how I call login now, and then my attempt with Reflection. Any and all help would be greately appreciated. Thanks in advance.
new login();
Class c = Class.forName("login");
new c();
Is there a way to call a class indirectly? I tried
Reflection but had no success. Below is how I call
login now, and then my attempt with Reflection. Any
and all help would be greately appreciated. Thanks in
advance.
new login();
Class c = Class.forName("login");
new c();You don't "call" a class. What you did there in the first line of code, that loaded the class. The second line isn't valid Java, as the compiler told you. If you want to create a new instance of that class, then you do something like this:Object x = c.newInstance();assuming that your class has a public constructor with zero arguments.
However the chances are you are on the wrong track with this question. Perhaps you'd like to post the original question, the one that "calling a class indirectly" was supposed to be the answer to?
Similar Messages
-
How to Execute different classes using editplus
Consider a program like this
class abc
public static void main(String args[])
System.out.println("abc");
class bbc
public static void main(String args[])
System.out.println("bbc");
In this program there are two classes when i compile this code in editplus i wont get any error but if i want to execute only ABC class how to do that in editplus because in editplus we usually set the file name for JAVA execution
But here it is different SO,how to execute different classes in a program which is saved with arbitary name in EDIT PLUS..Try reading an editplus FAQ or posting to an editplus forum or even searching through help in editplus.
-
How to execute a class wich is not in the classpath
Sometime the server can't be shutdown and, if You add some new classes to Your system there's a classpath problem : in the classpath OC4J doesn't see new classes
How can we solve that problem ?
Is it possible to execute something wich is not in the classpath ?
Can the classpath be changed at runtime ?
TIA
TullioPlease look at the following paper http://otn.oracle.com/tech/java/oc4j/pdf/ClassLoadingInOC4J_WP.pdf
tha describes how does classloading work in OC4J.
You can deploy application using opn expanded directory structure if you are using OC4J standalone.
Also you donot have to restart the server when classes are changed, you have to touch the application.xml for your application or web.xml for Web module to redeploy the apps.
regards
debu -
How to execute a jar file which has an applet, without using a html file ?
I have a jar file which contains a set of class files. iam able to execute the jar file by using this html code
<html>
<applet code="file.class" archive="file.jar" width="500" height="300">
<param name="name" value="value">
</applet>
</html>
I want to know how to execute this class file without using the html tags.
pls help me out in this.
AnkiHi,
You can make an executable jar file such that when you double click on that it starts running. Just follow the steps.
1. Open a notepad and write the following
Main-Class: XXXXXXXX
XXXXXXX means Your Main Class name. Don't forget to press Enter after you write your class name.
2. Save the file as Mani.mf
3. In the commant prompt ( your directory ) type following lines.
jar cmf Mani.mf Demo.jar *.*
4. This will make a jar file which is executable jar file
Hope this will help you.
Deepak -
Executing a .class file
Hi all,
Can anyone help me about how to execute a ".class" file from within a java Program. Thanks in advance
Regards,
Deepani have a class file in "c:\sample.class" i want to
run this class file from my program. How to achieve
this? i am a newbie kindly bear with me..the reason you're not getting a straightforward answer is that this is the sort of thing you can find out for yourself in the tutorials, or from your teacher, or a book, or a simple google query. the forum isn't the place for complete novices to learn from, that would be a waste of effort on everybody's part
get reading! -
How to execute the method of a class loaded
Hi,
I have to execute the method of com.common.helper.EANCRatingHelper" + version
version may be 1,2, etc
if version = 1 the class is com.common.helper.EANCRatingHelper1;
Iam able to load the class using following code.But iam unable to execute the method of the above class
Can anybody help me how to execute the method of the class loaded.
Following is the code
String version = getHelperClassVersion(requestDate);
String helperClass = "com.redroller.common.carriers.eanc.helper.EANCRatingHelper" + version;
Class eancRatingHelper = Class.forName(helperClass);
eancRatingHelper.newInstance();
eancRatingHelper.saveRating(); This is not executing throwing an error no method.
ThankseancRatingHelper.newInstance();Ok, that creates an instance, but you just threw it away. You need to save the return of that.
Object helper = eancRatingHelper.newInstance();
eancRatingHelper.saveRating(); This is not executing throwing an error no method.Of course. eancRatingHelper is a Class object, not an instance of your EANCRatingHelper object. The "helper" object I created above is (though it is only of type "Object" right now) -- you have to cast it to the desired class, and then call the method on that.
Hopefully EANCRatingHelper1 and 2 share a common interface, or you're up the creek. -
How to execute a jsp instruction from a java class?
How to execute a jsp instruction from a java class?
Any help please.
Thank'sI'll detail my problem:
Supposing that I have a jsp file called: start.jsp
In the start.jsp I instanciated an object called global from the class Global ( for example ).
Then, I called a custom taglib:
<ix:mytag/>
In the suitable tld file: the mytag is defined:
<tag>
<tag class>Tag1<.....
The java file Tag1 has method:
doStartTag(){
// here is the problem
global.doSomeFunctions();
Okay, the problem is that the object gobal is not defined in the class Tag1. what to do?
I think that I have to pass the object global as a parameter to the class Tag1. How to do that?
Actually, the problem was to insert the follwoing in the doStartTag method:
doStartTag(){
pageContext.getOut().print("<%= hello world %>");
The output is <%= hello world %> not hello world.
Okay, the new problem is how to pass an object as a parameter to a class called from a tld file.
Any help please.
Thank's too much -
How to execute (F8) this class?
Hi
I have quick question . I am trying to execute (F8) class CL_RSPLS_ENQ but it gives me error (Syntax error - Display generated test environment?). If I check class code , it does not give me syntax error. I wish to excute READ_LOCKS .I would prefer to excute using F8 .
Any help will be great help
Thanks
AGHello Al
The problematic parts of this class are its constants that are of type TN_S_CHASEL-OPT. The coding below shows the syntax error within the testing report:
G_C_OPT_CLOSED
type TN_S_CHASEL-OPT,
G_C_OPT_OPEN
type TN_S_CHASEL-OPT,
G_C_OPT_L_OPEN
type TN_S_CHASEL-OPT,
G_C_OPT_R_OPEN
type TN_S_CHASEL-OPT,
I tried to test this class using eCATT but got the same syntax error.
However, I believe that if the typing of these constants is changed from TN_S_CHASEL-OPT -> RSPLS_S_CHASEL-OPT (DDIC structure) the testing of the class should be possible.
Regards
Uwe -
How to convert a class file to exe file and how to cteate a class file to d
how to convert a class file to exe file
Hi Bhaskarq,
Hi,
It is not at all possible.
But it is a really worst method.
Please go through it.
This is a very common question asked in the comp.lang.java newsgroup. Its often useful to have an
executable application when deploying your
applications to a specific platform, but remember to
make your .class files available for users running
Unix/Macintosh/other platforms.
Microsoft provide a free system development kit (SDK),
for Java, which includes the jexegen tool. This
will convert class files into a .EXE form. The only
disadvantage is that users need a Microsoft Java
Virtual Machine (JVM) installed. If your target
platform is Win32, you can either redistribute the
virtual
machine, or raise the level of your system
requirements, to include Windows 98, or Windows 95
with
Internet Explorer 4. Systems matching these
requirements will already have a copy of the Microsoft
Java Virtual Machine installed.
Note : You must specify all of the class files your
application needs (except for standard java packges)
as a parameter, so if you have third party libraries,
you'll need to include them as well. You can use wildcards * though, and you don't need the original source code.
Also please see this Forum which will give a good idea
http://forum.java.sun.com/thread.jsp?forum=31&thread=149733
I hope this will help you.
Thanks
Bakrudeen
Technical Support Engineer
Sun MicroSystems Inc, India -
Any 1 know how to convert a class to jar??
How to convert a class file to jar executable file??
Here's a jar tutorial.
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html -
Does any one know how to execute program in Jump developer desktop
hi,
Does any one know how to execute program in Jump developer desktop,
actually i copied the hello world project from my eclipse workspace to jump
developers workspace and once i run the program it asks for the main class
and then i gave main class as my HelloWorld Class,it generates error as
java.lang.NoSuchMethodError: main
Exception in thread "main"
Can any one help me to come out of this problem.....
Thanks
MRaji solved it,
thanks
MRaj -
How to execute CGI Programs in Tomcat Server
Hi,
I am working on executing Perl Scrtipts(or CGI programs) in Tomcat Server.
I have downloaded ActivePerl 5.8.0 6.0.3 build.I have modified some .jar files in tomcat\server\lib.
I have changed conf\web.xml to access the CGIServlet.class that is in servlets-cgi.jar.
My example.cgi is
#!c:\Perl\bin\perl.exe
print
"Content-type: text/plain\n\n";
foreach $var (
sort keys %ENV) {
print
"$var=\"$ENV{$var}\"\n";
@values = split(
/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) {
($varname, $mydata) = split(
/=/,$i);
print "$varname = $mydata\n";
and my test.html is
<HTML>
<HEAD>
<TITLE>Environment Variables using GET</TITLE>
</HEAD>
<BODY>
<FORM ACTION="cgi-bin/example.cgi" METHOD="POST">
Press submit for a list of environment variables. <BR>
First Name: <input type="text" name="fname" size=30><p>
Last Name: <input type="text" name="lname" size=30><p>
<input type="submit">
</FORM>
</BODY>
</HTML>
here I have changed url mapping in web.xml to cgi-bin.
The test.html produces two text fields first and last name on submit:
it accesses:http://localhost:8080/smalltownpapers/cgi-bin/example.cgi?fname=Tim&lname=Eden
this should print some environmental variables but it is producing an empty page.
Tomcat is not showing any errors or Tomcat is not at all listening.
Can any one help me to solve this and how to execute Perl scripts in Tomcat server
Thanks,
Regards
MurthySorry, I've never done this. I went to the Tomcat site and pulled down the CGI docs, which you might have seen:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/cgi-howto.html
No other help available from me. Sorry. -
How to call Java class from Forms 6i?
Hi friends,
I need to call a Java class from my Forms 6i application.
(It runs under WIndows XP. It's a client/server application and I have only the client and the Form builder installed on my PC)
I don't know almost anything about Java's world so your help would be very useful for me.
Could you tell me exactly what i have to do?
I've read in metalink several Notes, but they supposed that the Java architecture is already installed in the computer.... I only have the default installation of Developer 6i... so I would need to know:
- How to install/configure the neccesary to execute Java classes without problem
- How to invoke the .class from Forms 6i.
Thanks a lot
Jose.And also this one:
Problem Description
Installed Forms 6i Rel 2 on a MS Windows machine. When trying to Import the Java
Classes getting the errors
PDE-UJI0001 Failed to create the JVM
Solution Description
You need to to install JDK 1.2.2 to run the Java Importer. And set the PATH's
and classpath's correctly.
Explanation
1. Download and install the JDK 1.2.2.
Possibly available at: http://java.sun.com/products/archive/
2. Assuming the JDK 1.2.2 is installed in c:\jdk1.2.2 directory and the JRE in
C:\PROGRA~1\JAVASOFT\JRE\1.2 directory; ORACLE_HOME=C:\Dev6iR2.
Set the PATH to
set PATH=c:\jdk1.2.2\bin;C:\PROGRA~1\JAVASOFT\JRE\1.2\bin;C:\PROGRA~1\JAVASOFT\JRE\1.2\bin\classic;%PATH%
( If you are using ias9i then the JDK 1.2.2 comes with the ias installtion ,
in this case please set the PATH to
D:\ias9i\Apache\jdk\bin;D:\ias9i\Apache\jdk\jre\bin;D:\ias9i\Apache\jdk\jre\bin\classic;%PATH% )
3. Set the CLASSPATH to set CLASSPATH=%CLASSPATH%;C:\Dev6iR2\TOOLS\COMMON60\JAVA\IMPORTER.JAR;.
(If you do not set the CLASSPATH correctly you will get the error
PDE-UJI002 Unable to find the required java importer classes)
4. Now run the Forms Builder by using the command.
C:\Dev6iR2\bin\ifbld60.exe
Now the Java Importer Should Run fine.
Francois -
How to execute a PL/SQL in JAVA
I know how to execute a store procedure in PL/SQ. But how to execute a PL/SQL in JSP or other JAVA application?
Thank you!<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Chin Chia Liang ([email protected]):
I know how to execute a store procedure in PL/SQ. But how to execute a PL/SQL in JSP or other JAVA application?
Thank you!<HR></BLOCKQUOTE>
You should use CallableStatement.
import java.sql.*;
class StoreProc
public static void main (String args [])
throws SQLException {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =DriverManager.getConnection ("jdbc:oracle:thin:@testing:1521:test1", "scott", "tiger");
//create procedure and call it in java (testproc)
CallableStatement cstmt = conn.prepareCall("{call testproc(?,?)}");
cstmt.setString(1, "teststore");
(2, "testagain");
cstmt.executeUpdate();
cstmt .close();
conn.close();
catch(SQLException e)
System.out.println("SQLException caught: " + e.getMessage()+" "+e.getErrorCode());
null -
When i executed this class file i am getting runtime errors
when i executed this class file i am getting runtime errors
code is :
import java.awt.event.*;
import java.awt.*;
public class Test extends Frame
java.awt.Window w;
TextField t;
Test()
t=new TextField(20);
add(t);
addWindowListener(new WindowAdapter()
public void windowDeactivated(WindowEvent ev) {
w.toFront();
System.out.println("hai");
setSize(300,300);
setVisible(true);
public static void main(String args[])
Test t =new Test();
after executing that class i am getting this errors
Exception occurred during event dispatching:
java.lang.NullPointerException:
at WindowEventDemo.windowActivated(WindowEventDemo.java:76)
at java.awt.Window.processWindowEvent(Window.java:612)
at java.awt.Window.processEvent(Window.java:576)
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.Container.dispatchEventImpl(Compiled Code)
at java.awt.Window.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventQueue.dispatchEvent(Compiled Code)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)
if anybody know how to pls help meYou are using w that you have not done anything with.
Add following code to the begining of your cinstructor:
w = this;
Then it should work.
//Anders ;-D
Maybe you are looking for
-
Is there a solution to the disappearing cursor problem yet?
Recently upgraded my 12 core to Mountain Lion from Snow Leopard to install Media Composer. The disappearing changing cursor is driving me batty. Also My ProTools installation has become very unstable. It sometimes stops processing for about 30 second
-
SAP MDM 5.5 SP6 client installable
Hi All Can any one help me out in getting the installable for SAP MDM 5.5 SP6 client installable. I need that version.Also let me know, does it effect in any way if the build version of server is different from the cleint version. Thanks in
-
Won't sleep after install of wireless router
I bought a D-link WBR-2310 wireless router and installed it between the internet modem and my iMac. Everything is working good after configuring the router but my iMac won't sleep now. Its like the iMac is picking up a constant signal from the D-link
-
Re:Preferred Crystal report method
Hi, What is preferred/recommended method to migrate the Crystal reports from BO XI 3.1 enviorment. It is better with BIAR or RPT method. Thanks, Crystalfan Edited by: Crystalfan on Apr 4, 2011 6:58 PM
-
Config / Account Determination
Hi, In SPRO -> Sales and Distribution -> Basic Functions -> Account Assignment / Costing -> Revenue Account Determination -> Assign G/L accounts. Before the upgrade to ECC 6.0 (SP17) we had entries like 001 Cust.Grp/Mdse Catgry/AcctKey