是否可以在java中将单个字符附加到数组或字符串的末尾
例如:
private static void /*methodName*/ () {
String character = "a"
String otherString = "helen";
//this is where i need help, i would like to make the otherString become
// helena, is there a way to do this?
}
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚为什么会这样.这可能是一个我无法辨认的愚蠢错误.错误再次出现:
getOutputMediaFile(int) is undefined for the type new Camera.PictureCallback(){}
我的代码:
public static final int MEDIA_TYPE_IMAGE = 1;
private PictureCallback mPicture = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
//Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
// Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
};
Run Code Online (Sandbox Code Playgroud) 我刚刚创建了一个java tic-tac-toe游戏我想弄清楚如何在某个条件下按下回车键时运行一个方法,例如下面...
if(/*condition is met*/){
//keyListener
}
Run Code Online (Sandbox Code Playgroud) 我有一个按钮,我希望它在单击时运行一个方法,这里是该按钮的代码...
playAgainButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
action(e);
}
public void action(ActionEvent e) {
Main.playerTurn = true;
Main.computerWon = false;
Main.playerWon = false;
button1.setText("");
button2.setText("");
button3.setText("");
button4.setText("");
button5.setText("");
button6.setText("");
button7.setText("");
button8.setText("");
button9.setText("");
}
});
Run Code Online (Sandbox Code Playgroud)
但我得到一个NullPointer错误,这也是...
java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at tictactoe.tictactoe.initComponents(tictactoe.java:281)
at tictactoe.tictactoe.<init>(tictactoe.java:13)
at tictactoe.Main.<clinit>(Main.java:30)
Exception in thread "main" Java Result: 1
Run Code Online (Sandbox Code Playgroud) 可能重复:
不间断切换
我正在制作一个小型计算器应用程序,当单击计算按钮时,会运行一个switch语句,但生成的数字不是它应该是的,我测试了我的输入,他们在这里工作的是switch语句:
switch (currentOp)
{
case "+" :
answer = Float.toString(inp1 + inp2);
case "-" :
answer = Float.toString(inp1 - inp2);
case "X" :
answer = Float.toString(inp1 * inp2);
case "/" :
answer = Float.toString(inp1 / inp2);
}
Run Code Online (Sandbox Code Playgroud) java ×5
swing ×3
android ×1
append ×1
awt ×1
eclipse ×1
key-bindings ×1
keylistener ×1
netbeans ×1
string ×1