2

At the first glance the question may seems to be duplicated. I have done some searches in Google.But unfortunately none of the results dont match with me. I have given the questions link below.

Exception in Application start method java.lang.reflect.InvocationTargetException JavaFX image transition

JavaFX - Exception in Application start method?

Exception in Application start method

Exception in Application start method

Exception in Application start method java.lang.reflect.InvocationTargetException

Ok, Let come to my problem. I am using Netbeans and Spring for dependency injection. My code was working fine. I just added a new method and connected it with a button. After pressing the run button i have got the error.

Stack Trace:

Executing C:\Users\Dell-3460\Documents\NetBeansProjects\JavaFXApplication_Vocubulary_Own\dist\run151098339\JavaFXApplication_Vocubulary_Own.jar using platform C:\Program Files\Java\jdk1.8.0_102\jre/bin/java
Start1...........
Nov 23, 2017 10:30:52 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 8.0.141 by JavaFX runtime of version 8.0.102
Nov 23, 2017 10:30:53 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1d4f4e8e: startup date [Thu Nov 23 22:30:53 BDT 2017]; root of context hierarchy
Nov 23, 2017 10:30:53 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [vocubularyBean.xml]
Exception in Application start method

From this StackTrace i am unable to trace the error. Then i have used Try-Catch within start method but no exact error message.

Start Method :

@Override
    public void start(Stage stage) throws Exception
        {
        System.out.println("Start1...........");
        try
          {
            Parent root = FXMLLoader.load(getClass().getResource("FXML_Main.fxml"));
            System.out.println("Start2...........");
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.show();
          } 
        catch (Exception e)
            {
              e.printStackTrace();
            }
        }

Stack Trace After Adding Try-Catch in Start Method :

Executing C:\Users\Dell-3460\Documents\NetBeansProjects\JavaFXApplication_Vocubulary_Own\dist\run151098339\JavaFXApplication_Vocubulary_Own.jar using platform C:\Program Files\Java\jdk1.8.0_102\jre/bin/java
Start1...........
Nov 23, 2017 10:30:52 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 8.0.141 by JavaFX runtime of version 8.0.102
Nov 23, 2017 10:30:53 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1d4f4e8e: startup date [Thu Nov 23 22:30:53 BDT 2017]; root of context hierarchy
Nov 23, 2017 10:30:53 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [vocubularyBean.xml]
Exception in Application start method

From this stack trace i am thinking there might some problems in FXML file as second line has not printed. But my question is why it is not showing any error message? I am using SceneBuilder. I have created an empty FXML file and it is loading.

Snippet of Controller Code :

@FXML
    private void other_save_new_and_save_edit_other_word_button_action(ActionEvent actionEvent)
        {  
            bean_controller_Other_I.other_save_new_and_save_edit_other_word_button_action(actionEvent);
        }

Snippet of FXML Code:

 <Button layoutX="197.0" layoutY="32.0" mnemonicParsing="false" onAction="#other_save_new_and_save_edit_other_word_button_action" prefWidth="75.0" text="Save" AnchorPane.leftAnchor="197.0" />

Problem Identified :

public class ApplicationContextSingleTon
    {
        private static ApplicationContext applicationContext ;
        public static ApplicationContext getBean()
            {
                System.out.println(" AC_Line 1 : ");
                if(applicationContext == null)
                  {
                    System.out.println(" AC_Line 2 : ");
                    applicationContext = new ClassPathXmlApplicationContext("vocubularyBean.xml");
                    System.out.println(" AC_Line 3 : ");
                  }
                return applicationContext;
            }
    }



public interface ApplicationContext_I
    {
        ApplicationContext applicationContext = ApplicationContextSingleTon.getBean();
    }

public class Controller_Main implements Initializable,ApplicationContext_I
    {
    Controller_e2b_I bean_controller_e2b_I;
    Controller_e2e_I bean_controller_e2e_I;
    Controller_Other_I bean_controller_Other_I;

    @Override
    public void initialize(URL url, ResourceBundle rb)
        {
            bean_Initializer();
            System.out.println(".......Start........");
        }
    public void bean_Initializer()
        {
            bean_controller_e2b_I = (Controller_e2b_I) applicationContext.getBean("bean_Controller_e2b_Impl");
            bean_controller_e2b_I.setController_Main(this);

            bean_controller_e2e_I = (Controller_e2e_I) applicationContext.getBean("bean_Controller_e2e_Impl");
            bean_controller_e2e_I.setController_Main(this);

            bean_controller_Other_I = (Controller_Other_I) applicationContext.getBean("bean_Controller_Other_Impl");
            bean_controller_Other_I.setController_Main(this);
        }
//other codes
    }

