每当我编译程序时,我都会收到此错误:java.lang.reflect.InvocationTargetException当我将BorderPane的内部节点(HBox)设置为底部时,会发生错误。为什么我会收到此错误,如何解决?
// remove trailing newline
char * newline = NULL;
if( NULL != (newline = strstr( buf, "\n") ) )
{ // then trim newline
*newline = '\0';
}
// data declarations for removing space characters
char *sourceIndex = buf;
char *targetIndex = buf;
// following loop removes space characters, in place
// and stops when the string terminator char encountered
for( ; sourceIndex; sourceIndex++)
{
if( ' ' != *sourceIndex )
{ // then char to have in final output
*targetIndex = *sourceIndex; // copy it
targetIndex++; // step to next position in target
}
}
*targetIndex = '\0'; // terminate the (possibly shorter) string
...
// pass to new process
if( 0 == childpid )
{ // then child process
execv(buf, parmList); // only returns if execv() failed
perror( "execv failed" );
exit( EXIT_FAILURE );
}
完全错误:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.geometry.*;
import java.util.*;
import javafx.scene.text.*;
public class Test extends Application
{
public void start(Stage stage)
{
BorderPane pane = new BorderPane();
HBox hBox = new HBox(10);
boolean player1 = true;
Label label = new Label("Player" + ((player1) ? "1" : "2") + "'s turn");
label.setFont(Font.font(20));
TextField colField = new TextField();
colField.setPrefColumnCount(1);
Button submit = new Button("Submit");
hBox.getChildren().addAll(label, colField, submit);
pane.getChildren().add(hBox);
pane.setBottom(hBox);
Scene scene = new Scene(pane);
stage.setTitle("Connect 4");
stage.setScene(scene);
stage.show();
}
}
答案 0 :(得分:2)
您要将hbox
添加到pane
两次:一次使用pane.getChildren().add(...);
,一次使用pane.setBottom(...);
。这导致hbox
在场景图中出现两次,给出了#34;重复的孩子"错误。您可能只需要pane.setBottom(...);
版本。