/ / Javaは、文字列を返すことを除いて、すべてのメソッドが文字列に対して機能します-java、string

Javaのすべてのメソッドは、文字列を返すこと以外は文字列に対して機能します - java、string

何らかの理由で、私は文字列のほぼすべてのメソッドを実行できます。これも:

*文字列の長さを取得する

*文字列に追加

*サブストリングを使用

*そしておそらく他のすべて

ただし、myを使用する場合を除き、文字列の値を取得できません。 drawString lwjglで画面に描画するメソッド。問題をさらに説明する前のコードを次に示します。

public static boolean chatOn = false;
public static String text = "";
public static float typetimer = 0;
public static int ctrltimer = 0;
public static boolean runcmd = false;

public static void chat() {
if (Keyboard.isKeyDown(Keyboard.KEY_TAB)) {
if (ctrltimer < 0) {
chatOn = !chatOn;
Keyboard.destroy();
try {Keyboard.create();} catch (LWJGLException e) {}
ctrltimer = 10;
}
}
ctrltimer -= Game.delta;
typetimer -= Game.delta;
if (chatOn) {
//try {text.replace(null, "happy");} catch(NullPointerException e) {}
System.out.println(text);//print to console, dosen"t
Text.drawString(text, 0, 0);//write the text on the screen with my draw method, does work
System.out.println(text);//print to console, dosen"t, yet the one drawstring worked
if (typetimer < 0) {
while (Keyboard.next()) {
try {
if (Keyboard.getEventKey() == Keyboard.KEY_BACK) {
text = text.substring(0, text.length()-1);
typetimer = 1;
System.out.println(text);//print to console, doesn"t
}
else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
System.out.println(text);//print to console, doesn"t
runCommand();
text = "";
chatOn = false;
}
else {
System.out.println(text);//print to console, doesn"t
text = text + Keyboard.getEventCharacter();
}
typetimer = 10;
} catch(Exception e){

}
}
}
}
}

public static void runCommand() {
String command = text;
System.out.println(command);//print to console, doesnt
if (command.startsWith("time")) {
try {
String[] time = new String[1];
time = command.split(" ", 0);
Camera.nighttimeASecond = Integer.parseInt(time[0]);
} catch (Exception e){
System.out.println("could not set time");
}
}
}

コード内のメモを読むと、どこに私が置いているかがわかります print メソッドと drawString 方法。ザ print メソッドは何も出力せず、文字列の最初の数ワードを出力する場合がありますが、 drawString 方法はうまくいきました。ありがとう-タイラー

回答:

回答№1は0

もし System.out.println(text); 前は空です Text.drawString(text, 0, 0); が呼び出され、その後 text 空の場合 Text.drawString() と呼ばれます。あなたがすべき 「マティアスに従う」推奨デバッグガイド そして、あなたの問題が発生している場所を見つけます(またはいくつかを追加します System.out.println()次の text 特に怠けている場合はコードをトレースしてトレースします:p)。 Text クラス、私は "印刷される文字列が設定されていないことを賭けたいと思います Text 静的な文字列を印刷している、または印刷する文字列が Text クラス自体。

審査:

String command = text;
System.out.println(command);//print to console, doesnt

text 設定されることはありません。