NullPointer when accessing FXML annotated object

Hello

I had a strange behavior (!) using an annotated object FXML...

Consider the following:

You have a soft with build FXML UI.

There is a button named connectB which is annotated @FXML...

In the initialize method of my application, I have disable this button.

After the start of my application, I want to connect to a database...

Therefore, I use a task < void >

I put everything together in one class (the main application class)

Here's the code...

public class MainApp extends Application implements Initializable{

// ... several other objects
@FXML
  private Button connectB;

@Override
 public void initialize( URL location, ResourceBundle resources ) {

 connectB.setDisable( true );
  // ...
}

@Override
 public void start( final Stage stage ) throws Exception {
 

 // setup the fxml loader
 final FXMLLoader guiLoader = new FXMLLoader( getClass().getResource( "/fxml/Scene.fxml" ) );
 // load the root node
 rootNode = guiLoader.load();

 Scene scene = new Scene( rootNode );
 scene.getStylesheets().add( "/styles/Styles.css" );

 stage.setTitle( "Test" );
 stage.setScene( scene );
 stage.show();
    
          // start the task async via an ExecutorService
 es.sumbit( new DBSetupTask() );
 }

// the db connection task class
private final class DBSetupTask extends Task<Void> {

 @Override
 protected Void call() throws Exception {

 try {
 // connecto to DB
 PersistenceManager.initSessionFactory();

 }
 catch ( final ExceptionInInitializerError eiiE ) {
 mainAppLogger.error( "Failed to connect to DB!", eiiE );

 }
 return null;
 }

 @Override
 protected void failed() {
 super.failed();
 connectB.setDisable( true );
 }

 @Override
 protected void cancelled() {
 super.cancelled();
 }

 @Override
 protected void succeeded() {
 super.succeeded();
 connectB.setDisable( false );

 }

 @Override
 protected void running() {
 super.running();
}

 }

}

The connectB is not null in the initialize method, but later in the task class


Someone knows why?

Kind regards

Olek

I put everything together in one class (the main application class)

Do not do this. Your application is not your controller.

Here's what happens:

The FXMLoader analyzes your FXML file. When it encounters the attribute fx:controller (which I assume that you have set to "MainApp"), it creates a new instance of the specified class. Once the object hierarchy specified in the FXML file is assembled, injects values in the controller instance, he created and then calls initialize() on this object.

If you find yourself with two instances of the MainApp class; one in which the start (...) method is called and the other in which the initialize (...) method is called. The values of injection (connectB) are initialized only in the second case.

To resolve this problem, set a controller class regardless of your application class:

public class MyController {
    @FXML
    private Button connectB ;
    public void initialize() {
        // ...
    }
    public void setupDB() {
        es.submit(new DBSetupTask());
    }

    private final class DBSetupTask extends Task { ... }
}

and then call the appropriate method of your start method (...):

public class MainApp extends Application {
   @Override
   public void start(Stage stage) {
       final FXMLLoader guiLoader = new FXMLLoader(getClass().getResource("/fxml/Scene.fxml"));
       rootNode = guiLoader.load();
       Scene scene = new Scene(rootNode);
       scene.getStylesheets().add("/styles/Styles.css");
       stage.setTitle("Test");
       stage.setScene(scene);
       stage.show();

       MyController controller = (MyController)guiLoader.getController();
       controller.setupDB();
   }
}

Tags: Java

