Non-static initializers run after constructors, causing confusion
Here are two Java classes, where class testinit2 extends class testinit1. testinit2 has an initializer and overrides the setaaa method of testinit1. What is surprising us is that the initializer in testinit2 is run AFTER the constructor of testinit1 is run. This means that the call in testinit1 constructor setaaa which actually runs the overridden method in testinit2 is completely blown away by the subsequent run of the initializer in testinit2
In other words we expected the value of testinit2.aaa2 to be "new", but instead it is "old"
Does this seem to work as the spec intended????
/* Class A */
import java.util.*;
class testinit1
public String aaa1 = "old";
public testinit1 () {
System.out.println("inside testinit1 constructor");
this.setaaa("new");
public void setaaa(String newval) {
System.out.println("inside testinit1.setaaa");
aaa1 = newval;
/* Class B */
import java.util.*;
class testinit2 extends testinit1
public String aaa2 = "old";
public testinit2 () {
// super();
System.out.println("ckpt3: aaa2 is " +aaa2);
System.out.println("inside testinit2 constructor");
public void setaaa(String newval) {
System.out.println("inside testinit2.setaaa");
aaa1 = newval;
System.out.println("ckpt1: aaa2 is " +aaa2);
aaa2 = newval;
System.out.println("ckpt2: aaa2 is " +aaa2);
But wouldn't that imply that the superclass must know
how its being used? It doesn't know that the method
has been overridden by a subclass. This seems like a
perfectly normal thing to do. I'm not ranting, just
seems like a lot of people could get bitten by this
behavior.Correct, it doesn't know. That's why you shouldn't be calling that method. The point is that you shouldn't make it possible in the first place for subclasses to override methods that might be called whilst the object is under construction.
Sure, people get bitten by this, but thre's not much that can be done about it, so the best they can do is learn from their mistakes.
If the compiler could stop this from happening, then (off the top of my head, without much thought about it, so I might be wrong), the Halting Problem would be solvable. Hence, by contradiction, there's nothing that can be done and we're stuck with it.
Of course, you could carefully document exactly what methods your superclass calls from its constructor, and in what order it calls them, and then you could maybe work around your problem, but I certainly wouldn't recommend it - you would likely be setting yourself up for a fall some time further down the line.
Your best option here is most probably to change your design.
Similar Messages
-
Dynamic JNLP causes exception on 1st run after java install
I have a dynamic JNLP file (php) which runs my software. It works just fine, except for the 1st time it is run after a user has installed Java.
I get the exception; "The following field was missing from the jnlp file: <jnlp>". When I look at the jnlp code in JWS in the "Launch File" tab of the error message, I see that the JNLP is not there - but the page the user would see if he was not logged into the system (as if JWS has cached the file or something).
If I close it down, press F5 to refresh, and run it again everything works fine.
I'm running the dyanmic.jnlp?dummy=randomnumber943934 to prevent caching. In addition, these headers are sent: (php code)
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");.. so nothing should be cached. But I'm not sure that's where the problem is - cause it only happens the first time after a java install.
Any clues?I think you're dynamicallt created jnlp is invalid in someway; I can use the following without any problems:
<?php
header("Content-type: application/x-java-jnlp-file");
echo "<?xml version=\"1.0\" ?>\n";
$codebase = trim(stripslashes(urldecode($_REQUEST["codebase"])));
$href = trim(stripslashes(urldecode($_REQUEST["href"])));
echo "<jnlp spec=\"1.0+\" codebase=\"$codebase\" href=\"$href\">\n";
?>
</jnlp>
you should try and test the output of your generated code, something like this should work:
test.php
<html>
<body>
<textarea rows=20 cols=70>
<?php
include 'mydynamicscript.php';
?>
</textarea>
</body>
</html>
The first time a jnlp is called it is downloaded into the browser cache and javaws.exe is executed on it from that location, this in turn downloads the jnlp again from the passed codebase & href attributes into the jws cache. Subsequent calls the jnlp are extracted from the copy in the webstart cache, and often downloaded from the codebase & href attributes when it detects possible changes. In your case these jnlp files seem to differ.
- Richard -
Ffox 3.6.10 on a Compaq Evo N8OOv began spontaneously shutting down w/o warning, closing all Internet applications w/ot affecting the operation of the computer, including non-Internet programs running simultaneously. Avira AntiVir Personal and with Spybot gave no hits suggesting infection.
See:
* http://kb.mozillazine.org/Firefox_crashes
* [[Firefox crashes]]
Your above posted system details show multiple Java Console extensions.
You can uninstall (remove) the Java Console extensions and disable the Java Quick Starter extension as you do not need them to run Java applets.
See http://kb.mozillazine.org/Java#Multiple_Java_Console_extensions
See also http://www.java.com/en/download/help/quickstarter.xml - What is Java Quick Starter (JQS)? What is the benefit of running JQS? - 6.0
Disable the Java Quick Starter extension: Tools -> Addons -> Extensions
Control Panel -> Java -> Advanced tab -> Miscellaneous -> Java Quick Starter (disable) -
I have been working on this file for 4 days now and I can't get past these errors.
Here's the whole project:
package toysmanager;
public class ToysManager {
//Method ToysManager
public ToysManager() {
//Method main
public static void main(String[] args) {
ToddlerToy Train1 = new ToddlerToy();
ToddlerToy Train2 = new ToddlerToy();
ToddlerToy Train3 = new ToddlerToy();
System.out.print("This is an object of type ToysManager");
Train1.PrintProductID();
Train2.PrintProductID();
Train3.PrintProductID();
public class ToddlerToy{
private int ProductID = 0;
private String ProductName = "";
private float ProductPrice = 0;
public ToddlerToy(int id,String name, float price){
ProductID = id;
ProductName = name;
ProductPrice = price;
//Method PrintProductID
public int PrintProductID(){
System.out.print("This method is PrintProductID in the class ToddlerToy");
System.out.print("Product ID is:" + ProductID);
return ProductID;
public String PrintProductName(){
System.out.print("This method is PrintProductName in the class ToddlerToy");
System.out.print("Product Name:" + ProductName);
return ProductName;
public float PrintProductPrice(){
System.out.print("This method is PrintProductPrice in the class ToddlerToy");
System.out.print("Product Price: $" + ProductPrice);
return ProductPrice;
And here are the errors:
"ToysManager.java": non-static variable this cannot be referenced from a static context at line 9, column 29
"ToysManager.java": ToddlerToy(int,java.lang.String,float) in toysmanager.ToysManager.ToddlerToy cannot be applied to () at line 9, column 29
"ToysManager.java": non-static variable this cannot be referenced from a static context at line 10, column 29
"ToysManager.java": ToddlerToy(int,java.lang.String,float) in toysmanager.ToysManager.ToddlerToy cannot be applied to () at line 10, column 29
"ToysManager.java": non-static variable this cannot be referenced from a static context at line 11, column 29
"ToysManager.java": ToddlerToy(int,java.lang.String,float) in toysmanager.ToysManager.ToddlerToy cannot be applied to () at line 11, column 29
Any help would be appreciated as I am plainly not understanding this even with a book.Annie:
Could you help me understand the original ToyManager instructions more please? Not asking you to do the work for me I just do not understand exactly what they want me to do...
Assignment:
After you install JCreator, write a Java program, with a single class called ToysManager. The main method should print the name of the class, for example: "This is an object of type ToysManager."
(Hint: the process is very similar to the "Hello World!" program.)
Please add file (.java)
Group Portion:
Deliverables: two *.java files
As a group, add a second class called ToddlerToy to your ToysManager project.
Here are the requirements for the ToddlerToy:
* The class ToddlerToy is public and has a default constructor.
* It has one private attribute called ProductID (of type int).
* It has two public methods called SetProductId() and PrintProductId().
* The method SetProductId() assigns a value to the attribute ProductId. For now, the value is hard-coded.
* The method PrintProductId prints the value of the attribute ProductId.
* The class ToddlerToy has no main() method. In Java, there is only one main method for the entire program. In this case, the main method is in the ToysManager class.
Here are the requirements for the main method of the ToysManager class:
* Create an object called Train1 of class type ToddlerToy, using the default constructor.
* Call the methods SetProductId() and PrintProductId() to set then print the the value of ProductId.
* The first statement in each method should print the name of the method, for example: "This is method <method name> in class <class name>". This should help you trace the execution of your program. Feel free to comment out the print statement.
* On the Small Group Discussion Board, discuss your understanding of the concepts of class, object, constructor, method, and attribute.
* Give one example of a class (giving its name, attributes, and methods) that could be part of the shipping application.ANY help with this at all is greatly appreciated...a friend of mine found your post and used it to give me code snippets for help and I had no idea. Nearly got me in deep water...redoing the assignment but personally I find the next two assignments much easier to understand than this one. The instructions are confusing to me...can you point me in the right direction? -
Non-static variable Help needed
Hi, I am creating a multi threaded web server but get the following error
non-static variable this cannot be referenced from a static context
HttpRequest request = new HttpRequest(connectionSocket);
Please could someone help.
Many Thanks
import java.io.* ;
import java.net.* ;
import java.util.* ;
public final class MultiWebServer
public static void main(String argv[]) throws Exception
// Set the port number.
int port = 6789;
// Establish the listen socket.
String fileName;
ServerSocket listenSocket = new ServerSocket(port);
// Process HTTP service requests in an infinite loop.
while (true) {
// Listen for a TCP connection request.
Socket connectionSocket = listenSocket.accept();
// Construct an object to process the HTTP request message.
HttpRequest request = new HttpRequest(connectionSocket);
// Create a new thread to process the request.
Thread thread = new Thread(request);
// Start the thread.
thread.start();
final class HttpRequest implements Runnable
final static String CRLF = "\r\n";
Socket socket;
String requestMessageLine;
String fileName;
Date todaysDate;
// Constructor
public HttpRequest(Socket socket) throws Exception
this.socket = socket;
socket = null;
// Implement the run() method of the Runnable interface.
public void run()
try {
processRequest();
} catch (Exception e) {
System.out.println(e);
private void processRequest() throws Exception
// Get a reference to the socket's input and output streams.
//InputStream is = new InputStream(socket.getInputStream());
//DataOutputStream os = new DataOutputStream(socket.getOutputStream());
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(
socket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(
socket.getOutputStream());
// Set up input stream filters.
requestMessageLine = inFromClient.readLine();
//BufferedReader br = null;
// Get the request line of the HTTP request message.
String requestLine = null;
// Display the request line.
System.out.println();
System.out.println(requestLine);
StringTokenizer tokenizedLine =
new StringTokenizer(requestMessageLine);
if (tokenizedLine.nextToken().equals("GET"))
fileName = tokenizedLine.nextToken();
if ( fileName.startsWith("/")==true )
fileName = fileName.substring(1);
File file = new File(fileName);
int numOfBytes = (int)file.length();
FileInputStream inFile = new FileInputStream(fileName);
byte[] fileInBytes = new byte[numOfBytes];
inFile.read(fileInBytes);
/* Send the HTTP header */
outToClient.writeBytes("HTTP/1.1 200 Document Follows\r\n");
if (fileName.endsWith(".jpg"))
outToClient.writeBytes("Content-Type: image/jpeg\r\n");
if (fileName.endsWith(".jpeg"))
outToClient.writeBytes("Content-Type: image/jpeg\r\n");
if (fileName.endsWith(".gif"))
outToClient.writeBytes("Content-Type: image/gif\r\n");
if (fileName.endsWith(".html"))
outToClient.writeBytes("Content-Type: text/html\r\n");
if (fileName.endsWith(".htm"))
outToClient.writeBytes("Content-Type: text/html\r\n");
outToClient.writeBytes("Content-Length: " + numOfBytes + "\r\n");
outToClient.writeBytes("\r\n");
/* Now send the actual data */
outToClient.write(fileInBytes, 0, numOfBytes);
socket.close();
else
System.out.println("Bad Request Message");
todaysDate = new Date();
try {
FileInputStream inlog = new FileInputStream("log.txt");
System.out.println(requestMessageLine + " " + todaysDate );
FileOutputStream log = new FileOutputStream("log.txt", true);
PrintStream myOutput = new PrintStream(log);
myOutput.println("FILE -> " + requestMessageLine + " DATE/TIME -> " + todaysDate);
catch (IOException e) {
System.out.println("Error -> " + e);
System.exit(1);
socket.close();import java.io.* ;
import java.net.* ;
import java.util.* ;
public final class MultiWebServer
public MultiWebServer(){
try{
// Set the port number.
int port=6789;
// Establish the listen socket.
String fileName;
ServerSocket listenSocket=new ServerSocket(port);
// Process HTTP service requests in an infinite loop.
while(true){
// Listen for a TCP connection request.
Socket connectionSocket=listenSocket.accept();
// Construct an object to process the HTTP request message.
HttpRequest request=new HttpRequest(connectionSocket);
// Create a new thread to process the request.
Thread thread=new Thread(request);
// Start the thread.
thread.start();
}catch(IOException ioe){
}catch(Exception e){
public static void main(String argv[]) throws Exception
new MultiWebServer();
final class HttpRequest implements Runnable
final static String CRLF = "\r\n";
Socket socket;
String requestMessageLine;
String fileName;
Date todaysDate;
// Constructor
public HttpRequest(Socket socket) throws Exception
this.socket = socket;
socket = null;
// Implement the run() method of the Runnable interface.
public void run()
try {
processRequest();
} catch (Exception e) {
System.out.println(e);
private void processRequest() throws Exception
// Get a reference to the socket's input and output streams.
//InputStream is = new InputStream(socket.getInputStream());
//DataOutputStream os = new DataOutputStream(socket.getOutputStream());
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(
socket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(
socket.getOutputStream());
// Set up input stream filters.
requestMessageLine = inFromClient.readLine();
//BufferedReader br = null;
// Get the request line of the HTTP request message.
String requestLine = null;
// Display the request line.
System.out.println();
System.out.println(requestLine);
StringTokenizer tokenizedLine =
new StringTokenizer(requestMessageLine);
if (tokenizedLine.nextToken().equals("GET"))
fileName = tokenizedLine.nextToken();
if ( fileName.startsWith("/")==true )
fileName = fileName.substring(1);
File file = new File(fileName);
int numOfBytes = (int)file.length();
FileInputStream inFile = new FileInputStream(fileName);
byte[] fileInBytes = new byte[numOfBytes];
inFile.read(fileInBytes);
/* Send the HTTP header */
outToClient.writeBytes("HTTP/1.1 200 Document Follows\r\n");
if (fileName.endsWith(".jpg"))
outToClient.writeBytes("Content-Type: image/jpeg\r\n");
if (fileName.endsWith(".jpeg"))
outToClient.writeBytes("Content-Type: image/jpeg\r\n");
if (fileName.endsWith(".gif"))
outToClient.writeBytes("Content-Type: image/gif\r\n");
if (fileName.endsWith(".html"))
outToClient.writeBytes("Content-Type: text/html\r\n");
if (fileName.endsWith(".htm"))
outToClient.writeBytes("Content-Type: text/html\r\n");
outToClient.writeBytes("Content-Length: " + numOfBytes + "\r\n");
outToClient.writeBytes("\r\n");
/* Now send the actual data */
outToClient.write(fileInBytes, 0, numOfBytes);
socket.close();
else
System.out.println("Bad Request Message");
todaysDate = new Date();
try {
FileInputStream inlog = new FileInputStream("log.txt");
System.out.println(requestMessageLine + " " + todaysDate );
FileOutputStream log = new FileOutputStream("log.txt", true);
PrintStream myOutput = new PrintStream(log);
myOutput.println("FILE -> " + requestMessageLine + " DATE/TIME -> " + todaysDate);
catch (IOException e) {
System.out.println("Error -> " + e);
System.exit(1);
socket.close(); -
Non-static cannot be referenced from a static context - ?
Hi, i understand (kinda) what the error means
i think its saying that i cannot call a non-static method "bubbleSort"
from the static method main (correct?)
but i dont know how to fix it...
do i make bubbleSort
public static void bubbleSort???
C:\jLotto\dataFile\SortNumbers.java:80: non-static method bubbleSort(int[]) cannot be referenced from a static context
bubbleSort( a ); //sort the array into ascending numbers
my code:
import java.io.*;
import java.util.*;
public class SortNumbers
public static void main( String args[]) throws IOException
int num;
int a[] = new int[7]; //an array for sorting numbers
File inputFile = new File("C:\\jLotto\\dataFile\\outagain.txt");
File outputFile = new File("C:\\jLotto\\dataFile\\sortedNum.txt");
BufferedReader br = new BufferedReader( new FileReader( inputFile ));
PrintWriter pw = new PrintWriter( new FileWriter( outputFile ));
String line = br.readLine();
while( line != null ){//reads a single line from the file
StringBuffer buffer = new StringBuffer(31); //create a buffer
StringTokenizer st = new StringTokenizer( line," "); //create a tokenizer
while (st.hasMoreTokens()){
// the first 4 tokens are id,month,day,ccyy, no sorting needed
// so they are simply moved into the buffer
for (int i =1; i<5; i++){
num = Integer.parseInt(st.nextToken());
buffer.append( num );
buffer.append( "|");
//tokens 5 to 11 need to be sorted into acending order
//so read tokens 5 to 11 into an array for sorting
for (int i =0; i<7; i++){
a[i] = Integer.parseInt(st.nextToken());
bubbleSort( a ); //sort the array into ascending numbers
//the array is sorted so read array back into the buffer
for ( int i = 0; i < a.length; i++ ){
buffer.append( a[ i ] );
buffer.append( "|" ) ;
}//end of while st.hasMoreTokens
//then write out the record from the stringBuffer
pw.println( buffer );
line = br.readLine();
}//end of while != null
br.close();
pw.close();
}//end of static main
// sort the elements of an array with bubble sort
public void bubbleSort( int b[] )
int swapMade = 0; //if after one pass, no swaps were made - exit
for ( int pass = 1; pass < ( b.length - pass) ; pass++ ) // passes reduced for speed
for ( int i = 0; i < b.length - 1; i++ ) // one pass
if ( b[ i ] > b[ i + 1 ] ) // one comparison
swap( b, i, i + 1 ); // one swap
swapMade = 1;
} // end of if
} //end of one pass
if (swapMade == 0) pass = 7; //no swaps, so break out of outter for loop
}//end of passes, end of outter for loop
}//end of bubblesort method
// swap two elements of an array
public void swap( int c[], int first, int second )
int hold; // temporary holding area for swap
hold = c[ first ];
c[ first ] = c[ second ];
c[ second ] = hold;
} //end of swap
}//end of class SortNumbersStatic means
when u run the program (a class), there is only one variabel / type in memory.
ex static int a; //assume it's inside the aStaticClass
mean no wonder how many u create object from this class, variabel a only have 1 in memory. so if u change a (ex a=1;) all instance of this aStaticClass will effected (because they share the same variabel).
Try to read more at :
http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
I hope this will help you....happy new year
yonscun -
Converting from non-static to static
I am tyring to convert a method from non-static to static. I changed a few variables to get it to work and everything is now static in the method except for the getClass() method which it calls, does anyone know how I could work around this.
Heres the method -
public static void addObjectToPanel(String type, String name)
JLabel label = new JLabel("The object");
// The getClass() here is causing the problem
label.setIcon(new ImageIcon(getClass().getResource("object.gif")));
label.setBounds(xCoordinate, yCoordinate, width, height);
display.setLayout(null);
display.add(label);
// After the image is placed by this method, then the x coordinate is moved to allow for the next object
xCoordinate +=150;
// This resizes the JPanel as images are added, this solves a potential issue with the JScrollPane
display.setPreferredSize(new Dimension( (900+xCoordinate), (600+yCoordinate) ));Is there any way I can get around using getClass() or is there anything else I could do, thanks.It's a static method. You should know what thename
of the class that it is in is.Sorry, I didn't see that they were talking about the
actuall class that the method is in, i missed
something written earlier.
I am now using label.setIcon(new
ImageIcon("object.gif"));and everything is working fine now.
Thanks everyone for your help.Be warned that this is not the same as what you did initially. The initial version looks in the class loading path. The final version looks in the current directory. I believe your intention is better reflected by the initial version. -
Static initializers in process definitions
I get the following error when compiling a .jpd in workshop:
ERROR: DESCRIPTION: An unexpected exception occurred while attempting to locate
the run-time information for this Web Service. Error: java.lang.reflect.InvocationTargetException:null
The code that causes it is:
private static Log log = LogFactory.getLog(Whatever.class);
I have experimented a little, any such static initializer will cause the error.
Has anyone seen this before?nemo666 wrote:
is it still cool to use static initializers in java 1.4.2 and later ?Yes. Why? Was there some feature added to that version that you think supersedes static initializers? -
Static initializers get called over and over?
I have a java web application running on resin. I don't know why but from time to time my class files suddenly get reloaded. I can notice from my log files that static initializers get called over and over again, which is causing me problems. How can this happen? Any settings I should fix? Anyone has similar problems?
ram, thank you very much for your reply.
I'm sure this problem doesn't always happen.
I have a static initializer in a different
application on a different resin server but it never
initializes over and over.
There must be some settings I can change to make it
not to initialize more than once.I concur with Ram on this one. Having static initializers in container managed apps can be very dangerous if you need to make sure that it is initialized exactly once. I've seen problems like this happen on several vendor's Containers. A safer approach could be to store these values in your container's Application-scope. This way, you not only ensure that these values are initialized exactly once, but that the value will be available to all JVM's running should this app be deployed in a clustered environment. -
Error on compile - non-static variable can not be referencedfrom static con
Error on compile happening with addButton?
Thanks
import java.awt.*;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JFrame;
public class Log implements ActionListener {
JButton addButton;
public static void addComponentsToPane(Container pane) {
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridy = 3;
c.gridx = 0;
JLabel callsignLabel= new JLabel("Callsign");
pane.add(callsignLabel, c);
c.gridy = 3;
c.gridx = 1;
JLabel nameLabel= new JLabel("Name");
pane.add(nameLabel, c);
c.gridy = 3;
c.gridx = 2;
JLabel timeLabel= new JLabel("Time");
pane.add(timeLabel, c);
c.gridy = 3;
c.gridx = 3;
JLabel dateLabel= new JLabel("Date");
pane.add(dateLabel, c);
c.gridy = 3;
c.gridx = 4;
JLabel frequencyLabel= new JLabel("Freq ");
pane.add(frequencyLabel, c);
c.gridy = 3;
c.gridx = 5;
JLabel locationLabel = new JLabel("Country/State");
pane.add(locationLabel, c);
c.gridy = 5;
c.gridx = 0;
addButton = new JButton("Add");
pane.add(addButton, c);
addButton.addActionListener(this);Thank you for the reply
I am new to Java
What is wrong with the way it is coded?The error message tells you what's wrong: You're trying to reference a non-static variable from a static context.
If you don't know what that means, then click the link I provided and look at the results from that google search. You might have to go through a few before you find a satisfactory explanation. And after you've done that, if you have specific questions about things you didn't understand there, please post again. -
Calling a non-static method from another Class
Hello forum experts:
Please excuse me for my poor Java vocabulary. I am a newbie and requesting for help. So please bear with me! I am listing below the program flow to enable the experts understand the problem and guide me towards a solution.
1. ClassA instantiates ClassB to create an object instance, say ObjB1 that
populates a JTable.
2. User selects a row in the table and then clicks a button on the icon toolbar
which is part of UIMenu class.
3. This user action is to invoke a method UpdateDatabase() of object ObjB1. Now I want to call this method from UIMenu class.
(a). I could create a new instance ObjB2 of ClassB and call UpdateDatabase(),
== OR ==
(b). I could declare UpdateDatabase() as static and call this method without
creating a new instance of ClassB.With option (a), I will be looking at two different object instances.The UpdateDatabase() method manipulates
object specific data.
With option (b), if I declare the method as static, the variables used in the method would also have to be static.
The variables, in which case, would not be object specific.
Is there a way or technique in Java that will allow me to reference the UpdateDatabase() method of the existing
object ObjB1 without requiring me to use static variables? In other words, call non-static methods in a static
way?
Any ideas or thoughts will be of tremendous help. Thanks in advance.Hello Forum:
Danny_From_Tower, Encephalatic: Thank you both for your responses.
Here is what I have done so far. I have a button called "btnAccept" created in the class MyMenu.
and declared as public.
public class MyMenu {
public JButton btnAccept;
//Constructor
public MyMenu() {
btnAccept = new JButton("Accept");
} I instantiate an object for MyMenu class in the main application class MyApp.
public class MyApp {
private MyMenu menu;
//Constructor
public MyApp(){
menu = new MyMenu();
public void openOrder(){
MyGUI MyIntFrame = new MyGUI(menu.btnAccept);
}I pass this button all the way down to the class detail02. Now I want to set up a listener for this
button in the class detail02. I am not able to do this.
public class MyGUI {
private JButton acceptButton;
private detail02 dtl1 = new detail02(acceptButton);
//Constructor
public AppGUI(JButton iButton){
acceptButton = iButton;
public class detail02{
private JButton acceptButton;
//Constructor
public detail02(JButton iButton){
acceptButton = iButton;
acceptButton.addActionListener(new acceptListener());
//method
private void acceptListener_actionPerformed(ActionEvent e){
System.out.println("Menu item [" + e.getActionCommand( ) + "] was pressed.");
class acceptListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
acceptListener_actionPerformed(e);
} I am not able to get the button Listener to work. I get NullPointerException at this line
acceptButton.addActionListener(new acceptListener());in the class detail02.
Is this the right way? Or is there a better way of accomplishing my objective?
Please help. Your inputs are precious! Thank you very much for your time! -
Issues with iTunes 9.2 not running after download.
I have been trying to get iTunes 9.2 going since the 24th when I purchased my iPhone 4. I have had NO LUCK getting iTunes to properly run after downloading the flie.
I have Vista 64 bit.
When I download the file and attempt to run it, I get the error "Publisher could not be verified" I select run anyway and nothing happens.
I have tried every suggestion made on this form
I have-
Tried to run as administrator
Deleted temp folder in Users/Name
Ran windows installer cleanup utility
downloaded the file from firefox and IE
It's very annoying because the 32 bit will run and install, but the 64 bit will not. Any suggestions?None of your software will install on any computer I own. I tried to download Safari and download iTunes through that browser to see if the results would be different, but after downloading it that file does NOTHING after being ran. It's so pathetic I can't even sync my iPhone 4 to my computer after having it since Thursday. Three different computers three different downloads with 2 different browsers.
I'm getting ready to just box up this phone and return it, if I cant even sync it to iTunes, it's useless to me.
If I download through Firefox, nothing happens when I run the executable.
If I download it through Internet Explorer, I get the message that it is an invalid publisher, or publisher could not be identified.
I have erased my temp folder, deleted browser history on both browsers, still nothing.
I am running it in Administrator mode, I have done every suggestion that you have on your site and nothing works. -
Firefox will not run after update (3.6 8.0) WinXP
I noticed that my mother's laptop was running Firefox 3.6 still, and offered to update. I downloaded 8.0, and ran the install. Had no issues with the install, no errors, nothing. I told it to run after the install finished, and it never came up. I tried the icon, still nothing. I downloaded Firefox 7.0, and installed it, figuring there might have been an issue with 8.0, since it just came out, nd tried it, same result. I rebooted the system, and tried again, still nothing happens, just the little hourglass for a moment, and then.. nothing. There is nothing in the task manager, no process for firefox. I tried running the profile manager and the plain program from the run under the start menu of windows with antivirus turned off, and got nothing there either.
I'm running windows XP Pro
::edit::
I was able to re-instal 3.6.24 back over top, and it works, but I would like to update it for her still, if it can be done.A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
See:
*https://support.mozilla.com/kb/Server+not+found
*https://support.mozilla.com/kb/Firewalls -
Problem with OSB 11g - Unable to call non-static java methods
I have a problem in OSB. Unable to see any java methods when loading java callout. I have checked the java classes in the .jar file and they are all non-static java methods.
Is there any way where OSB is able to see this non-static java methods?
Need help urgently!
Thanks!Technical standpoint: Do you know why OSB is not able to call non-static methods?
This is by design. Ability to call non-static methods require Object creation which adds additional complexity. eg How to pass variables in constructor?. How/where to store created object for use across across pipeline instance?. Object life cycle (when and how to create object) etc. To avoid above complexites static methods are only supported.
"a lot of non-static method to call" just for my understanding what are the number involved?. If number is too high you can always request for a enhancement.
Thanks
Manoj -
Abstract method versus static and non-static methods
For my own curiosity, what is an abstract method as opposed to static or non-static method?
Thanks>
Following this logic, is this why the "public static
void main" 0r "Main" method always has to be used
before can application can be run: because it belongs
to the class (class file)?
Yes! Obviously, when Java starts up, there are no instances around, so the initial method has to be a static (i.e. class) one. The name main comes from Java's close association with C.
RObin
Maybe you are looking for
-
Use require group in virtual host
Hi, I have set up several virtual hosts in my middle tier, and configured them as partner applications so that OID/SSO can be used for authentication. It works fine, but the only supported method I can see is 'require valid-user' which allows any use
-
Having trouble with multiple lines
I'm trying to fill out this form for an application that is a read/enter/print only PDF, and I got to a multiple line box and instead of being able to enter text in line for line, when you try to enter text it shows as one big format which I can't ch
-
Hi Gurus, I am using OWB 11gR1 & Oracle 10gR2 as a repository database on a windows machine. There are patch_paris_repos_sys.sql & patch_paris_repos.bat given in the product\11.1.0\db_1\owb\UnifiedRepos directory. What is the use of this script? Has
-
Regarding the timestamp usage in oracle 11g
Hi All, I am using the following query in 11g. SELECT DISTINCT TO_DATE(SHIP_DTTM,'mm/dd/yyyy') FROM PS_IN_DEMAND WHERE SHIP_DTTM BETWEEN TO_DATE(fromdate,'mm/dd/yyyy') AND TO_DATE(todate,'mm/dd/yyyy') The error i am getting is System.Data.Odbc.OdbcEx
-
Hello Everyone and congratulations for the Support Forum! I am experiencing Cover Flow view problems since I installed iTunes 10 on my windows based laptop. I here enclose address of a picture to let you better understand which the problem is. http:/