小编Cod*_*ver的帖子

在java中将单个字符附加到字符串或char数组中?

是否可以在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)

java string append

47
推荐指数
3
解决办法
39万
查看次数

getOutputMediaFile(int)未定义类型new Camera.PictureCallback(){}错误令我困惑

我无法弄清楚为什么会这样.这可能是一个我无法辨认的愚蠢错误.错误再次出现:

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 eclipse android

6
推荐指数
1
解决办法
1万
查看次数

java中的KeyPressed事件

我刚刚创建了一个java tic-tac-toe游戏我想弄清楚如何在某个条件下按下回车键时运行一个方法,例如下面...

if(/*condition is met*/){
     //keyListener
}
Run Code Online (Sandbox Code Playgroud)

java swing awt keylistener key-bindings

5
推荐指数
2
解决办法
4万
查看次数

关于java中的动作声明的NullPointerExeption

我有一个按钮,我希望它在单击时运行一个方法,这里是该按钮的代码...

             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)

java user-interface swing netbeans nullpointerexception

0
推荐指数
1
解决办法
82
查看次数

Switch Statement Buggy?

可能重复:
不间断切换

我正在制作一个小型计算器应用程序,当单击计算按钮时,会运行一个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 swing switch-statement

0
推荐指数
3
解决办法
194
查看次数