Similar Questions

  • Screen reader accessibility for noninteractive objects

    I work at 8 Cp and try to do a course entirely compatible Section 508. I tested with the Window-Eyes screen reader. The screen reader can access the reading and fine TOC bar buttons, and it usually recognizes interactive elements on the screen. However, most of the time, the screen reader is not recognizing the legends or the intelligent forms with text on screen. Many slides are just text and a button transparent text to pause the screen, therefore, that I need the screen reader to read the content of the course. According to the documentation, I shouldn't copy the text in the name of accessibility for each object, although I tried in a few places without success. The accessibility feature looks so flaky. From time to time, I can get something to work, but not completely, or I can't repeat.

    I was able to get the screen reader to read the text if I remove all the interactive elements, including the reading and TOC bar. In other words, if I have a class 1-slide, Captivate accessibility works. As soon as I try to give people an option to move to the next slide with a control button or the play bar, it stops working.

    Yes, accessibility is enabled. I tried to hide the rectangle around the objects in HTML5. I tried editing both SWF and HTML5. I tried to text buttons transparent instead click on the boxes, which seemed to make a small difference. I tried different shortcuts and ensured that I never use the same shortcut twice on a single slide.

    How access a screen reader text within Captivate content? The documentation says you can access it with arrows, but it does not work. People do in the real world in order to make it accessible when the program does not work the way that the documentation says it should? I know from reading other threads that some organizations have given up and just went to provide text alternatives.

    I am open to any suggestion.

    My suggestion is that do you what others have already done.  Try to make Captivate content "fully Section 508 compliant" is not a realistic goal.

    As you noted, screen readers prefer to pay attention to the interactive objects.  If you must use interactive objects even for text objects that does not need to be buttons.  (You can set their action IT success to no Action so that they just sit and do nothing.)

    But you're still going to have problems at some point and these questions will be showstoppers.

    So, save yourself a lot of hassle and invoke the clause to exhaust all of the Section 508 and W3C accessibility documents which allows you to offer a "text alternative".  Create an accessible MS Word or PDF document that contains the same content.  You're going to do in a short time it would take you to try in VAIN to get e-learning content of Captivate to satisfy all the rules of Section 508.

    Probably NOT what you wanted to hear, but I really think someone needs to say this.

  • 'Invalid Annotation object' error, cannot save

    Hello

    My father is worked on a document .pdf of 50 + page (adding annotations etc.) for several hours. When adding the latest annotation, it has shown a pop-up window saying "no valid Annotation object. No matter how many times press us 'OK', the pop-up window shows once again. We can not even save the document or close it normally. I know it can force always close drive, but that won't save the document. There's a .tmp in AppData\Roaming\Adobe\Acrobat\10.0\AutoSave file, that would help me to recover the document if I shut the window? Or is there a way we could save the document?

    The OS is Windows 7. Thank you!

    Make a copy of this file to another location before closing the application. Then force-close, he re - open and see if she's trying to recover the file. If not, you can use the .tmp file, just rename it first to .pdf...

  • Access the main object of a SWF file in memory

    Hey.

    I'm trying to access the main object of a SWF file in memory. Consider the following code:

    package test {}
    import flash.display.Sprite;
    import flash.utils.ByteArray;

    SerializableAttribute public class Main extends Sprite {}
    public void Main (): void {}
    var b:ByteArray = new ByteArray();
    b.writeObject (this); This main object is what I'm trying to access
    }
    }
    }

    However, when I do a trace (b.length), the value I get does not match the length of the actual SWF file, then perhaps that there is another way.

    I am trying to achieve the same type of content that you would get if you load an external SWF using loadBytes, unless I want to access the principal object of SWF (running in memory) in this way.

    I have this even possible?

    Thank you.

    Hey.

    Well, I never knew a solution to it (if it is still possible to what I asked). However, I believe that I've implemented a workaround solution that should be enough for my needs. Perhaps it may help someone else too:

    Although I can not (seem to) get the SWF running access itself to memory, I can load another copy of itself. When I tested the copy loaded (in memory) and compared with the content of the file on the disk, using a hex editor, content match!

    This allows me to do things like control totals and which do not. An implementation is to use this technique to guard against the 'cache-hacking' of sovereign wealth funds.

  • Problem of access to an object in a VBox

    Hello!

    I have a problem with access to an object that is in a VBox.
    I made an example so you can see my problem. I'm trying to access pnlChat.
    If you load the swf file you will not see the alert because there is something wrong (and I don't know what)
    If you try to delete the < mx:VBox > tags that surround the pnlChat Panel, it will not work.

    Why can't I access the object when it's in a VBox?

    Thank you

    'Jimmy Jeeves' wrote in message
    News:g8jv84$5ib$1@forums. Macromedia.com...
    > Hi!
    >
    > I have a problem with access to an object that is in a VBox.
    > I made an example so you can see my problem. I am trying to access
    > pnlChat.
    > If you load the swf file you will not see the alert because there is something
    > evil
    > (and I don't know what)
    > If you try to remove the tags that surround the pnlChat Panel, it
    > will be
    > work.
    >
    > Why can't access this object when it's in a VBox?

    In the FAQ I am compiling:

    Q: I need to set a property or add a listener for events on a component
    It's in a ViewStack/TabNavigator/accordion. When the component is not
    the first child of the browser container, I get null object error
    (#1009). What causes this and how can I solve this problem?
    R: by default, the Navigator container create only the children of
    each component this component is seen. The easy way to fix this is to set the
    creationPolicy for the browser to 'all '. However, this will cause your
    request to take more time to load. A better way to solve this problem is to wait
    a future event, like creationComplete on the component that you want to access,
    or use the link to 'pull' data in the component.
    The way I handle it is to call invalidateProperties() on the evolution of the
    ViewStack. I then override commitProperties() and claim an initializer of «»
    each pane. In the body of each initializer function, I check to see if the
    selectedItem to the viewStack is one that cares about my initalizer. If
    No, I just got back from the function immediately. This initializer inside
    function, I set properties and add listeners as appropriate.

  • Firefox has suddenly start delay when accessing the secure site

    We have an application Java Tomcat 7 on Amazon Web Services EC2 server. The server is configured so that our application is the root application and is accessible from port 80. The application and the Tomcat are configured with SSL, so that whenever someone types in the url of the site (e.g. www.something.net) Tomcat will switch to HTTPS and use port 8443.
    This all works fine, but it seems that if for some reason any Firefox expires when accessing the site, it will never reconnect on the site and any attempt to connect using www.something.net indicates that the connection has expired. Yet if you put in the port number (for example, www.something.net:8443) happens immediately.
    I tried setting compensation in web cache content, defining the limit of cache to zero and by disabling web content offline. None of this has worked. Re-installing Firefox worked.
    We if the question was limited to Firefox, but we did eventually run run in on Chrome too. On Chrome, I was able to get the browser to connect to the site by going to settings > advanced > clear data of the browser and delete the browser history, download, history, cookies and cache of images and files. Once I did the site come immediately with www.something.net and switch to HTTPS as it is supposed to do.
    It took me several months to encounter this problem. But other users have encountered immediately (for example, when configuring a new machine).
    Anyone can shed some light on this? I saw some issues, but none of them had what contributed to my situation. Can anyone suggest a way to remove all that is prevent Firefox to connect?

    Pass port SSL 8443 to 443 has solved the problem. It seems that when the www.something.net url is entered, Firefox remembers that it's an SSL site and automatically add the 's' to get the https. In fact after the timeout, the url in the browser line https:www.something.net. Of course, this is by default the SSL port (443) standard, which does not work if 8443 is used. Join port 443 has solved the problem.

    If you read about Tomcat configuration, the default SSL port is 8443. Maybe this is done for the test, but there never seems to be explained that there could be problems with 8443.

  • access the document object in the framework

    access the document object in the framework
    ------------------------------------------------
    Hi, MVP!

    There are 2 frames, frame1 and frame2, in my web page. I want to access the document using vb frame1 object and the web browser. How can I write codes front right to do?

    Thank you

    Hi Stanley.K,

    Your question of Windows is more complex than what is generally answered in the Microsoft Answers forums, since it relates to coding in Visual Basic Application Script. It should be better in Visual Basic on MSDN Forums.

    Please post your question in the MSDN Forums by visiting the following link:

    http://social.msdn.Microsoft.com/forums/en-us/vbgeneral/threads

  • Get an error when accessing network drive

    When access to a network drive, windows Explorer stops working, the details of the problem has the information below:

    Signature of the problem:
    Problem event name: InPageError
    Error state code: c0000185
    Type of media loopholes: 00000000
    The system version: 6.0.6002.2.2.0.768.3
    Locale ID: 1033
    Additional information 1: 3f99
    More information 2: 7b94c546746d8721f4815f57894d509c
    Information additional 3:4077
    Additional information 4: 957418e1c18d4eef54a00dc53de02605

    Read our privacy statement:
    http://go.Microsoft.com/fwlink/?LinkId=50163&clcid=0x0409

    Hi va3449,

    1. When was the last time it was working fine?
    2. Did you the latest changes on the computer?

    Check if you can access the network from mode drive safe mode with networking.

    Steps to start in safe mode with networking

    Note: Do not try the step below if you use wireless or internet Dialup Connection

    (a) restart your computer if it is running.

    (b) press F8 after your computer powers initially on.

    (c) once you see the menu Advanced Boot Options, you can stop tapping.

    d keys) use the up/down arrow to select your selection.

    (e) select Mode safe mode with networking and press ENTER.

    (f) you should see loading drivers and wait please.

    (g) you should then be at the Welcome screen.

    (h) logon to your computer using an account with administrator privileges.

    If you can access the network from mode drive safe mode with networking then I would suggest that you do own start-up to check whether a third-party program installed on the computer is the origin of the problem in normal mode.

    To help resolve the error and other messages, you can start Windows Vista or Windows 7 by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.

    See the link below to learn more about how to clean boot.

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    http://support.Microsoft.com/kb/929135

    Reset the computer to start as usual

    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:

    (a) click Start, type msconfig in the search box and press ENTER.

    (b) If you are prompted for an administrator password or for confirmation, type your password or click on continue.

    (c) under the general tab, click the Normal startup option, and then click OK.

    (d) when you are prompted to restart the computer, click on restart.

    I hope this helps!

    Halima S - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Why Windows Explorer (Windows 7 PC to the Server 2003 AD domain) keep crashing when accessing files on a network share.

    1. Why Windows Explorer (Windows 7 PC to the Server 2003 AD domain) keep crashing when accessing files on a network share.

    Hi John,.

    The question you posted would be better suited in the TechNet Forums. I would recommend posting your query in the link below.

    http://social.technet.Microsoft.com/forums/en-us/w7itprosecurity/threads

    Hope this information helps.

  • "no execution is access to directory object ' procedure

    I have an external table which cannot launch procedure but who can perform simple PL/SQL code.

    DB is 12 c, connected user shared with DBA privileges and of course read, write on directory

    Allows from the end:

    KUP-04087: no execute access to directory object SCRIPT_DIR
    

    -pass

    QL> declare
      v_ind               number;
    begin
      select count(*)
        into v_ind
        from PDBS_LIST
       where PDB_NAME = 'CORE';
       dbms_output.put_line(v_ind);
    end;  2    3    4    5    6    7    8    9   10   11   12
     13  /
    
    0
    
    
    PL/SQL procedure successfully completed.
    

    -does not

    SQL>  create procedure nir_test as
      v_ind               number;
    begin  select count(*)
        into v_ind
        from PDBS_LIST
       where PDB_NAME = 'CORE';
    end;  2    3    4    5    6    7    8    9   10
     11  /
    
    
    Procedure created.
    
    
    SQL> exec nir_test;
    BEGIN nir_test; END;
    *
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04087: no execute access to directory object SCRIPT_DIR
    ORA-06512: at "C##ADMIN.NIR_TEST", line 6
    ORA-06512: at line 1
    

    The table:

      CREATE TABLE "C##ADMIN"."PDBS_LIST" 
       ( "PDB_NAME" VARCHAR2(30 CHAR), 
      "CREATED_AT" CHAR(19 CHAR), 
      "SIZE_MB_ALLOC" NUMBER, 
      "SIZE_MB_USED" NUMBER
       ) 
       ORGANIZATION EXTERNAL 
        ( TYPE ORACLE_LOADER
          DEFAULT DIRECTORY "SCRIPT_DIR"
          ACCESS PARAMETERS
          ( records delimited by newline
        preprocessor SCRIPT_DIR:'get_pdbs_list.sh'
        fields terminated by whitespace ldrtrim
          )
          LOCATION
           ( 'Do_NOT_Delete.txt'
           )
        );
    

    create the directory of the same user solved the problem.

    But I do not know why because I give read, write to this user if the directory was created through any other user.

  • After that the effects cannot continue: error when access to the files instead of inside "/ users/dsvp/Library/Preferences/Adobe/After Effects / 13.8.

    After Effects after several months, I now can't launch After Effects without this error: After Effects can't continue: error when access to the files instead of inside "/ users/dsvp/Library/Preferences/Adobe/After Effects / 13.8.  There is no subfolder this Library which is the first obvious sign of something not going.  I've uninstalled and reinstalled twice with the same error and lack of file structure.  I do not understand why a re - install does not create the files and folders needed.

    reset your preferences - http://helpx.adobe.com/after-effects/using/preferences.html

    [moved from the installation, update, & members of Acrobat After Effects]

  • After that the effects cannot continue: error when access to the files instead of inside "/ users/me/Library/Preferences/Adobe/After Effects / 13.8", if it please check the file permissions and try again.

    After that the effects cannot continue: error when access to the files instead of inside "/ users/me/Library/Preferences/Adobe/After Effects / 13.8", if it please check the file permissions and try again.

    [Fixed spelling - Mod]

    Go to the folder listed in the path and change the permissions to read/write. Do you know how? It is in the info file.

  • When I transform an object effects don't are not scaling with him... why?

    When I transform an object effects don't are not scaling with him... why?

    You must make the smart object layer and then transform.  Layer styles dimensionnera then with the object.

  • When I create any object and select the object I can't resize

    Hello

    I have a version of the track of the Illustrator, something I problem with my selection tool when I select any object or text I can't resize it there are no show any option for this, happens on the last day. I have reset my Illustrator, but it still has problem. Please give me a solution.

    Thank you

    umangkansagra,

    How about Ctrl / Cmd + Shift + B to switch between showing and hiding the bounding box?

    Absence of any (other) cause/cure, try the list:

    Sometimes, (some) things may fail or stop working for no apparent reason. When (other) possible reasons/remedies do not work, it is perhaps a kind corruption (temporary or permanent), or even preference settings which disturbs, which can be cured with something on the following list put in place in order to provide a catch-all solution for otherwise intractable cases. It starts with a few easy suggestions and safe) 1 and 2) for cases less serious and goes two ways 3) and 4) to reset the default preferences (easily but irreversibly and more laboriously but more completely and also reversible), then follows a list 5) various other possibilities, and it ends with a complete reinstallation 6). If no other suggestion doesn't work, or if no other suggestion appears, you can start on the list and decide how to go or who can apply.

    The following is a general list of things, try when

    (A) the question is not in a specific file,

    (B) you have a printer installed, connected and turned on if it's a physical printer (you can use Adobe PDF/Acrobat Distiller as a printer by default without the need to have a printer on, of course you will need to specify when you really need print on paper), and

    (C) It is not caused by problems with opening a file from external media (see below).

    You tried/made some of them already; 1 and 2) are easier for temporary strangenesses and 3) and 4) specifically may be corrupted/inconvenient preferences); ((5) is a list in itself and 6) is the last resort.

    If possible / there is, you must record a current work first, of course.

    (1) close Illy and open again.

    (2) restart the computer (you can make up at least 5 times);

    (3) close Illy and press Ctrl + Alt + Shift / Cmd + Option + shift during startup (easy, but irreversible);

    4) move the folder (follow the link with this name) with closed Illy (more tedious but also more thorough and reversible), for CS3 - CC you can find the file here:

    https://helpx.Adobe.com/Illustrator/KB/preference-file-location-Illustrator.html

    5 look through and try the relevant among the other options (click on the link with that name, item 7) is a list of the usual suspects among other applications which can disturb and confuse Illy, point 15) applies to the maybe CS5, CS6 and CC);

    Even worse, you can:

    6 (A) uninstall (check the box to delete the preferences, if any), B) run the cleanup tool (if you have CS3/CS4/CS5/CS6/CC) and C) reinstall. It is important to use this step three way: otherwise, things may persist.

    http://www.Adobe.com/support/contact/cscleanertool.html

  • I'm updating photoshop today and when I drag an object from illustrator to photoshop, the object doesn't turn into a dynamic object why?

    Update photoshop today and when I drag an object from illustrator to photoshop object market not turning into a smart object why?

    OK - think I have this sorted out now.

    When you copy and paste an Illustrator file in Photoshop, you get the dialog box PASTE.

    You can paste as smart object, Pixels, path and shape layer. In the past, you would select depending on what you want (in my case for most Smart Object) and viola - you have your dynamic object. However, in the newly revised version, there is a checkbox in low called "Add to my current library" If this box is checked, it becomes a library file that displays with a 'cloud' icon in the layer. If you uncheck the 'Add to my current library' it won't matter as a regular smart object.