<?xml version="1.0" encoding="UTF-8"?>
<beans  xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
        >

    <bean id="bean_DAO_e2b_Impl" class="com.vocubulary.e2b.DAO_e2b_Impl" ></bean>
    <bean id="bean_Controller_e2b_Impl" class="com.vocubulary.e2b.Controller_e2b_Impl" >
        <property name="bean_DAO_e2b_I" ref="bean_DAO_e2b_Impl"/>
    </bean>

    <bean id="bean_DAO_e2e_Impl" class="com.vocubulary.e2e.DAO_e2e_Impl" ></bean>
    <bean id="bean_Controller_e2e_Impl" class="com.vocubulary.e2e.Controller_e2e_Impl" >
        <property name="bean_DAO_e2e_I" ref="bean_DAO_e2e_Impl"/>
    </bean>

    <!--start : problem Area-->
    <bean id="bean_DAO_Other_Impl" class="com.vocubulary.other.DAO_Other_Impl" ></bean>
    <bean id="bean_Controller_other_Impl" class="com.vocubulary.other.Controller_Other_Impl" >
        <property name="bean_DAO_Other_I" ref="bean_DAO_Other_Impl"/>
    </bean>
    <!--end : problem Area-->
</beans>

I think no need to describe codes as they are self explanatory. I have identified some xml codes as problem in the xml mapping file. I think finally i have identified the problem.

If i am keeping the codes active within the problem area in xml mapping file then the problem is happening. But if i am commenting those lines, the program is starting well.

And another problem is if those lines are active, within ApplicationContextSingleTon class, "AC_Line 3" is not being printed. Means the application is being halted at "AC_Line 2".

I think i have mapped the classes properly. As i am using Netbeans, if i do ctrl+clik on the class names, mapped in the problem area, Netbeans is taking me the class.

Now i have two Questions :

  1. Why i am not getting full stack trace?

  2. What is the wrong with those lines?

Black Swan
  • 813
  • 13
  • 35
  • How you initialize Spring DI?? Where you hook CDI to FXMLLoader??? – Rafael Guillen Nov 23 '17 at 17:20
  • This is probably not the solution, but it would be good to rule it out... is it possible to satisfy the condition mentioned in the JavaFX API version WARNING? – Jose Martinez Nov 23 '17 at 17:22
  • @Rafael Guillen, sorry i am not familiar with CDI. I am taking the bean by application context at the overrided "initialize" method. – Black Swan Nov 23 '17 at 17:28
  • When I say CDI I mean Spring DI, how do you integrate Spring Framework to JavaFx?? – Rafael Guillen Nov 23 '17 at 17:30
  • That's not the complete stack trace. Can you post the rest of it? – James_D Nov 23 '17 at 17:53
  • @James_D, trust me, it is complete stack trace... – Black Swan Nov 23 '17 at 17:55
  • 1
    Well, it may be all you are seeing, for some reason, but it is not the complete stack trace. You need to figure out how to get the complete stack trace in order to diagnose the problem. Are you actually reaching the `catch` block? If so, you really should see the rest of the stack trace from the code that is there. – James_D Nov 23 '17 at 17:59
  • @James_D, please check the Edit. – Black Swan Nov 23 '17 at 18:16

2 Answers2

2

I have recently run into the issue with "Exception in start method" being printed but no stack trace being printed. The solution (at least for me) to catching the exception is to catch a Throwable rather than an Exception. Example:

@Override
public void start(Stage stage) throws Exception {
    try {
        //... start method code here
    } catch(Throwable t) {
        t.printStackTrace()
    }
}
  • Welcome to Stack Overflow. Just be sure that you're catching Throwable for the right reasons: [https://stackoverflow.com/a/2274130/773334] (https://stackoverflow.com/a/2274130/773334) – JACH Jan 27 '21 at 00:22
  • works for me. you can use Exception instead. – Lucke Nov 10 '22 at 17:45
0

I just barely ran into this issue, and could not figure out why the exception was not printing. Like you, I tried surrounding my entire Start method in a try-catch. It turns out that STDERR isn't being sent to the proper location. The way I found this out was by surrounding with a try-catch (again), and using System.out.println(ex) instead of ex.printStackTrace(). You could also use ex.printStackTrace(System.out).

I suppose I am late to the party, but hopefully I can help anybody who may encounter this same issue.

Bennett D
  • 61
  • 1
  • 1
  • 5