title: ClassNotFoundException on new custom control - JavaFx
body: <p>I am creating a simple project for my university, and at some point on my UI I wanted an Text Field in which the user input will be checked if it is a number or not. If yes, it will write the value to the Text Field. Otherwise it will leave it as it is. I must note that <strong>I do not</strong> want to use a spinner and also <strong>I do not</strong> want to create the custom control as a JAR and then import it. Now, I used the <code>NumericTextField</code> class that i took from <a href="https://stackoverflow.com/a/18959399/5900485">here</a>, but when i try to use it I get from both intelliJ idea(console) and the scene builder this error: </p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException</p>
  </blockquote>
  
  <p>I read several topics in stackoverflow that were talking for the specific issue, but none of these gave me a solution to my issue.</p>
  
  <p>This is how I use the <code>NumericTextField</code> class from the fxml file:</p>
  
  <pre><code>&lt;NumericTextField fx:id="simpleTxt" layoutX="53.0" layoutY="87.0" prefHeight="39.0" prefWidth="205.0" /&gt;
  </code></pre>
  
  <p>And the custom control i imported it in the fxml file like this:</p>
  
  <pre><code>&lt;?import com.MyProjectName.NumericTextField?&gt;
  </code></pre>
  
  <p>The code of the <code>NumericTextField</code> class:</p>
  
  <pre><code>package com.MyProjectName;
  import javafx.scene.control.TextField;
  public class NumericTextField extends TextField
  {
      @Override
      public void replaceText(int start, int end, String text)
      {
          if (validate(text))
          {
              super.replaceText(start, end, text);
          }
      }
      @Override
      public void replaceSelection(String text)
      {
          if (validate(text))
          {
              super.replaceSelection(text);
          }
      }
      private boolean validate(String text)
      {
          return text.matches("[0-9]");
      }
  }
  </code></pre>
  
  <p>I load the form like this:
  <a href="https://image.prntscr.com/image/auJdHFIFSoC_WY9i3p8eOA.png" rel="nofollow noreferrer"><img src="https://image.prntscr.com/image/auJdHFIFSoC_WY9i3p8eOA.png" alt="enter image description here"></a></p>
  
  <p>This is the error I get from the console:</p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
      at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1787)
      at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1670)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
      at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8863)
      at javafx.controls/javafx.scene.control.Button.fire(Button.java:200)
      at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
      at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
      at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3876)
      at javafx.graphics/javafx.scene.Scene$MouseHandler.access$1300(Scene.java:3604)
      at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1874)
      at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2613)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
      at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
      at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
      at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
      at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:189)
      at java.base/java.lang.Thread.run(Thread.java:844)
  Caused by: java.lang.reflect.InvocationTargetException
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
      at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
      at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
      at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1784)
      ... 47 more
  Caused by: javafx.fxml.LoadException: 
  /C:/Users/miche/IdeaProjects/CS%20106%20-%20Final%20Project/out/production/CS%20106%20-%20Final%20Project/com/PatientManagementSystem/AddEditPatient.fxml
      at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
      at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2863)
      at javafx.fxml/javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2707)
      at javafx.fxml/javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2676)
      at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2542)
      at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
      at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
      at com.PatientManagementSystem.MainFormController.OnInsertNewPatient(MainFormController.java:114)
      ... 58 more
  Caused by: java.lang.ClassNotFoundException: com.PatientManagementSystem$NumericTextField
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
      at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2931)
      at javafx.fxml/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2920)
      at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2861)
      ... 64 more
  </code></pre>
  
  <p>If there is someone that can spot what I am doing wrong, it will be great! Thank you all in advance! </p>