Maybe you are looking for

  • Health Dashboard missing IoS10?

    I use the application health to fire the blood pressure, heart rate and blood sugar levels on a daily basis. In earlier versions of IoS, I got all this information available on a single screen--dashboard - but this seems to have disappeared from IoS1

  • ICloud family member App requests

    Hello Fact the colossal mistake of buying my daughter an iPod Touch 5th (iOS 9.3.5) for her birthday and defining its place as a member of the family in iCloud, so no matter what application it wants to download (and God, there are many of them) must

  • Qosmio F10 does not start

    Hello my partner has a laptop qosmio who appears to be dead. He used it apparently pink lines appears across the screen, and it was cut. He tested food that looks very good. He gets the lights coming but they do nothing and the computer shows nothing

  • Want 7640: HP Envy 7640 black Rectangles

    New printer. When I print documents (.) PDF's all I printed that day) the printer prints random black rectangles on the text. I ran the diagnostic tests and other tools.   Went to the HP page to download the drivers. Don't know how if I have the curr

  • my jumps to cursor that I will be typing aline upward gaze and she was moved upward, aline and help slug

    When linking an email or in response to a note from messenger, I'm on a single line typing away and looking for the next thing I know the cursor jumped aline or 2 and tapping on another line; What change fixes or applications must I do?   Thank you