2015-09-18 2 views
-1

je rencontre un problème avec les lignes 112/113/114 le programme compilera sans eux, je suis en train d'essayer d'obtenir les données de (base de données ObservableList) et l'afficher sur la table, j'essaie de garder les variables comme date, double. les a changé en SimpleDoubleProperty, SimpleObjectProperty.en essayant d'afficher des objets sur la table JAVAFX et je reçois java.lang.NullPointerException

c'est l'exception devient am

at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown 
Source) at 
com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown 
Source) ... 1 more Caused by: java.lang.NullPointerException at 
org.xcellcomm.Controller.initialize(Controller.java:103) ... 23 more 
Exception running application org.xcellcomm.Start 




package org.xcellcomm; 


import java.net.URL; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.ResourceBundle; 


import javafx.beans.property.SimpleDoubleProperty; 
import javafx.beans.property.SimpleObjectProperty; 
import javafx.beans.property.SimpleStringProperty; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.control.RadioButton; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.control.ToggleGroup; 
import javafx.scene.control.Alert; 
import javafx.scene.control.Alert.AlertType; 
import javafx.scene.control.cell.PropertyValueFactory; 
import javafx.scene.control.Button; 
import javafx.scene.control.CheckBox; 

import javafx.scene.control.TextField; 






public class Controller implements Initializable { 

    private final ObservableList<Mrc> data = 
       FXCollections.observableArrayList(); 

    Date date; 
    ArrayList<Mrc> dailyMRC; 

    final static int VALUEBUNDLE = 5; 
    final static int PHP = 6; 
    final static int BLOCKIT = 1; 
    final static int RHAPSODY = 10; 
    final static int WORLDCALLING = 5; 
    final static int LOOKOUT = 3; 



     @FXML 
     private CheckBox checkboxFeatureLookout; 

     @FXML 
     private RadioButton plan40Radio; 

     @FXML 
     private CheckBox checkboxBlockIt; 

     @FXML 
     private CheckBox checkboxFeatureValueBundle; 

     @FXML 
     private TextField textfeildTodayGoal; 

     @FXML 
     private Button buttonAddActivation; 

     @FXML 
     private CheckBox checkboxFeatureRhpsody; 

     @FXML 
     private CheckBox checkboxFeatureWorldCalling; 

     @FXML 
     private RadioButton plan50Radio; 

     @FXML 
     private CheckBox checkboxFeaturePhp; 

     @FXML 
     private RadioButton plan60Radio; 

     @FXML 
     private TextField textfeildTodayActivations; 

     @FXML 
     private TableView<Plana> dailyActivationTable; 

     @FXML 
     private TableColumn<Plana, Date> dailyActivationTimeColon; 

     @FXML 
     private TableColumn<Plana, Double> dailyActivationPlanColon; 


     private final ObservableList<Plana> database = 
       FXCollections.observableArrayList(); 
     @Override 
     public void initialize(URL location, ResourceBundle resources) { 
dailyActivationPlanColon = new TableColumn<Controller.Plana, Double>(); 
dailyActivationTimeColon = new TableColumn<Controller.Plana, Date>(); 
dailyActivationTable.getColumns().addAll(dailyActivationPlanColon,dailyActivationTimeColon); 
      dailyMRC = new ArrayList<>(); 

      ToggleGroup group = new ToggleGroup(); 
      plan40Radio.setToggleGroup(group); 
      plan50Radio.setToggleGroup(group); 
      plan60Radio.setToggleGroup(group); 


      dailyActivationPlanColon.setCellValueFactory(new PropertyValueFactory<Plana, Double>("PlanProperty")); 
      dailyActivationTimeColon.setCellValueFactory(new PropertyValueFactory<Plana,Date>("dateProperty")); 
      dailyActivationTable.setItems(database); 


     } 


     //Getting input from the GUI and Calculate the MRC Constructor 
     private int newActivationCalculater(){ 
      int mrc=0; 
      if(plan40Radio.isSelected())mrc=+40; 
      if(plan50Radio.isSelected())mrc=+50; 
      if(plan60Radio.isSelected())mrc=+60; 
      if(checkboxBlockIt.isSelected())mrc=+BLOCKIT; 
      if(checkboxFeatureLookout.isSelected())mrc=+LOOKOUT; 
      if(checkboxFeaturePhp.isSelected())mrc=+PHP; 
      if(checkboxFeatureRhpsody.isSelected())mrc=+RHAPSODY; 
      if(checkboxFeatureValueBundle.isSelected())mrc=+VALUEBUNDLE; 
      if(checkboxFeatureWorldCalling.isSelected())mrc=+WORLDCALLING; 


      return mrc; 
     } 

     //Getting the Current time for the mrc constructor 
     private Date currentTime(){ 

      Date date = new Date(); 
     return date; 

     } 


