Java package class access
Hi All,
I have two packages in a webapplication. com.mycompany.myapp and com.mycompany.myapp.classbank.
I set up the application so I have a package for re-usable classes(myapp.classbank) and the other for the backing beans for my pages and the session bean and application bean etc(myapp).
I can get access to any objects methods from the classes in myapp but I cannot get access to the methods in say the sessionbean from the classbank classes.
Code completion shows access to the sessionbeans methods but I always get a null pointer exception when the app is run / debugged.
Any insight would be most helpful.
Regards
Jim
Thanks All,
I can access any of the sessionbeans variables through the public getters and setters from any other class in the same package. If I try to access any of the same member variables from any class in the second package I get the null pointer... I can see each time the line of code that throws the exception. Its always the first line of code to try to access a getter or setter in the session bean from the second package.
An example error (Tomcat 5.5.17 NetBeans 5.5) from today below :
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:150)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92)
... 29 more
Caused by: java.lang.NullPointerException
at com.mycompany.imageshop.classbank.ShoppingBasket.setNumberOfPictures(ShoppingBasket.java:498)
at com.mycompany.imageshop.viewBasket.incSmallQuantityButton_action(viewBasket.java:1094)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146)
... 30 more
Oct 15, 2007 11:36:24 AM org.apache.catalina.core.ApplicationContext log
SEVERE: #{viewBasket.incSmallQuantityButton_action}: javax.faces.el.EvaluationException: java.lang.NullPointerException
javax.faces.FacesException: #{viewBasket.incSmallQuantityButton_action}: javax.faces.el.EvaluationException: java.lang.NullPointerException
Similar Messages
-
Compiling java package class referring a default package class.
I am trying to compile a java class having a package defination referring a java class with a default package.
The code for the default package class is .
public class Test{.
public static void main(String[] args){
System.out.println("Hello World!");
This class compiles fine.
I have another class called PackJava, whose code is :
package test;
import Test;
public class PackJava{
public static void main(String[] args){
Test test = new Test();
System.out.println("Hello World!");
I have Test file in the windows path
D:\development\packagetest\example
and the PackJava java file in the path
D:\development\packagetest\example\test
I have set the CLASSPATH environment varibale as
D:\development\packagetest\example;.
When I try to compile the PackJava from the
D:\development\packagetest\example path giving the command as
javac -classpath . test\PackJava.java
or
javac -classpath %CLASSPATH% test\PackJava.java
it gives me error,
Do any of you have an idea of the parameter i should pass
to the -classpath option
ThanksThere is a way around all this. The classes in the default packages need to implement an interface with the methods require. The interface can be in any package you want ie. com.work.around.interf.MyInterface1. Next, make this interface available in a Singleton. - The only catch here is that, the main method must reside in default package as well. And o, on start of main, instantiate the class you want and put it in the singleton. There after, you may refer to it from the singleton.
Enjoy. -
Java inner class access specifiers
public class MyClass1 {
public static void main(String argv[]){ }
/*Modifier at XX */ class MyInner {}
What modifiers would be legal at XX in the above code?
1) public
2) private
3) static
4) friendIam a newbie to javaI don't care. I still assume you have a brain and expect you to use it.
and iam struck with this
question, iam getting a compile time error for any
access specifiers mentioned as options, but the
answers given by my superior are 1,2,3, are
correct..Then you made a typo or whatever. Make sure you eliminate the problems that are not "illegal access modifier" errors.
What good is knowing the reply to this if you can't even write an example? -
Java Package/Class Dependency
Hi, friends,
I would like to get a list of packages that a given package depends on. If it is possible, I would also know which class of the given package depends on which classes.
Is there any software to do this?
If I would like to write a Java utility for that purpose, how can I proceed?
Best regards,
Youbinin the HTML fles of the java doc, you can know the class hierarchy and antecedents of each class. For example, class JComponent :
java.lang.Object
|
--java.awt.Component
|
--java.awt.Container
|
--javax.swing.JComponent
Moreover, the java doc also show the inner classes, fields and methods inherited from those super classes...
you may also know which classes extends this one. For example JComponent :
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
AbstractButton, BasicInternalFrameTitlePane, Box, Box.Filler, JColorChooser,
JComboBox, JFileChooser, JInternalFrame, JInternalFrame.JDesktopIcon, JLabel,
JLayeredPane, JList, JMenuBar, JOptionPane, JPanel, JPopupMenu, JProgressBar,
JRootPane, JScrollBar, JScrollPane, JSeparator, JSlider, JSpinner, JSplitPane,
JTabbedPane, JTable, JTableHeader, JTextComponent, JToolBar, JToolTip, JTree,
JViewport
vincent -
Can a servlet running on server A access a class defined on server B?
More information:
I am new at Java servlet programming and want to make sure that my web application is secure. I have set up a Java class that returns some user information (name, email address etc) and I have set up some jsp and servlet pages that access the class via an 'import my.class...' for servlets and a '@page import ="my.class..." 'for jsp. The jsp and servlet pages do session checking and authentication but the class does none of that - it's methods just return the requested data. I do not want to put any authentication in the class but I want to be certain that there is no way some other web server out on the internet could access this class in my web application. I do not think it is possible but my fear is that some hacker out there could somehow remotely do an @page import "my.class..." on my webserver and then gain access to my class methods? These web apps are running inside a Glassfish 3.0 app server.
Thanks!user479480 wrote:
That is very helpful info. I have been writing a lot of functional type code (updating, selecting and returning database data etc) inside Java servlets but when I get a new requirement I end up rewriting the same code in new servlet pages. So I have been thinking of putting all of that functional code in classes that I can re-use but was unsure of the security access and did not want to clutter the classes up with a bunch of session/authentication checking.
Do you recommend any books on J2EE Web programming? Thanks again for your assistance.Code re-use isn't a problem that way, because you can put your common code into a library jar and use it in as many JVMs as you like. What you can't do is to access any Java objects running in one JVM from another one, whether or not they are on the same machine. -
Where should i add the java packages class path in the ORACLEJDeveloper 10g
Hello friends,
I have created a BPEL Program using java embedding activity.
In it i have added some java code.
I want to attach path of some java class packages.
So can any one tell me solution for this.
Thanks and regards.
Ram Krishna Tripathi
[email protected]Hello friends,
I have made a Bpel program in oracle process manager 10.1.2 . using java
embedding activity.
(i) I have put the java class files in BPEL-INF /classes folder and
SYSTEM/classes folder but still compiler is giving error that classes
couldnot be found.
I have set the class path in Project -> properties
So please tell me what could be solution for this problem..
(ii) Can the import package statements can be written in BPEL program in the
java embedding activity ?
Thanks and regards
Ram Krishna Tripathi
[email protected] -
Anyone know of a Java package to access the Windows registry, ntfs acl, etc
I know Java is OS neutral but I was wondering if anyone has developed an open source or free group of java classes (probably C++ wrappers) to give you the ability to easily interface with Windows? I'm looking for ways to work with Windows users and groups, NTFS permissions, the Windows registry, the Windows API, etc. I saw a decent registry wrapper awhile back but I'm not sure about the rest!
@GeneAnthony wrote:
I know Java is OS neutral but I was wondering if anyone has developed an open source or free group of java classes (probably C++ wrappers) to give you the ability to easily interface with Windows? I'm looking for ways to work with Windows users and groups, NTFS permissions, the Windows registry, the Windows API, etc. I saw a decent registry wrapper awhile back but I'm not sure about the rest!JNI is a perfect+ candidate for this. Just write your own wrappers, or simply reference native win32 API. -
Understanding Java Class Accessibility
I don't understand what makes a Java library class accessible by a Java applet. If an applet has an import statement that imports, say, java.util.TreeMap, then when a web browser accesses a web page containing that applet, does it download the Java code for the TreeMap class at that time, and if so, does that mean that you have to package the TreeMap class as part of your applet class code somehow? Or, must the TreeMap class be installed as part of the Java virtual machine on the computer that is running the browser? If the latter, what determines whether or not the typical computer will have the TreeMap class available? Is the TreeMap class available on a PC running Windows XP, using the Java virtual machine that Microsoft supplies? Where can I read about this sort of thing? How can I determine what classes I can safely use if I want my applet to run on both Windows and Macs?
"I don't understand what makes a Java library class accessible by a Java applet. If an applet has an import statement that imports, say, java.util.TreeMap, then when a web browser accesses a web page containing that applet, does it download the Java code for the TreeMap class at that time, and if so, does that mean that you have to package the TreeMap class as part of your applet class code somehow? "
No.
"Or, must the TreeMap class be installed as part of the Java virtual machine on the computer that is running the browser?"
Yes
"If the latter, what determines whether or not the typical computer will have the TreeMap class available?"
The version of the Java Runtime environment/Plug-in installled on the PC
"Is the TreeMap class available on a PC running Windows XP, using the Java virtual machine that Microsoft supplies?"
No which why some people don't use the newer Java classes or Swing when they write applets.
"Where can I read about this sort of thing? How can I determine what classes I can safely use if I want my applet to run on both Windows and Macs?"
http://java.sun.com/j2se/1.4.1/docs/guide/plugin/developer_guide/using_tags.html -
Creation of developement class,package and access key
COULD ANYBODY EXPLAIN about
creation of developement class,package and access key
and who will create them?Working With Development Objects
Any component of an application program that is stored as a separate unit in the R/3 Repository is called a development object or a Repository Object. In the SAP System, all development objects that logically belong together are assigned to the same development class.
Object Lists
In the Object Navigator, development objects are displayed in object lists, which contain all of the elements in a development class, a program, global class, or function group.
Object lists show not only a hierarchical overview of the development objects in a category, but also tell you how the objects are related to each other. The Object Navigator displays object lists as a tree.
The topmost node of an object list is the development class. From here, you can navigate right down to the lowest hierarchical level of objects. If you select an object from the tree structure that itself describes an object list, the system displays just the new object list.
For example:
Selecting an Object List in the Object Navigator
To select development objects, you use a selection list in the Object Navigator. This contains the following categories:
Category
Meaning
Application hierarchy
A list of all of the development classes in the SAP System. This list is arranged hierarchically by application components, component codes, and the development classes belonging to them
Development class
A list of all of the objects in the development class
Program
A list of all of the components in an ABAP program
Function group
A list of all of the function modules and their components that are defined within a function group
Class
A list of all of the components of a global class. It also lists the superclasses of the class, and all of the inherited and redefined methods of the current class.
Internet service
A list of all of the componentse of an Internet service:
Service description, themes, language resources, HTML templates and MIME objects.
When you choose an Internet service from the tree display, the Web Application Builder is started.
See also Integrating Internet Services.
Local objects
A list of all of the local private objects of a user.
Objects in this list belong to development class $TMP and are not transported. You can display both your own local private objects and those of other users. Local objects are used mostly for testing. If you want to transport a local object, you must assign it to another development class. For further information, refer to Changing Development Classes
http://help.sap.com/saphelp_46c/helpdata/en/d1/80194b454211d189710000e8322d00/content.htm
Creating the Main Package
Use
The main package is primarily a container for development objects that belong together, in that they share the same system, transport layer, and customer delivery status. However, you must store development objects in sub-packages, not in the main package itself.
Several main packages can be grouped together to form a structure package.
Prerequisites
You have the authorization for the activity L0 (All Functions) using the S_DEVELOP authorization object.
Procedure
You create each normal package in a similar procedure to the one described below. It can then be included as a sub-package in a main package.
To create a main package:
1. Open the Package Builder initial screen (SE21 or SPACKAGE).
2. In the Package field, enter a name for the package that complies with the tools Naming Conventions
Within SAP itself, the name must begin with a letter from A to S, or from U to X.
3. Choose Create.
The system displays the Create Package dialog box.
4. Enter the following package attributes:
Short Text
Application Component
From the component hierarchy of the SAP system, choose the abbreviation for the application component to which you want to assign the new package.
Software component
Select an entry. The software component describes a set of development objects that can only be delivered in a single unit. You should assign all the sub-packages of the main package to this software component.
Exception: Sub-packages that will not be delivered to customers must be assigned to the HOMEsoftware component.
Main Package
This checkbox appears only if you have the appropriate authorization (see Prerequisites).
To indicate that the package is a main package, check this box.
5. Choose Save.
6. In the dialog box that appears, assign a transport request.
Result
The Change package screen displays the attributes of the new package. To display the object list for the package in the Object Navigator as well, choose from the button bar.
You have created your main package and can now define a structure within it. Generally, you will continue by adding sub-packages to the main package. They themselves will contain the package elements you have assigned.
See also
Adding Sub-Packages to the Main Package
http://help.sap.com/saphelp_nw04/helpdata/en/ea/c05d8cf01011d3964000a0c94260a5/content.htm
access key used for change standard program.
www.sap.service.com -
How to find classes in a java package
i am writing a java IDE. i want to extract all class names from a java package eg. java.lang (through coding). how can i do that.
Thanks in advanceFile file = new File("path to your jar file");
JarFile jf = new JarFile(file);
Enumeration e = jf.entries();
ZipEntry ze = null;
while(e.hasMoreElements()){
ze = (ZipEntry) e.nextElement();
ze.toString(); // gives you the file name
you have to understand java.util.jar java.util.zip packages for working with jar/zip files.
Hope this helps -
How to access AM/VO instance from a Java Service class
Hi,
I have a Java service class that is loaded by Java ServiceLoader (http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html) at run time, and I need to access database tables inside that service class. So is there any way that I can access AM/VO instances from that Java class in order to read database table? Thanks.
Regards,
K HeinYou can access an application module with the the two methods below:
YOURAppModule mAM;
public void setUpAM()
throws NamingException
try
String AMDefName = "YOUR_APP_DEF_NAME";
Hashtable env = new Hashtable(2);
env.put(JboContext.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);
ApplicationModule am = null;
InitialContext ic = new InitialContext(env);
ApplicationModuleHome home = (ApplicationModuleHome) ic.lookup(AMDefName);
am = home.create();
// Connect the AM to a database connection
String jndiDB = "jdbc/HRDS";
am.getTransaction().connectToDataSource(null, jndiDB, false);
boolean connected = am.getTransaction().isConnected();
mAM = (YOURAppModule) am;
catch (NamingException nex)
// do some error processing
throw nex;
catch (Exception eee)
// do some error processing
throw eee;
public void tearDownAM()
if (mAM != null)
if (mAM .getTransaction().isConnected())
mAM .getTransaction().disconnect();
mAM .remove();
}You find the YOUR_APP_DEF_NAME in your application module under 'Configurations' -> AppModuleJndiName.
Make sure you tear down each AM you set up. Otherwise you are running out of resources pretty fast.
Timo -
JavaFX accessing Java Inner Classes
We have LOTS of common Java classes that look like this...
public class X {
public class Y {
public static final String Z = "ZzZZZzzZzzZzzZz";
}So in JAVA we can access them like this...
public String z = X.Y.Z;But in JavaFX I CAN'T do this...
var z : X.Y.Z;The compiler says +"non-static class com.myproject.X.Y cannot be referenced from a static context"+
Tell me it aint so, please :)Galien, I doubt AndrewHughes can / want to change all the existing Java classes...
I tried to reproduce (I did) and found a workaround...
Java class (X.java):
public class X
public static final String ZX = "ZzZZZzzZzzZzzZzXX";
public class Y
public static final String ZY = "ZzZZZzzZzzZzzZzYY";
public static void main(String[] args)
new A();
class A
A()
System.out.println(X.Y.ZY);
}OK, it works...
JavaFX code: var z = X.Y.Z;(and not var z: X.Y.Z; since Z isn't a type...) Error "+non-static class X.Y cannot be referenced from a static context+". Mmmm...
Trying var z = X.ZX; works, of course.
Looking at the generated class files, I thought of a workaround: var z = X$Y.ZY;Yay! it works! :-D -
Does Java package has Model class?
I found the following code below from http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html. The problem is there is no Model class during the java compilation. I thought it is included in the Java package. Anyway, I was fail to import the Model class from java.lang.Object, java.awt, java.awt.event.*, javax.swing.*, java.util.*, and so on. Does Model class belong to Java package or self create?
// Action.java:
public abstract class Action {
protected Model model;
public Action(Model model) { this.model = model; }
public abstract String getName();
public abstract Object perform(HttpServletRequest req);
// CreateUserAction.java:
public class CreateUserAction extends Action {
public CreateUserAction(Model model) {
super(model);
public String getName() { return "createUser"; }
public Object perform(HttpServletRequest req) {
return model.createUser(req.getAttribute("user"),
req.getAttribute("pass"));
}No, it's not a Java SDK class, and it doesn't self-create. It must be part of the blueprints download, so you'll have to find where it is (a JAR file you've downloaded, perhaps) and put it in the CLASSPATH.
-
import java.rmi.*;
public class Rem extends java.rmi.server.UnicastRemoteObject implements RemInt {
public static void main(String args[]) {
System.setSecurityManager(new RMISecurityManager());
try {
Rem r = new Rem();
Naming.rebind("saurabh", r);
} catch(Exception e) { e.printStackTrace(); }
public Rem() throws java.rmi.RemoteException {
public String give() {
return("u got it from server");
import java.rmi.Remote;
public interface RemInt extends java.rmi.Remote {
public String give() throws java.rmi.RemoteException;
STACK TRACE
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.
0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.ja
va:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.connect(Socket.java:419)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.<init>(Socket.java:290)
at java.net.Socket.<init>(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocke
tFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocke
tFactory.java:122)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:159)
at Rem.main(Rem.java:10)I also get that exception, but only when I use SSL and the client is launched with Java Web Start.
I have tried to solve the problem by changing the permissions in the policy file but the problem still arises.
If I use default sockets (i.e.: no SSL) the client runs ok.
This is the policy file that the server uses:
grant {
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";
permission java.util.PropertyPermission "*", "read";
permission java.io.FilePermission "*", "read,write";
permission java.lang.RuntimePermission "*"; -
Understanding the combination of inheritance, packages and access modifiers
I am working on a problem to help my practical understanding of accessing inherited members and methods from a different package using both inheritance and instance variable.
Unfortunately, I am totally lost when I tried to set this up and understand what was happening.
Problem:
Create a class named "classA" under package "pack1" with 4 members (int pub_a, int priv_a, int prot_a, int def_a) and methods (pub_func1, priv_func1, prot_func1, def_func1). Mark the members and methods with 4 different access specifiers (public, private, protected, and default)
Create a class named "classB" under package "pack2", ClassB will inherit classA of package pack1. ClassB will have 2 members (int pub_b, int priv_b) and methods (pub_func2, prot_func2) with 2 different access specifiers (public, protected)
Try accessing the members of class classA in package pack1 inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through inheritance.
Create an instance of class classA inside class classB of package pack2. Find out what members and methods are accessible and not-accessible through the instance.
Note: In your solution, comment out the lines that are in-accessible with the actual error message at the top of the comment.
So I produced the following code (I don't think i set this up right):
//filename A.java
package pack1;
public class A {
public int pub_a;
private int priv_a;
protected int prot_a;
int def_a;
public int pub_func1() {return 1;}
private int priv_func1() {return 2;}
protected int prot_func1() {return 3;}
int def_func1() {return 4;}
//filename B.java
package pack2;
import pack1.A;
public class B extends A{
public int pub_b;
private int priv_b;
public int pub_func2() { return 5; }
private int priv_func2() { return 6; }
//directly inherited fields, at least one should be accessible?
pub_a = 1;
priv_a = 1;
prot_a = 1;
def_a = 1;
int i;
// directly inherited methods, at least one should be accessible?
i = pub_func1();
i = priv_func2();
A a = new A();
//not sure what's accessible here, as no error red underlines appear
a.pub_a = 1;
a.priv_a = 1;
a.prot_a = 1;
a.def_a = 1;
}I would be interested to know how one would approach and address this problem.//filename B.java
package pack2;
import pack1.A;
public class B extends A{
public int pub_b;
private int priv_b;
public int pub_func2() { return 5; }
private int priv_func2() { return 6; }
//directly inherited fields, at least one should be accessible?
pub_a = 1;//true
priv_a = 1;// false
prot_a = 1;//true
def_a = 1;//false
int i;
// directly inherited methods, at least one should be accessible?
i = pub_func1();//true
i = priv_func2();//false
A a = new A();
//not sure what's accessible here, as no error red underlines appear
a.pub_a = 1;//true
a.priv_a = 1;//false
a.prot_a = 1//false;
a.def_a = 1;//false
}Edited by: fun_with_me on May 31, 2008 8:30 AM
Maybe you are looking for
-
Activate GL account field in IW31
Hi, My issue is similar to what is mentioned in the below link: GL Field required in MIGO for Movement type 261 In IW21, 'Components Tab' the required materials are mentioned and system automatically creates a Reservation. User then issues the reserv
-
Can't set to manual mode if it's not listed in iTunes!
Hi, I'm struggling with this infuriating "feature" where iPods can only be synced with one computer to ensure everything being up-to-date. I just bought a new computer and want to copy new music to my iPod shuffle (2nd gen). I don't need auto-syncing
-
Hi, Hope someone can help. I live in France but I'm a british citizen. I've set up an itunes account but because I'm in France I've had to set it up in France.....I now can't understand anything!!! Does anyone know if I'm able to buy UK books etc on
-
Is there a WML/WAP Render Kit for JSF 1.2? I have a Nokia 3120 mobile phone which can access the Internet through the WAP Browser. Based on the specs page for the phone on Forum Nokia the phone's browser can also support XHTML. One area which I am no
-
PB 10.4.4 + Dlink 624 (wireless) don't like WPA encryption
Hi all, my PB and my wife's iBook both cannot lock on to the airport signal from our DLink 624 WITH WPA encryption. everything runs smoothly with the safety features disabled, but just gives me a "couldn't log on to the .... network" message and has