Bypassing Constructors....
Hi there,
Does anyone know how to create a new instance without causing invocation of a constructor? Its driving me mad - I know I've got it in one of my reference books (Java XML I think, where they create custom XML serialization streams) - but I cant find it!
Ive got a feeling it might be in one of the sun.misc classes....
Does anyone know....?
Why do you want to do that? Cos Im a monkey :o)
Apart from that, Im knocking up a rules engine for creating fully populated class instances for as many class types in my application that I can get it to manage. In certain scenarios the ability to do this comes in handy for me.
and I don't see a reason to do itObject creation without constructor invocation is also used for standard (java.io) Object de-serialization. I can imagine it being equally useful in other object persistence frameworks too.
Similar Messages
-
How do I create a Modal JDialog (non-bypassable when visible)?
After customising a JDialog, I found that it is basically ignored after it has been created, by the main program. I've tried many ways to stop this from happening, searched the Java tutorial and googled it, but cannot find out how to do so. I have used the constructor for a modal Dialog:
JDialog(Dialog owner, String title, boolean modal)However, my methods are still treated like a non-modal Dialog, as they are ignored. Is there a certain method I have to call to make this Dialog modal (not able to be bypassed when made visible). If so then I would appreciate it if anybody could help, or perhaps point me along the right way.JDialog(Dialog owner, String title, boolean modal)How do you expect us to solve your problem based on a single line of code? Create a simple demo program that shows the problem
Here is a simple demo that works.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DialogModal extends JFrame implements ActionListener
public DialogModal()
JButton button = new JButton("Show Dialog");
button.addActionListener( this );
getContentPane().add( button );
public void actionPerformed(ActionEvent e)
JDialog dialog = new JDialog(this, "Modal Test", true);
dialog.setSize(300, 300);
dialog.show();
public static void main(String[] args)
JFrame frame = new DialogModal();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
} -
Fields initialization : initializers vs constructors
I've just come to thought that I might be doing the wrong thing using initializers instead of initializing fields in the constructor. Of cause I'm speaking of DPL..
I'm used to do something like this:
@Persistent
class Compound
private final Map<Integer, Integer> elements = new HashMap<Integer, Integer>();
private Compound() {} //dummy private default constructor to be used by BDB
//actual constructor to be used in the code
public Compound(int initialValue)
//some specific initialization...
//e.g.:
elements.add(initialValue, initialValue);
}But while thinking about what will BDB actually do when demarshaling the object instance, I came to idea that it would re-construct the elements map and forget the one I carefully create in the initializer.. So to avoid the useless object instantiation I'd have to initialize the field in constructor like this:
@Persistent
class Compound
private final Map<Integer, Integer> elements;
//dummy private default constructor to be used by BDB
private Compound()
//now I have to assign something to elements field because it's final..
// or just remove the *final* modifier???
elements = null;
//actual constructor to be used in the code
public Compound(int initialValue)
elements = new HashMap<Integer, Integer>()
//some specific initialization...
//e.g.:
elements.add(initialValue, initialValue);
}So my question is: is there any actual difference between the first and second approaches? Or I just thinking the wrong way?..Hm.. Yes, I'm pretty sure it's working with JE. I was thinking that reflection allows bypassing the "final" modifier.. Hm.. Quick googling gives this for example: http://stuffthathappens.com/blog/2007/10/13/you-can-change-final-fields/. While reading this article it seems that it's still a bad idea to rely on it..
Interesting, thanks. I was probably remembering tests I performed on Java 1.4, which does not allow setting final fields, according to one of the comments.
Yes, relying on this behavior can get you into trouble for two reasons.
1. If the field happens to be public, JE will not call setAccessible.
2. If you're using the bytecode annotator, JE does not use reflection to set fields, and the generated code that changes the final field will fail.
The second issue is insidious, if you use the default reflection mechanism during initial development and then switch to bytecode generation later on.
I think JE should always throw an exception if the final modifier is set, to guard against this.
--mark -
My Mac is bypassing a website filter... How can I stop it?
I am a computer technician at our local high school. Right now, the school has about 800 Dell computers, but we are planning on introducing a few Macintosh labs within the next school year.
Since they lack educational value, the school district's director of technology (my boss) has a web filter (Deep Nine) that blocks myspace, facebook, youtube, proxy sites, and other similar sites.
Myspace is blocked via a keyword filter, any page containing the word "myspace" in the url, or in the document a set number of times, is automatically blocked. The other sites are simply blocked by URL. This filter works perfectly on our Dells, no one can access Myspace, Facebook, Proxies, etc.
I brought my Macbook to work today, plugged it into the network, and logged onto the internet. I noticed instantly that my homepage (Facebook) loaded without being blocked at all. Curious, I tested myspace and youtube, and I could get on youtube fine, but myspace remained blocked.
I checked on the Dell next to me, and all those sites will still being filtered and blocked. Yet my Macbook was able to access them without issue. So it would appear that my Macbook has some mystic ability to bypass the web address filter, but it can not bypass the keyword filter.
I do not have any proxies configured. My Macbook connects to the network (and thus, the internet) the same exact way the other computers within the school do, with the exception of the other computers being within Active Directory.
I need to find out if it is an issue with the Mac or with our Filter. I don't have any other Macs available to test with (Our only other Mac in the school is our DHCP server, and we do not use servers as "lab rat" computers).
Has anyone had any similar issues with this? Or does anyone know of any way I can diagnose this with only one Mac and only one Filter?
Specs: OS 10.5.5, Safari 3.1.2, wired networking.
Message was edited by: Joey Hogan
Message was edited by: Joey HoganThe DeepNines product works well and does much more than a simple URL filter. The problem lies entirely in your district setup and not in their product. If you're not using a proxy filter, then you have all access and routes designed to head out on typical port 80 traffic to your isp and ultimately the internet hence no proxy configs. The filter is integrated with LDAP accounts at each of your locations to tell it which users and groups are to get filtered at what level. That tie in is what breaks down who goes where. If you introduce new macs onto the network and they have not been configured to work with the DN appliance and are going out unfiltered... then there are 2 problems here. #1 is that you have computers attaching to the network, receiving leases and doing what they want. Use DHCP reservations or a whitelist to control who gets on your network. #2 is that your DeepNines filter has not been set to failover to BLOCK. Instead, it's allowing unknown users to bypass freely simply because it doesn't recognize their group/account. And Orange, stop slamming the company. They are a smaller business that has taken a much better approach to filtering than any other large corporation. Standard database driven URL filters DO NOT WORK....PERIOD! I challenge you to call any district that is running their appliance to get their opinion of it in comparison to any of the other basic url filters out there. I did just that last week and they had absolutely nothing but high praises for the DN product. One even laughed at Websense which they had before switching simply for the lack of ability to block anonymouse proxies.
-
Error while calling a super class public method in the subclass constructor
Hi ,
I have code like this:
CLASS gacl_applog DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS:
create_new_a
IMPORTING pf_obj TYPE balobj_d
pf_subobj TYPE balsubobj
pf_extnumber TYPE string
EXPORTING pfx_log_hndl TYPE balloghndl
EXCEPTIONS error
ENDCLASS.
CLASS gacl_applog IMPLEMENTATION.
METHOD create_new_a.
DATA: ls_log TYPE bal_s_log.
Header aufsetzen
MOVE pf_extnumber TO ls_log-extnumber.
ls_log-object = pf_obj.
ls_log-subobject = pf_subobj.
ls_log-aluser = sy-uname.
ls_log-alprog = sy-repid.
ls_log-aldate = sy-datum.
ls_log-altime = sy-uzeit.
ls_log-aldate_del = ls_log-aldate + 1.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = pfx_log_hndl
EXCEPTIONS
OTHERS = 1.
IF ( sy-subrc NE 0 ).
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING error.
ENDIF.
ENDMETHOD.
CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
PUBLIC SECTION.
DATA: log_hndl TYPE balloghndl READ-ONLY
, t_log_hndl TYPE bal_t_logh READ-ONLY
METHODS: constructor
IMPORTING pf_obj TYPE balobj_d
pf_subobj TYPE balsubobj
pf_extnumber TYPE string
EXCEPTIONS error
, msg_add REDEFINITION
, display REDEFINITION
ENDCLASS.
CLASS gcl_applog_temp IMPLEMENTATION.
METHOD constructor.
CALL METHOD create_new_a
EXPORTING pf_obj = pf_obj
pf_subobj = pf_subobj
pf_extnumber = pf_extnumber
IMPORTING pfx_log_hndl = log_hndl.
IF ( sy-subrc NE 0 ).
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING error.
ENDIF.
ENDMETHOD.
A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass '
Can you please suggest how to change the code with out affecting the functioanlity.
Thank you ,
Lakshmi.Hi,
Call that method by instance of Subclass. OR
SUPER-->method.
Read very useful document
Constructors
Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
METHODS CONSTRUCTOR
IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
EXCEPTIONS.. <ei>.
and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
CLASS-METHODS CLASS_CONSTRUCTOR.
and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
Pls. reward if useful.... -
My 7 year old has a passcode on her iPod touch. She forgot it, after multiple attempts at what it could have been, it comes up with disabled etc.....I have tried it in recovery and hooking it up to iTunes (which the device has been previously synced up to) to restore. But the problem I am having is it only gives me the option to update also, to iOS 6.1.3 with the new bug fix which it won't allow you to bypass the passcode. It gets a little into the downloading, turns the iPod on and then asks for the passcode to continue?! I am at a loss as to what to do now, as every forum says put it in recovery and restore. I can't use the 'find my iPhone' app as the iPod is offline. I've tried it on a laptop not prev synced up to and get the same problem. Has any one got any ideas!
Try disabling the computer's antivirus and firewall.
- Next try the manual install method of:
iDevice Troubleshooting 101 :: iPhone, iPad, iPod touch
Place the iPod in recovery mode after the firmware download is complete and then restore using the instructions in the article. Sometimes recovery mode timeouts and returns to disabled before the firmware download is complete.
- Then try on another computer -
Bypass Header and Footer in Excel output
I have a Requirement like this
I need to have the report output in the below three formats
PDF,EXCEL,HTML
But when we see the ouput in EXcel it should not have the Footer and Header Scetion ,
remaining two output formats (PDF,HTML) must have the Footer and Header Section.
Any one having any idea about this issue.
Thanks in Advance.
Have a Nice day.Hi @BIPuser.
I said the same thing to them but they said no that is final option but we need only single template for all the outputs alos it should handle the bypassing of header and footer for excel output.
Thanks for your reply, If i come across anything i will let u know. -
Value set in constructor is not getting saved in button Action method
Hi All,
I am not understanding why the value set ( On Condition )in constructor is not hold in the button actoin method.
Could any body explain me on that
for this I will try to explain with sample example
I have taken a button and add a integer property in session bean.
now if session bean's property is even then I am trying to set the button value to bidNow other wise Accept Invitation.
Till this opstion everything is OK
but once I click on Button,
Constructor is doing the right job only. But I do not understand why in button action I am getting the First Value only.
public Page1() {
// <editor-fold defaultstate="collapsed" desc="Creator-managed Component Initialization">
try {
if (getSessionBean1().getIntValue()%2==0)
button1.setValue("BidNow");
else
button1.setValue("Accept Invitation");
getSessionBean1().setIntValue(getSessionBean1().getIntValue()+1);
log("In Constructor Button Value : "+button1.getValue());
} catch (Exception e) {
log("Page1 Initialization Failure", e);
throw e instanceof javax.faces.FacesException ? (FacesException) e: new FacesException(e);
// </editor-fold>
// Additional user provided initialization code
public String button1_action() {
// TODO Replace with your code
log("In Action Button Value : "+button1.getValue());
return null;
}and here is the log
[#|2005-07-19T11:55:17.859+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:17.859+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:18.359+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:18.359+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:18.843+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:18.843+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:19.312+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:19.312+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:19.828+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:19.828+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:20.234+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:20.250+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:20.828+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:20.828+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:21.328+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:21.328+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:35.437+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:35.437+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:35.906+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:35.921+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:36.265+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:36.265+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:36.890+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:36.890+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:37.171+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : BidNow|#]
[#|2005-07-19T11:55:37.171+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]
[#|2005-07-19T11:55:37.468+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Constructor Button Value : Accept Invitation|#]
[#|2005-07-19T11:55:37.468+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.web|_ThreadID=14;|WebModule[/webapplication12]In Action Button Value : BidNow|#]As per this log every time I am getting Bid Now only in action, though the value is changed in Construtcor
Can u explain the reason for thisHi Sudhakar,
Please try the following and you will get an idea as to what is happening:
1. Drag and drop a button, 2 outputText components
2. Add a property to the session bean called intValue of type int. Customize it to set it's initial value to 0
3. Add the following lines of code to the constructor
outputText1.setValue("" + getSessionBean1().getIntValue());
getSessionBean1().setIntValue(getSessionBean1().getIntValue()+1);
4. Double click on the button component to go to the button action method.
5. Add the following line of code
outputText2.setValue("" + etSessionBean1().getIntValue());
6. Save and run the application
7. Watch the values of outputText1 and outputText2 with each click of the button
Also, try the application with the following code block in the button action method:
if(getSessionBean1().getIntValue()%2==0){
button1.setValue("Bid Now");
} else{
button1.setValue("Accept Invitation");
getSessionBean1().setIntValue(getSessionBean1().getIntValue()+1);
outputText1.setValue(button1.getValue());
outputText2.setValue("" + getSessionBean1().getIntValue());
When the above code block is in the button action method the values set to button are as expected.
Hope that helps
Cheers
Giri :-) -
the only 2 options i have are:
Get me out of here and Technical Details.
The documentation shows a third option to bypass, but this is not available to me.
I am trying to get an SSO passed into a website that uses my corporate SSO in our SaaS subscription. It works fine on IE10 and was working fine on Firefox until recently.Note that the forum software detect your computer as Windows NT 4.0
Check that you do not run Firefox in compatibility mode or with a reduced screen resolution.<br />
Make sure that you do not run Firefox in compatibility mode.<br />
You can open the Properties of the Firefox desktop shortcut via the right-click context menu and check the "Compatibility" tab.<br />
Make sure that all items are deselected in the "Compatibility" tab of the Properties window.
What does it say under the technical details?
If "I Understand the Risks" is missing then this page may be opened in an (i)frame and in that case try the right-click context menu and use "This Frame: Open Frame in New Tab". -
Incoming calls bypass the general iphone lock
Although I've set up the general lock on my IPhone 3G, incoming calls bypass the mechanism and make the phone accessible by anyone who picks it up. Is there a way to require a passcode for receiving calls....I want to block all access to my phone!
Any help would be greatly appreciated.
Message was edited by: chiroguy2pittsburghYou'll find that with the iPhone locked, an incoming call will not allow access to the phone, i.e. you can only answer and talk, not access the phone OS.
-
How to bypass Fan Error on X1 Carbon
Hi folks,
We're in a real pickle right now trying to help out one of our faculty members. She needs to use her new X1 Carbon laptop but is getting a 'Fan Error' message on her X1 Carbon immediately after turning it on.
Is there anyway we can bypass this error on the X1 Carbon? We're trying the Escape key with no success. We understand that the laptop may need a fan replaced, but we really need to access data for an important conference tomorrow in Dubai.
Any ideas or suggestions? Thank you kindly!!http://forums.lenovo.com/t5/X-Series-ThinkPad-Laptops/X1-Carbon-Won-t-Boot-without-AC-Cord-reset-swi...
try this method.
Otherwise you would be in a pickle. This is one reason why i dislike Ultrabook format with their proprietary SSD format.
Regards,
Jin Li
May this year, be the year of 'DO'!
I am a volunteer, and not a paid staff of Lenovo or Microsoft -
Passing arraylist between constructors?
Hi guys,
I've pretty new to java, and I think i'm having a little trouble
understanding scope. The program I'm working on is building a jtree
from an xml file, to do this an arraylist (xmlText) is being built and
declared in the function Main. It's then called to an overloaded
constructor which processes the XML into a jtree:
public Editor( String title, ArrayList xmlText ) throws
ParserConfigurationException
Later, in the second constructor which builds my GUI, I try and call
the same arraylist so I can parse this XML into a set of combo boxes,
but get an error thrown up at me that i'm having a hard time solving- :
public Editor( String title ) throws ParserConfigurationException
// additional code
// Create a read-only combobox- where I get an error.
String [] items = (String []) xmlText.toArray (new String[
xmlText.size () ]);
JComboBox queryBox = new JComboBox(items);
JComboBox queryBox2 = new JComboBox(items);
JComboBox queryBox3 = new JComboBox(items);
JComboBox queryBox4 = new JComboBox(items);
JComboBox queryBox5 = new JComboBox(items);
This is the way I understand the Arraylist can be converted to a string
to use in the combo boxs. However I get an error thrown up at me here
at about line 206, which as far as I understand, is because when the
overloaded constructor calls the other constructor:
public Editor( String title ) throws ParserConfigurationException -
It does not pass in the variable xmlText.
I'm told that the compiler complains because xmlText is not defined
at that point:
- it is not a global variable or class member
- it has not been passed into the function
and
- it has not been declared inside the current function
Can anyone think of a solution to this problem? As I say a lot of this
stuff is still fairly beyond me, I understand the principles behind the
language and the problem, but the solution has been evading me so far.
If anyone could give me any help or a solution here I'd be very
grateful- I'm getting totally stressed over this.
The code I'm working on is below, I've highlighted where the error
crops up too- it's about line 200-206 area. Sorry for the length, I was
unsure as to how much of the code I should post.
public class Editor extends JFrame implements ActionListener
// This is the XMLTree object which displays the XML in a JTree
private XMLTree XMLTree;
private JTextArea textArea, textArea2, textArea3;
// One JScrollPane is the container for the JTree, the other is for
the textArea
private JScrollPane jScroll, jScrollRt, jScrollUp,
jScrollBelow;
private JSplitPane splitPane, splitPane2;
private JPanel panel;
// This JButton handles the tree Refresh feature
private JButton refreshButton;
// This Listener allows the frame's close button to work properly
private WindowListener winClosing;
private JSplitPane splitpane3;
// Menu Objects
private JMenuBar menuBar;
private JMenu fileMenu;
private JMenuItem newItem, openItem, saveItem,
exitItem;
// This JDialog object will be used to allow the user to cancel an exit
command
private JDialog verifyDialog;
// These JLabel objects will be used to display the error messages
private JLabel question;
// These JButtons are used with the verifyDialog object
private JButton okButton, cancelButton;
private JComboBox testBox;
// These two constants set the width and height of the frame
private static final int FRAME_WIDTH = 600;
private static final int FRAME_HEIGHT = 450;
* This constructor passes the graphical construction off to the
overloaded constructor
* and then handles the processing of the XML text
public Editor( String title, ArrayList xmlText ) throws
ParserConfigurationException
this( title );
textArea.setText( ( String )xmlText.get( 0 ) + "\n" );
for ( int i = 1; i < xmlText.size(); i++ )
textArea.append( ( String )xmlText.get( i ) + "\n" );
try
XMLTree.refresh( textArea.getText() );
catch( Exception ex )
String message = ex.getMessage();
System.out.println( message );
}//end try/catch
} //end Editor( String title, String xml )
* This constructor builds a frame containing a JSplitPane, which in
turn contains two
JScrollPanes.
* One of the panes contains an XMLTree object and the other contains
a JTextArea object.
public Editor( String title ) throws ParserConfigurationException
// This builds the JFrame portion of the object
super( title );
Toolkit toolkit;
Dimension dim, minimumSize;
int screenHeight, screenWidth;
// Initialize basic layout properties
setBackground( Color.lightGray );
getContentPane().setLayout( new BorderLayout() );
// Set the frame's display to be WIDTH x HEIGHT in the middle of
the screen
toolkit = Toolkit.getDefaultToolkit();
dim = toolkit.getScreenSize();
screenHeight = dim.height;
screenWidth = dim.width;
setBounds( (screenWidth-FRAME_WIDTH)/2,
(screenHeight-FRAME_HEIGHT)/2, FRAME_WIDTH,
FRAME_HEIGHT );
// Build the Menu
// Build the verify dialog
// Set the Default Close Operation
// Create the refresh button object
// Add the button to the frame
// Create two JScrollPane objects
jScroll = new JScrollPane();
jScrollRt = new JScrollPane();
// First, create the JTextArea:
// Create the JTextArea and add it to the right hand JScroll
textArea = new JTextArea( 200,150 );
jScrollRt.getViewport().add( textArea );
// Next, create the XMLTree
XMLTree = new XMLTree();
XMLTree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION
XMLTree.setShowsRootHandles( true );
// A more advanced version of this tool would allow the JTree to
be editable
XMLTree.setEditable( false );
// Wrap the JTree in a JScroll so that we can scroll it in the
JSplitPane.
jScroll.getViewport().add( XMLTree );
// Create the JSplitPane and add the two JScroll objects
splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, jScroll,
jScrollRt );
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(200);
jScrollUp = new JScrollPane();
jScrollBelow=new JScrollPane();
// Here is were the error is coming up
String [] items = (String []) xmlText.toArray (new String[
xmlText.size () ]);
JComboBox queryBox = new JComboBox(items);
JComboBox queryBox2 = new JComboBox(items);
JComboBox queryBox3 = new JComboBox(items);
JComboBox queryBox4 = new JComboBox(items);
JComboBox queryBox5 = new JComboBox(items);
* I'm adding the scroll pane to the split pane,
* a panel to the top of the split pane, and some uneditible
combo boxes
* to them. Then I'll rearrange them to rearrange them, but
unfortunately am getting an error thrown up above.
panel = new JPanel();
panel.add(queryBox);
panel.add(queryBox2);
panel.add(queryBox3);
panel.add(queryBox4);
panel.add(queryBox5);
jScrollUp.getViewport().add( panel );
// Now building a text area
textArea3 = new JTextArea(200, 150);
jScrollBelow.getViewport().add( textArea3 );
splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
jScrollUp, jScrollBelow);
splitPane2.setPreferredSize( new Dimension(300, 200) );
splitPane2.setDividerLocation(100);
splitPane2.setOneTouchExpandable(true);
// in here can change the contents of the split pane
getContentPane().add(splitPane2,BorderLayout.SOUTH);
// Provide minimum sizes for the two components in the split pane
minimumSize = new Dimension(200, 150);
jScroll.setMinimumSize( minimumSize );
jScrollRt.setMinimumSize( minimumSize );
// Provide a preferred size for the split pane
splitPane.setPreferredSize( new Dimension(400, 300) );
// Add the split pane to the frame
getContentPane().add( splitPane, BorderLayout.CENTER );
//Put the final touches to the JFrame object
validate();
setVisible(true);
// Add a WindowListener so that we can close the window
winClosing = new WindowAdapter()
public void windowClosing(WindowEvent e)
verifyDialog.show();
addWindowListener(winClosing);
} //end Editor()
* When a user event occurs, this method is called. If the action
performed was a click
* of the "Refresh" button, then the XMLTree object is updated using
the current XML text
* contained in the JTextArea
public void actionPerformed( ActionEvent ae )
if ( ae.getActionCommand().equals( "Refresh" ) )
try
XMLTree.refresh( textArea.getText() );
catch( Exception ex )
String message = ex.getMessage();
ex.printStackTrace();
}//end try/catch
else if ( ae.getActionCommand().equals( "OK" ) )
exit();
else if ( ae.getActionCommand().equals( "Cancel" ) )
verifyDialog.hide();
}//end if/else if
} //end actionPerformed()
// Program execution begins here. An XML file (*.xml) must be passed
into the method
public static void main( String[] args )
String fileName = "";
BufferedReader reader;
String line;
ArrayList xmlText = null;
Editor Editor;
// Build a Document object based on the specified XML file
try
if( args.length > 0 )
fileName = args[0];
if ( fileName.substring( fileName.indexOf( '.' ) ).equals(
".xml" ) )
reader = new BufferedReader( new FileReader( fileName )
xmlText = new ArrayList();
while ( ( line = reader.readLine() ) != null )
xmlText.add( line );
} //end while ( ( line = reader.readLine() ) != null )
// The file will have to be re-read when the Document
object is parsed
reader.close();
// Construct the GUI components and pass a reference to
the XML root node
Editor = new Editor( "Editor 1.0", xmlText );
else
help();
} //end if ( fileName.substring( fileName.indexOf( '.' )
).equals( ".xml" ) )
else
Editor = new Editor( "Editor 1.0" );
} //end if( args.length > 0 )
catch( FileNotFoundException fnfEx )
System.out.println( fileName + " was not found." );
exit();
catch( Exception ex )
ex.printStackTrace();
exit();
}// end try/catch
}// end main()
// A common source of operating instructions
private static void help()
System.out.println( "\nUsage: java Editor filename.xml" );
System.exit(0);
} //end help()
// A common point of exit
public static void exit()
System.out.println( "\nThank you for using Editor 1.0" );
System.exit(0);
} //end exit()
class newMenuHandler implements ActionListener
public void actionPerformed( ActionEvent ae )
textArea.setText( "" );
try
// Next, create a new XMLTree
XMLTree = new XMLTree();
XMLTree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION );
XMLTree.setShowsRootHandles( true );
// A more advanced version of this tool would allow the JTree
to be editable
XMLTree.setEditable( false );
catch( Exception ex )
String message = ex.getMessage();
ex.printStackTrace();
}//end try/catch
}//end actionPerformed()
}//end class newMenuHandler
class openMenuHandler implements ActionListener
JFileChooser jfc;
Container parent;
int choice;
openMenuHandler()
super();
jfc = new JFileChooser();
jfc.setSize( 400,300 );
jfc.setFileFilter( new XmlFileFilter() );
parent = openItem.getParent();
}//end openMenuHandler()
public void actionPerformed( ActionEvent ae )
// Displays the jfc and sets the dialog to 'open'
choice = jfc.showOpenDialog( parent );
if ( choice == JFileChooser.APPROVE_OPTION )
String fileName, line;
BufferedReader reader;
fileName = jfc.getSelectedFile().getAbsolutePath();
try
reader = new BufferedReader( new FileReader( fileName ) );
textArea.setText( reader.readLine() + "\n" );
while ( ( line = reader.readLine() ) != null )
textArea.append( line + "\n" );
} //end while ( ( line = reader.readLine() ) != null )
// The file will have to be re-read when the Document
object is parsed
reader.close();
XMLTree.refresh( textArea.getText() );
catch ( Exception ex )
String message = ex.getMessage();
ex.printStackTrace();
}//end try/catch
jfc.setCurrentDirectory( new File( fileName ) );
} //end if ( choice == JFileChooser.APPROVE_OPTION )
}//end actionPerformed()
}//end class openMenuHandler
class saveMenuHandler implements ActionListener
JFileChooser jfc;
Container parent;
int choice;
saveMenuHandler()
super();
jfc = new JFileChooser();
jfc.setSize( 400,300 );
jfc.setFileFilter( new XmlFileFilter() );
parent = saveItem.getParent();
}//end saveMenuHandler()
public void actionPerformed( ActionEvent ae )
// Displays the jfc and sets the dialog to 'save'
choice = jfc.showSaveDialog( parent );
if ( choice == JFileChooser.APPROVE_OPTION )
String fileName;
File fObj;
FileWriter writer;
fileName = jfc.getSelectedFile().getAbsolutePath();
try
writer = new FileWriter( fileName );
textArea.write( writer );
// The file will have to be re-read when the Document
object is parsed
writer.close();
catch ( IOException ioe )
ioe.printStackTrace();
}//end try/catch
jfc.setCurrentDirectory( new File( fileName ) );
} //end if ( choice == JFileChooser.APPROVE_OPTION )
}//end actionPerformed()
}//end class saveMenuHandler
class exitMenuHandler implements ActionListener
public void actionPerformed( ActionEvent ae )
verifyDialog.show();
}//end actionPerformed()
}//end class exitMenuHandler
class XmlFileFilter extends javax.swing.filechooser.FileFilter
public boolean accept( File fobj )
if ( fobj.isDirectory() )
return true;
else
return fobj.getName().endsWith( ".xml" );
}//end accept()
public String getDescription()
return "*.xml";
}//end getDescription()
}//end class XmlFileFilter
} //end class Editor
Sorry if this post has been a bit lengthy, any help you guys could give
me solving this would be really appreciated.
Thanks,
Iain.Hey. Couple pointers:
When posting, try to keep code inbetween code tags (button between spell check and quote original). It will pretty-print the code.
Posting code is good. Usually, though, you want to post theminimum amount of code which runs and shows your problem.
That way people don't have to wade through irrelevant stuff and
they have an easier time helping.
http://homepage1.nifty.com/algafield/sscce.html
As for your problem, this is a scope issue. You declare an
ArrayList xmlText in main(). That means that everywhere after
the declaration in main(), you can reference your xmlText.
So far so good. Then, inside main(), you call
Editor = new Editor( "Editor 1.0", xmlText );Now you've passed the xmlText variable to a new method,
Editor(String title, ArrayList xmlText) [which happens to be a
constructor, but that's not important]. When you do that, you
make the two variables title and xmlText available to the whole
Editor(String, ArrayList) method.
This is where you get messed up. You invoke another method
from inside Editor(String, ArrayList). When you call
this(title);you're invoking the method Editor(String title). You aren't passing
in your arraylist, though. You've got code in the Editor(String) method
which is trying to reference xmlText, but you'd need to pass in
your ArrayList in order to do so.
My suggestion would be to merge the two constructor methods into
one, Editor(String title, ArrayList xmlText). -
Code in main does not require catch, but code in constructor does
this is the original program, its all in main. i took all the code out of main and put it in a constructor to make it more usable, and started making the necessary adjustments. i eventually got it to work but i had to catch exceptions EVERYWHERE. why does this code not require so many exceptions when the code is in main?
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class MainClass {
public static void main(String args[]) throws Exception {
URL u = new URL("");
URLConnection uc = u.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
// ||
if (contentLength == -1) {
throw new IOException("Error: No File Found.");
InputStream raw = uc.getInputStream();
InputStream in = new BufferedInputStream(raw);
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
bytesRead = in.read(data, offset, data.length - offset);
if (bytesRead == -1)
break;
offset += bytesRead;
in.close();
if (offset != contentLength) {
throw new IOException("Only read " + offset + " bytes; Expected " + contentLength + " bytes");
String dirText = "text";
String dirTarget = "target";
String filename = u.getFile().substring(u.getFile().lastIndexOf('/') + 1);
String dirAndFile;
// determine weather the file is a target or is to be parsed for more files
if(contentType.startsWith("text/")) {
dirAndFile = dirText + "\\" + filename;
else {
dirAndFile = dirTarget + "\\" + filename;
FileOutputStream out = new FileOutputStream(dirAndFile);
out.write(data);
out.flush();
out.close();
}Edited by: chopficaro on May 1, 2010 8:15 AMok but still, why do i not have to catch all these exceptions when the code is in main rather than a constructor? heres the code after i put it in the constructor:
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
public class MainClass {
public static void main(String args[]) throws Exception
MainClass mc = new MainClass("http://www.google.com/intl/en_ALL/images/logo.gif");
MainClass(String addr)
URL u = null;
try
u = new URL(addr);
catch (MalformedURLException e)
// Print out the exception that occurred
System.out.println("Invalid URL "+addr+": "+e.getMessage());
URLConnection uc = null;
try
uc = u.openConnection();
catch (IOException e)
// Print out the exception that occurred
System.out.println("Unable to create "+addr+": "+e.getMessage());
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
if (contentLength == -1)
System.out.println("no file");//throw new IOException("Error: No File Found.");
InputStream raw=null;
InputStream in=null;
try
raw = uc.getInputStream();
in = new BufferedInputStream(raw);
catch (IOException e)
// Print out the exception that occurred
System.out.println("bad input stream "+e.getMessage());
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength)
try
bytesRead = in.read(data, offset, data.length - offset);
catch (IOException e)
// Print out the exception that occurred
System.out.println(e.getMessage());
if (bytesRead == -1)
break;
offset += bytesRead;
try
in.close();
catch (IOException e)
// Print out the exception that occurred
System.out.println(e.getMessage());
if (offset != contentLength)
System.out.println("didnt read enough bytes"); //throw new IOException("Only read " + offset + " bytes; Expected " + contentLength + " bytes");
String dirText = "text";
String dirTarget = "target";
try
String filename = u.getFile().substring(u.getFile().lastIndexOf('/') + 1);
String dirAndFile;
// determine weather the file is a target or is to be parsed for more files
if(contentType.startsWith("text/"))
dirAndFile = dirText + "\\" + filename;
else
dirAndFile = dirTarget + "\\" + filename;
FileOutputStream out = new FileOutputStream(dirAndFile);
out.write(data);
out.flush();
out.close();
catch (IOException e)
// Print out the exception that occurred
System.out.println(e.getMessage());
} -
How do I unlock an iPhone 4 with iOS 7 and bypass the activation lock?
How do I unlock an iPhone 4 with iOS 7 and bypass the activation lock? I can't find the previous owner and I really want to use my new iPhone, I did purchase it Second-Handed.and now I'm stuck. Ive tried recovery mode and nothing still restores and asks me the same thing. Been working on this forever- Please Help!
If you want to risk your money, fine.
To answer your questions
Is this just an iOS 7 feature?
Yes, Activation Lock is an iOS 7 feature.
Could you not restore the device to an earlier version?
No, you cannot downgrade your iOS device.
That may mean jailbreaking, I'm not sure.
Jailbreaking is not supported by Apple or this forum.
Or what about replacing the motherboard?
There are no user serviceable parts on an iPhone. -
Disable or bypass SSL on Sharepoint Foundation 2013
My SSL certificate is expired and I am going to purchase the new certificate for the server. But at the mean time,
I want to disable SSL (https) login, I've tried to remove the certificate and binding from IIS and remove the certificate
from SharePoint Central Administration interface, and also configure the mapping URL from https to http but when
I login the sharepoint website, it still try to redirect to https but cannot load the login page now. Anyone know how
to bypass and make my sharepoint site can be access through http temporary? Thanks
Rgds,
LKF4459Hi LKF4459,
Are you trying to access your SharePoint from outside your domain? If so, it might be possible that a firewall that publishes your SharePoint sites does the redirect from http to https.
Also, it may be possible that IIS is configured to always redirect to https. See this link for more information:
http://www.sslshopper.com/iis7-redirect-http-to-https.html
Regards, Nico
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer
Maybe you are looking for
-
Mail on iphone not showing up in outlook
For some reason just recently I am receiving mail on my iphone, but it doesn't show up on my desktop which uses Outlook. I have had the Iphone for a couple of months and this has just started. I use gmail and I have the Incoming Settings set to never
-
Computer crashed-all info lost. Re-installed iTunes,
Computer crashed and had to re-install everything. I did not make a backup disc of the iTunes library, which contained alot of uploaded CD's, that we no longer have. In order to sync new music we would have to competely erase the ipod content and wil
-
I'm looking at "SAP Note 1165319 - Optimizer merge fix for Oracle 10.2.0.4". Does the merge patch 8775584 contain all the following previous merge patches, especially merge patch 7228971 which contains the work around "_fix_control"='6329318:OFF'? 87
-
Hi Experts, I have a report called Repeaters Report in that i have to show the columns like: Agent ,Total Purchasers,Repeaters, Repeater Ratio,Total Purchase Amount , Repeaters Purchase Amount, Repeated Amount Ratio I got all the Column Values Except
-
Moving roles with user assignment
Hi There, Need your help... We have roles and users created in QA for training, now we want to move roles from QA to Production with user assignment. Users that are created in QA for training have also been created in Production, is it possible to mo