     public void buttonAddActivationPressed(){ 
      if(plan40Radio.isSelected()||plan50Radio.isSelected()||plan60Radio.isSelected()){ 
     double mrc = (double)newActivationCalculater(); 
     Date date = currentTime(); 
     //Mrc newactivation = ; 

     unselectAllItem(); 

     database.add(new Plana((int)mrc, date)); 
     todayactivationRefresh(); 



      }//if end 
      else{//if user did not select plan 

       Alert alert = new Alert(AlertType.WARNING); 
      alert.setTitle("Warning!"); 
      alert.setHeaderText("Something wrong:)"); 
      alert.setContentText("You didn't select a Plan"); 

      alert.showAndWait();} 
     } 
     void todayactivationRefresh(){ 
      String todayactivation=dailyMRC.size()+""; 
      textfeildTodayActivations.setText(todayactivation); 
     } 
     void unselectAllItem(){ 
      plan40Radio.setSelected(false); 
      plan50Radio.setSelected(false); 
      plan60Radio.setSelected(false); 

      checkboxBlockIt.setSelected(false); 
      checkboxFeatureLookout.setSelected(false); 
      checkboxFeaturePhp.setSelected(false); 
      checkboxFeatureValueBundle.setSelected(false); 
      checkboxFeatureWorldCalling.setSelected(false); 
      checkboxFeatureRhpsody.setSelected(false); 


     } 

     public class Plana {// its might not work because it is it's not public 

       // private final SimpleStringProperty dateStringProperty; 
       private final SimpleDoubleProperty PlanProperty; 
       private final SimpleObjectProperty<Date> dateProperty; 





       private Plana(double gPlan, Date gDate) { 
        // this.dateStringProperty = new SimpleStringProperty(gStringDate); 
        this.PlanProperty = new SimpleDoubleProperty(gPlan); 
        this.dateProperty = new SimpleObjectProperty<Date>(gDate); 
       } 

       /** 
       * @return the dateStringProperty 
       */ 
      // public SimpleStringProperty getDateStringProperty() { 
       // return dateStringProperty; 
       //} 

       /** 
       * @return the planProperty 
       */ 
       public SimpleDoubleProperty getPlanProperty() { 
        return PlanProperty; 
       } 

       /** 
       * @return the dateProperty 
       */ 
       public SimpleObjectProperty<Date> getDateProperty() { 
        return dateProperty; 
       } 
      } 
    } 

et voici le startclass:

package org.xcellcomm; 



import java.util.Date; 



import javafx.application.Application; 
import javafx.beans.property.SimpleDoubleProperty; 
import javafx.beans.property.SimpleObjectProperty; 
import javafx.collections.FXCollections; 
import javafx.collections.ObservableList; 
import javafx.fxml.FXML; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.control.cell.PropertyValueFactory; 
import javafx.stage.Stage; 

public class Start extends Application { 





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


     Parent root = FXMLLoader.load(getClass().getResource("mainMrc.fxml")); 

     Scene scene = new Scene(root); 

     stage.setTitle("MRC Monitor"); 
     stage.setScene(scene); 
     stage.show(); 



    } 
    public static void main(String []args){ 
     launch(args); 
    } 



} 

mainMrc.fxml

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.*?> 
<?import javafx.scene.text.*?> 
<?import javafx.scene.chart.*?> 
<?import javafx.geometry.*?> 
<?import javafx.scene.control.*?> 
<?import java.lang.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.layout.VBox?> 

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.xcellcomm.Controller"> 
    <center> 
     <VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER"> 
     <children> 
      <Label text="Add New Activation :"> 
       <VBox.margin> 
        <Insets /> 
       </VBox.margin> 
      </Label> 
      <HBox prefHeight="100.0" prefWidth="200.0"> 
       <children> 
        <HBox prefHeight="90.0" prefWidth="200.0"> 
        <children> 
         <VBox prefHeight="200.0" prefWidth="100.0"> 
          <children> 
           <Label text="Select Plan Rate :" /> 
           <RadioButton fx:id="plan40Radio" mnemonicParsing="false" text="40 or less Plan" /> 
           <RadioButton fx:id="plan50Radio" mnemonicParsing="false" text="50 Plan" /> 
           <RadioButton fx:id="plan60Radio" mnemonicParsing="false" text="60 Plan" /> 
           <Region prefHeight="16.0" prefWidth="100.0" /> 
           <Button fx:id="buttonAddActivation" mnemonicParsing="false" onAction="#buttonAddActivationPressed" text="Add Activation" /> 
          </children> 
         </VBox> 
        </children> 
        </HBox> 
        <VBox prefHeight="102.0" prefWidth="163.0"> 
        <children> 
         <Label text="Added Features :" /> 
         <CheckBox fx:id="checkboxFeaturePhp" layoutX="10.0" layoutY="27.0" mnemonicParsing="false" text="PHP" /> 
         <CheckBox fx:id="checkboxBlockIt" mnemonicParsing="false" text="Block it" /> 
         <CheckBox fx:id="checkboxFeatureValueBundle" mnemonicParsing="false" text="Value Bundle" /> 
        </children> 
        </VBox> 
        <VBox prefHeight="200.0" prefWidth="100.0"> 
        <children> 
         <Label text="       " /> 
         <CheckBox fx:id="checkboxFeatureLookout" mnemonicParsing="false" text="Lookout MS" /> 
         <CheckBox fx:id="checkboxFeatureRhpsody" mnemonicParsing="false" text="Rhapsody" /> 
         <CheckBox fx:id="checkboxFeatureWorldCalling" mnemonicParsing="false" text="World Calling" /> 
        </children> 
        </VBox> 
       </children> 
      </HBox> 
      <Region prefHeight="23.0" prefWidth="600.0" /> 
      <HBox prefHeight="131.0" prefWidth="580.0"> 
       <children> 
        <TableView prefHeight="100.0" prefWidth="263.0"> 
        <columns> 
         <TableColumn prefWidth="109.0" text="Time" /> 
         <TableColumn prefWidth="82.0" text="Plan" /> 
        </columns> 
        <HBox.margin> 
         <Insets left="10.0" /> 
        </HBox.margin> 
        </TableView> 
        <Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" /> 
        <TableView prefHeight="100.0" prefWidth="309.0"> 
        <columns> 
         <TableColumn prefWidth="147.0" text="Date" /> 
         <TableColumn prefWidth="90.0" text="MRC" /> 
        </columns> 
        <HBox.margin> 
         <Insets right="10.0" /> 
        </HBox.margin> 
        </TableView> 
       </children> 
      </HBox> 
      <Region prefHeight="29.0" prefWidth="580.0" /> 
      <HBox prefHeight="100.0" prefWidth="200.0"> 
       <children> 
        <VBox prefHeight="150.0" prefWidth="218.0"> 
        <children> 
         <Label text="Today Activations" /> 
         <TextField fx:id="textfeildTodayActivations" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Activations"> 
          <font> 
           <Font size="18.0" /> 
          </font> 
         </TextField> 
         <Label text="Today Goal" /> 
         <TextField fx:id="textfeildTodayGoal" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Goal"> 
          <font> 
           <Font size="18.0" /> 
          </font> 
         </TextField> 
         <Label text="Current Process" /> 
         <ProgressBar prefWidth="200.0" progress="0.0" /> 
        </children> 
        </VBox> 
        <Region prefHeight="150.0" prefWidth="80.0" HBox.hgrow="ALWAYS" /> 
        <LineChart prefHeight="150.0" prefWidth="281.0"> 
        <xAxis> 
         <CategoryAxis side="BOTTOM" /> 
        </xAxis> 
        <yAxis> 
         <NumberAxis side="LEFT" /> 
        </yAxis> 
        </LineChart> 
       </children> 
      </HBox> 
     </children> 
     <BorderPane.margin> 
      <Insets left="10.0" right="10.0" /> 
     </BorderPane.margin> 
     </VBox> 
    </center> 
    <top> 
     <MenuBar BorderPane.alignment="CENTER"> 
     <menus> 
      <Menu mnemonicParsing="false" text="File"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="Close" /> 
      </items> 
      </Menu> 
      <Menu mnemonicParsing="false" text="Edit"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="Delete" /> 
      </items> 
      </Menu> 
      <Menu mnemonicParsing="false" text="Help"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="About" /> 
      </items> 
      </Menu> 
     </menus> 
     </MenuBar> 
    </top> 
</BorderPane> 
+0

Pourriez-vous ajouter un code pour nous? – ItachiUchiha

+0

Quelle est la question réelle? Les lignes qui sont commentées ne donnent pas d'erreurs de compilation lorsque je copie le code (bien que d'autres lignes le soient, car vous avez une dépendance sur une classe que vous n'avez pas fournie). S'il vous plaît expliquer ce que le comportement observé et attendu est, et fournir le code sous la forme d'un [MCVE] –

+0

@James_D je viens d'ajouter tout le code avec le FXML aussi bien –

Répondre

1

Votre tableView dans le fichier FXML ne pas et id, vous avez <TableView prefHeight="100.0" prefWidth="263.0"> et il devrait avoir assigner un id comme vous l'avez dans vos cases à cocher, radiobuttons, e tc.

+0

donc je crée le contrôleur en utilisant le contrôle généré générateur de scène, ne pas attribuer l'ID pour moi comme ceci: @FXML private CheckBox checkboxFeatureRhpsody; sinon comment dois-je ajouter. Je vous remercie! –

+1

@MeauxT dans votre fichier mainMrc.fxml, utilisez: 'au lieu de ' – Kachna

+0

merci c'est le travail et j'ai fait la même chose pour la Colonne le problème que je l'ai en ajoutant deux colonnes à la place de celle que j'ai donc la table a 4 au lieu de 2 colonnes, @ Win.ubuntu –