Can you help me with mouse pressed method please?

hi
can you help me with my problem please, player label doesn't show up in the applet and the draw string method it doesn't draw any strings like X or O for the game I don't know what is the problem maybe it is with MousePressed method which is in Board class. I tried to write the code of the location many times I'm not sure if the problem comes from there.
there is no error in my code, but it doesn't work.
this is class Board which has the mouseListener
class Board extends JPanel  implements MouseListener, MouseMotionListener
    private JLabel playerlabel; 
     private boolean play;
     private boolean start;
    private int turn; 
    private Square squares[][];
  private Player myplayer[][];
     public Board()
          setBackground( Color.WHITE );
          playerlabel = new JLabel( "X player first" );
          //playerlabel.setLayout(null);
     //     playerlabel.setLocation(500,500);
          add( playerlabel );
          play = true;
          turn = 1;
         squares = new Square[3][3];
         myplayer = new Player[3][3];
         int x = 40;
          int y = 40;
          for (int i=0; i<3; i++){
               x = 40;
               for (int j=0; j<3; j++){
                    Square s = new Square( x,y );
                    squares[i][j] = s;
                    x +=50;
               y +=50;
            this.addMouseListener(this);
        this.addMouseMotionListener(this);
      public void mouseClicked( MouseEvent event ){}
      public void mouseMoved( MouseEvent event ){}
      public void mouseEntered( MouseEvent event ){}
      public void mouseExited( MouseEvent event ){}
      public void mousePressed( MouseEvent event )
      {int xPos = event.getX();
              int yPos = event.getY();
                if(play && turn ==1){
                for (int i=0; i<3; i++){
                    for (int j=0; j<3; j++){
                         int x = squares[i][j].getX();
                         int y = squares[i][j].getY();
                         if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
                              if( squares[i][j].getOccupied() ==0 ){
                                   String ptext;
                                   ptext = "X";
                                   Player p = new Player(x, y,ptext);
                                   myplayer[i][j] = p;
                                   squares[i][j].setOccupied(1);
                                   playerlabel.setText( "O Player Turn" );
                                   turn = 2;
                                   repaint();
                                   Win();
                              else{
                                   turn = 2;
                                   playerlabel.setText( "O Player Turn" );
                                   repaint();
          if ( play && turn ==2 )
for (int i=0; i<3; i++){
                    for (int j=0; j<3; j++){
                         int x = squares[i][j].getX();
                         int y = squares[i][j].getY();
                         if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
                              if( squares[i][j].getOccupied() ==0 ){
                                   String ptext;
                                   ptext = "O";
                                   Player p = new Player(x, y,ptext);
                                   myplayer[i][j] = p;
                                   squares[i][j].setOccupied(2);
                                   playerlabel.setText( "X Player Turn" );
                                   turn = 1;
                                   repaint();
                                   Win();
                              else{
                                   turn = 1;
                                   playerlabel.setText( "X Player Turn" );
                                   repaint();
      public void mouseReleased( MouseEvent event )
      public void mouseDragged( MouseEvent event )
     public void Win(){
          if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else      if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
               if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else      if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          //Vertically win
           if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else      if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
           if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else      if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          //Diagonal win
                if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
           if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
     }//end win
public void setTurn(int t)
          turn = t;
          playerlabel.setText( "X Player Plays First" );
     public void paintComponent( Graphics g )
           super.paintComponent( g );
           this.setBackground( Color.WHITE );
          for (int i=0; i<3; i++){
               for (int j=0; j<3; j++){
                    g.setColor( Color.BLACK );
                     g.drawRect( squares[i][j].getX(), squares[i][j].getY(), 50, 50 );     
           for (int i=0; i<3; i++){
               for (int j=0; j<3; j++){
                     myplayer[i][j].draw(g);     
        //End of paintComponent   
}and this is the whole code of my program.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class Player{
     private int xCoordinate;
     private int yCoordinate;
    private String playerText;
  public   Player(int x, int y, String t)
        playerText = t;
        xCoordinate = x;
        yCoordinate = y;
    public void draw(Graphics g)
           g.drawString(playerText,  xCoordinate, yCoordinate);
     public void SetText(String t)
     { playerText = t;
}//end player
class Square
     private int x;
     private int y;
     private int occupied;
     public Square(int x1, int y1)
          x = x1;
          y= y1;
          occupied = 0;
     public void setX(int x1)
          x = x1;
     public int getX()
          return x;
     public void setY(int y1)
          y = y1;
     public int getY()
          return y;
     public void setOccupied(int o)
          occupied = o;
     public int getOccupied()
          return occupied;
public class TicTac extends JApplet implements ActionListener
{ private JPanel panel;
     private JButton newgame;
     private Board B;
     public void init()
          B = new Board();
          add( B, BorderLayout.CENTER );
          panel = new JPanel();
           newgame = new JButton( "New Game" );
           panel.add( newgame);
           add( panel, BorderLayout.SOUTH );
           newgame.addActionListener(this);
          public void actionPerformed( ActionEvent ev)
           {     Object source = ev.getSource();
     if (source == newgame)
                {remove(B);
               repaint();
          B = new Board();
               add( B, BorderLayout.CENTER );
     B.setTurn(1);
               repaint();
               validate();
        }//end class TicTac
class Board extends JPanel  implements MouseListener, MouseMotionListener
    private JLabel playerlabel; 
     private boolean play;
     private boolean start;
    private int turn; 
    private Square squares[][];
  private Player myplayer[][];
     public Board()
          setBackground( Color.WHITE );
          playerlabel = new JLabel( "X player first" );
          //playerlabel.setLayout(null);
     //     playerlabel.setLocation(500,500);
          add( playerlabel );
          play = true;
          turn = 1;
         squares = new Square[3][3];
         myplayer = new Player[3][3];
         int x = 40;
          int y = 40;
          for (int i=0; i<3; i++){
               x = 40;
               for (int j=0; j<3; j++){
                    Square s = new Square( x,y );
                    squares[i][j] = s;
                    x +=50;
               y +=50;
            this.addMouseListener(this);
        this.addMouseMotionListener(this);
      public void mouseClicked( MouseEvent event ){}
      public void mouseMoved( MouseEvent event ){}
      public void mouseEntered( MouseEvent event ){}
      public void mouseExited( MouseEvent event ){}
      public void mousePressed( MouseEvent event )
      {int xPos = event.getX();
              int yPos = event.getY();
                if(play && turn ==1){
                for (int i=0; i<3; i++){
                    for (int j=0; j<3; j++){
                         int x = squares[i][j].getX();
                         int y = squares[i][j].getY();
                         if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
                              if( squares[i][j].getOccupied() ==0 ){
                                   String ptext;
                                   ptext = "X";
                                   Player p = new Player(x, y,ptext);
                                   myplayer[i][j] = p;
                                   squares[i][j].setOccupied(1);
                                   playerlabel.setText( "O Player Turn" );
                                   turn = 2;
                                   repaint();
                                   Win();
                              else{
                                   turn = 2;
                                   playerlabel.setText( "O Player Turn" );
                                   repaint();
          if ( play && turn ==2 )
for (int i=0; i<3; i++){
                    for (int j=0; j<3; j++){
                         int x = squares[i][j].getX();
                         int y = squares[i][j].getY();
                         if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
                              if( squares[i][j].getOccupied() ==0 ){
                                   String ptext;
                                   ptext = "O";
                                   Player p = new Player(x, y,ptext);
                                   myplayer[i][j] = p;
                                   squares[i][j].setOccupied(2);
                                   playerlabel.setText( "X Player Turn" );
                                   turn = 1;
                                   repaint();
                                   Win();
                              else{
                                   turn = 1;
                                   playerlabel.setText( "X Player Turn" );
                                   repaint();
      public void mouseReleased( MouseEvent event )
      public void mouseDragged( MouseEvent event )
     public void Win(){
          if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else      if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
               if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else      if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          //Vertically win
           if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else      if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
           if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else      if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          //Diagonal win
                if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
          else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
          {playerlabel.setText("Player 1 X WON THE GAME!");
          play =false;          }
           if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
          else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
          {playerlabel.setText("Player 2 O WON THE GAME!");
          play =false;          }
     }//end win
public void setTurn(int t)
          turn = t;
          playerlabel.setText( "X Player Plays First" );
     public void paintComponent( Graphics g )
           super.paintComponent( g );
           this.setBackground( Color.WHITE );
          for (int i=0; i<3; i++){
               for (int j=0; j<3; j++){
                    g.setColor( Color.BLACK );
                     g.drawRect( squares[i][j].getX(), squares[i][j].getY(), 50, 50 );     
           for (int i=0; i<3; i++){
               for (int j=0; j<3; j++){
                     myplayer[i][j].draw(g);     
        //End of paintComponent   
        Edited by: mshadows on May 18, 2008 7:53 AM

I was playing with this a little bit and came up with this game model, something that I'm sure can be improved upon greatly:
TttXO.java
an enum to encapsulate X vs O. I could use a boolean here since it has 2 states, but this seems more intuitive to me
package dy08.m05.ttt;
* tic tac toe encapsulation of X vs O
* @author Pete
public enum TttXO
    X, O
}TttCell.java
encapsulates an individual cell in the tictactoe grid.
package dy08.m05.ttt;
* Tic Tac Toe Game cell
* can be occupied or not
* can hold TttXO X or O or null 
* @author Pete
public class TttCell
    private boolean occupied = false;
    private TttXO xo = null;
    public TttCell()
     * sets a Square for either x or o
     * @param TttXO
     * @return true if successful, false if already occupied
    public boolean setXO(TttXO xo)
        if (occupied)
            return false;
        else
            occupied = true;
            this.xo = xo;
            return true;
    public void reset()
        occupied = false;
        xo = null;
    public boolean isOccupied()
        return occupied;
    public TttXO getXO()
        return xo;
    // used to test and debug the class
    public String toString()
        if (occupied)
            return xo.toString();
        else
            return "-";
package dy08.m05.ttt;
* Tic Tac Toe game model
* @author Pete
public class TttGameModel
    private TttCell[][] cellGrid = new TttCell[3][3];
    private boolean xTurn = true;
    private boolean win = false;
    public TttGameModel()
        for (int i = 0; i < cellGrid.length; i++)
            for (int j = 0; j < cellGrid.length; j++)
cellGrid[i][j] = new TttCell();
public void reset()
xTurn = true;
win = false;
for (int i = 0; i < cellGrid.length; i++)
for (int j = 0; j < cellGrid[i].length; j++)
cellGrid[i][j].reset();
public boolean isXTurn()
return xTurn;
public boolean isWin()
return win;
* @param row
* @param col
* @return true if valid move, false if game already over or cell occupied
public boolean takeTurn(int col, int row)
TttXO currentXO = TttXO.O;
TttCell cell = cellGrid[row][col];
if (win)
return false;
if (cell.isOccupied())
return false;
if (xTurn)
currentXO = TttXO.X;
cell.setXO(currentXO);
win = checkWin(col, row, currentXO);
xTurn = !xTurn; // toggle xturn
return true;
public boolean checkWin(int col, int row, TttXO xo)
boolean win = false;
// first rows and columns
boolean temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[row][i].getXO() == xo;
win |= temp;
temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[i][col].getXO() == xo;
win |= temp;
if (row == col) // if slash diagonal
temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[i][i].getXO() == xo;
win |= temp;
if (row + col == 2) // if backslash diagonal
temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[i][2 - i].getXO() == xo;
win |= temp;
return win;
// used to test and debug the class
public String toString()
StringBuilder sb = new StringBuilder();
for (int i = 0; i < cellGrid.length; i++)
for (int j = 0; j < cellGrid[i].length; j++)
sb.append(cellGrid[i][j] + " ");
sb.append("\n");
if (win)
sb.append("win! Game over");
else
sb.append("No winner yet");
return sb.toString();
// test the class
public static void main(String[] args)
TttGameModel model = new TttGameModel();
checkMove(model, 0, 0);
checkMove(model, 1, 0);
checkMove(model, 1, 1);
checkMove(model, 2, 0);
checkMove(model, 1, 0); // bad move
checkMove(model, 2, 2);
// to test the class
private static void checkMove(TttGameModel model, int i, int j)
System.out.println("OK move: " + model.takeTurn(i, j));
System.out.println(model + "\n");

Similar Messages

  • Can you help me with an jsp execption please?

    Hello!
    Could you please try to help me with this code
    that brings me an exception?
    this is the jsp page :
    <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
    <%@ page import="java.io.FileWriter,java.io.IOException" %>
    <%
        String savePath = "", filepath = "", filename = "";
        String contentType = "", fileData = "", strLocalFileName = "";
        int startPos = 0;
        int endPos = 0;
    %>
    <%!
        temp data buffer
        void copyByte(byte [] fromBytes, byte [] toBytes, int start, int len){
           for(int i=start;i<(start+len);i++)
              toBytes[i - start] = fromBytes;
    %>
    <%
    int BOF = 0, EOF = 0;
    contentType = request.getContentType();
    out.println("<br>Content type is :: " +contentType);
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
         DataInputStream in = new DataInputStream(request.getInputStream());
         DataInputStream in1 = in;
         int formDataLength = request.getContentLength();
         byte dataBytes[] = new byte[formDataLength];
         int byteRead = 0;
         int totalBytesRead = 0;
         while (totalBytesRead < formDataLength){     
              byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);
              totalBytesRead += byteRead;
         out.println("<br>totalBytesRead : " + totalBytesRead + " : formDataLength = " + formDataLength);
         byte[] line = new byte[128];
         if (totalBytesRead < 3){
         return;     //exit if file length is not sufficiently large
         String boundary = "";
         String s = "";
         int count = 0;          
         int pos = 0;
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf("Content-Disposition: form-data; name=\""); //set the file name
         if(pos != -1)
         endPos = pos;
         }while(pos == -1);
         boundary = fileData.substring(startPos, endPos);
         startPos = endPos;
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf("filename=\"", startPos); //set the file name
         if(pos != -1)
    startPos = pos;
         }while(pos == -1);                         
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf("Content-Type: ", startPos);
         if(pos != -1)
              endPos = pos;                              
         }while(pos == -1);
         filename = fileData.substring(startPos + 10, endPos - 3);     //to eliminate " from start & end
         strLocalFileName = filename;
         int index = filename.lastIndexOf("\\");
         if(index != -1)
         filename = filename.substring(index + 1);
         else
         filename = filename;
         boolean blnNewlnFlag = false;
         startPos = endPos;     //added length of "Content-Type: "
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;               
         pos = fileData.indexOf("\n", startPos);
         if(pos != -1){
              if(blnNewlnFlag == true)
                   endPos = pos;                         
              else{
              blnNewlnFlag = true;
              pos = -1;
         }while(pos == -1);
    contentType = fileData.substring(startPos + 14, endPos);
         startPos = count + 1;
         do{
         copyByte(dataBytes, line, count ,1);     //read 1 byte at a time
         count+=1;
         s = new String(line, 0, 1);
         fileData = fileData + s;
         pos = fileData.indexOf(boundary, startPos);     //check for end of file data i.e boundry value               
         }while(pos == -1);
         endPos = count - boundary.length();
         out.println("<br><br>0. Local File Name = " + strLocalFileName);
         out.println("<br><br>1. filename = " + filename);
         out.println("<br>2. contentType = " + contentType);
         out.println("<br>3. startPos = " + startPos);
         out.println("<br>4. endPos = " + endPos);
         out.println("<br>5. boundary = " + boundary);
         String appPath = application.getRealPath("/");
         out.println("<br>appPath : " + appPath);
         String destFolder = appPath + "images/";
    String name = request.getParameter("signinName").trim();
    String email = request.getParameter("signinEmail").trim();
    String age = request.getParameter("signinAge").trim();
    String passwd = request.getParameter("signinPassword").trim();
    String profile = request.getParameter("signinProfile").trim();
    String type = filename.substring(filename.lastIndexOf("."));
         filename = destFolder + name + type;
         fileOutputStream fileOut = new FileOutputStream(filename);
         fileOut.write(dataBytes, startPos, (endPos - startPos));
         fileOut.flush();
         fileOut.close();
         out.println("<br>File saved as >> " + filename);
         else {
              out.println("Error in uploading ");
    %>
    this is the exception:
    exception
    org.apache.jasper.JasperException: java.lang.NullPointerException
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:382)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    root cause
    java.lang.NullPointerException
         org.apache.jsp.uploadFile_jsp._jspService(uploadFile_jsp.java:190)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)Thanks a lot !!

    root cause
    java.lang.NullPointerException
         org.apache.jsp.uploadFile_jsp._jspService(uploadFile_jsp.java:190)Some variable is getting null value ..so debug it.
    Best way is to start putting System.out's ....
    System.out.println("Step ############1");
    Put the incremental numbering between several code blocks. Check the log output. You will surely be able to find out till what point ur code is Ok.
    -Rohit

  • Can you help me with this problem? Please!

    I had just created this program that calculates the amount due from an international phone call. and I was wondering what I can do to get the program to execute when the user inputs let's say 3min and some amount of seconds. The program works when the number of minutes the call lasted is an integer, but it does not when the number of minutes the call lasted is lets say 4min30sec. Is there anyway I can get my program to execute both minutes and seconds? Help is very appreciated.
    Here's the program:
    import java.io.*;
    import java.text.DecimalFormat;
    public class PhoneCallBilling_Lab4
         static BufferedReader keyboard = new
         BufferedReader(new InputStreamReader(System.in));
         //Named constants
    static final double CONNECTION_FEE = 1.99;
    static final double FIRST_THREE_MIN_FEE = 2.00;
    static final double COST_OF_EACH_ADDITIONAL_MIN = 0.45;
         public static void main(String[] args) throws IOException
         //Variable declaration
    int noOfMinCallLasted;
    double amountDue;
    DecimalFormat twoDigits =
    new DecimalFormat("0.00");
    System.out.println("This program computes an international phone call.");
    System.out.print("Enter the number of minutes the call lasted: ");
    noOfMinCallLasted =
    Integer.parseInt(keyboard.readLine());
    System.out.println();
    if (noOfMinCallLasted<= 3)
         amountDue = CONNECTION_FEE +
         FIRST_THREE_MIN_FEE;
    else
    amountDue = CONNECTION_FEE +
    FIRST_THREE_MIN_FEE +
    (noOfMinCallLasted - 3) * COST_OF_EACH_ADDITIONAL_MIN;
    System.out.println("The number of minutes the call lasted was "
              + noOfMinCallLasted);
    System.out.println("Amount due = $"
    + twoDigits.format(amountDue));
    }

    How about converting the minutes to seconds and doing
    your calulations all in seconds?ok. I am going to try that but don't you think that it would be quite cumbersome if I was to have someone actually input information. They would have to go through the entire process of trying to figure out how many minutes is in a second and all of the other problems that may occur. If I didnt have to consider all possibilities when executing this program I could leave it as is. However, I have to. And the problem states that we (as in students) have to get the user to input the number of minutes and seconds and the program has to execute.

  • HT1329 hi i need help with my ipod nano i want to get my music from my ipod to i tunes so that i can be able to transfer the music on my i tunes to my ipad mini can you help me with that ?

    hi i need help with my ipod nano i want to transfer my music from the ipod to the itunes so that i can be able to transfer the music to my ipad can you help me with that ?

    You cannot use iTunes to transfer song files from iPod to computer, except for songs purchased from the iTunes Store.  However, there are third-party methods and utilities that can transfer from iPod to computer.  If you do an Internet search on something like"iPod transfer," you should get some links.  (The CNET article seems to be popular.)
    Once the song files are on your computer's drive, you can add them to your iTunes library, and then sync your iPad.

  • Hello, we have both Creative Cloud and Creative Cloud for teams. Can you help me with the difference and if i need to have both?

    Hello, we have both Creative Cloud membership and Creative Cloud for team. Can you help me with the difference and if i need to have both? We have 9 employees that are using it. Just not sure if i'm paying for something i don't need.
    Thank you

    Please refer to Creative Cloud Help | Creative Cloud / Common Questions
    CC is for retail use with 20 GB of storage space, CCT is where number of seats are purchased & assigned by one program admin where each seat gets 100GB of storage space.
    You can not have both the CC & team in one account as it will only provide you added storage space of 120 GB but you can activate the CC any of them or either of them twice as CC is based on Adobe ID.
    Regards
    Rajshree

  • HT204146 Good morning.  I just purchased Imatch but cannot download my music from an iphone 5 to IMatch in Icloud.  Can you help me with this?

    Good morning.  I just purchased Imatch but cannot download my music from an iphone 5 to IMatch in Icloud.  Can you help me with this?

    Hi
    Has iTunes completed its scan of your iTunes library on your computer Subscribing to iTunes from an iOS device.
    Jim

  • I am using Dreamweaver CS4  and can no longer connect to Device Central - Can you help me with this?

    I am using Dreamweaver CS4  and can no longer connect to Device Central - Can you help me with this?

    Device Central was discontinued April 23, 2012.
    http://www.adobe.com/products/devicecentral.html
    And replaced with Adobe Edge Inspect CC (for Cloud subscribers)
    http://html.adobe.com/edge/inspect/
    Nancy O.

  • Hi, recently i bought macbook pro with retina display and installed windows 8 professional original software also. but in windows 8 track pad is not working properly. can you help me with providing drivers for trackpad to work on windows 8 professional .

    hi, recently i bought macbook pro with retina display and installed windows 8 professional original software also. but in windows 8 track pad/ TOUCHPAD is not working properly. can you help me with providing drivers for trackpad to work on windows 8 professional .

    Did you download and install the Windows Support software? If you did, did you use the Boot Camp Control icon to set up the trackpad how you want it?
    http://www.apple.com/support/bootcamp/
    https://discussions.apple.com/community/windows_software/boot_camp

  • I run Windows 7 Home Premium on an HP Pavilion dv6. I cannot install iTunes or QuickTime. Can you help me with this?

    I run Windows 7 Home Premium on an HP Pavilion dv6. I cannot install iTunes or QuickTime. Can you help me with this?

    Hello raadabdaun,
    Thanks for the question, and welcome to Apple Support Communities.
    I understand you are having issues installing iTunes for Windows. The following article provides the most relevant information and troubleshooting steps:
    Trouble installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/HT1926
    Thanks,
    Matt M.

  • What will i do..there is a message show, "your device in not more eligible to create a free i cloud acount"..and when i try a new one it ask an account number, but i dont have...can you help me with this issue..

    What will i do..there is a message show, "your device in not more eligible to create a free i cloud acount"..and when i try a new one it ask an account number, but i dont have...can you help me with this issue..?
    I try also my old icloud user but its not recognizing the accoun...

    What will i do..there is a message show, "your device in not more eligible to create a free i cloud acount"..and when i try a new one it ask an account number, but i dont have...can you help me with this issue..?
    I try also my old icloud user but its not recognizing the accoun...

  • HT2801 I understand there is a way to use my Super Drive with my PC.  However, it requires a System OS Disk.  Which I never received.  Can you help me with this?

    I understand there is a way to use my Super Drive with my PC.  However, it requires a System OS Disk.  Which I never received.  Can you help me with this?

    Rick6812 wrote:
      I'm using Windows 8.1. 
    I do not know what you mean by a Windows 8.1.  Please clarify.
    The Apple superdrive is designed to be used with the following Macs.
    It will not work with any other Mac unless you perform this modification;
    http://www.tuaw.com/2012/04/02/use-the-macbook-air-superdrive-with-any-almost-ma c/
    Are you trying to get it to work with a PC? 
    Ciao.

  • I recently updated to ios 6.1.1 and since then, the photos i am uploading via ios does not show on my timeline or on the newsfeed, but the pictures show in the album. can you help me with it? thanks.

    i recently updated to ios 6.1.1 and since then, the photos i am uploading via ios does not show on my timeline or on the newsfeed, but the pictures show in the album. can you help me with it? thanks.

    fingers crossed, it appears they are working the bugs out of this update....i was able to post a pic to my newsfeeds/time line this morning....first the picture went into the ios album but within a minute, it appeared on my timeline! im glad ...

  • How to Setup Forward Error Handling in PI Scenarios. Can you help me with the same with screen shots if possible?

    Dear all
    How to Setup Forward Error Handling in PI Scenarios. Can you help me with the same with screen shots if possible?
    Thanks
    Regards
    karan

    Hello
    These are the following errors
    1. Trace level="1" type="T">no interface action for sender or receiver found</Trace>
    2. <Trace level="1" type="System_Error">Application-Error exception return from pipeline processing!
    3.
    <Trace level="1" type="T">Application Error at Receiver... => ROLLBACK WORK</Trace>  
    <Trace level="1" type="T">System Error at Receiver... => ROLLBACK WORK</Trace>  
    <Trace level="1" type="B" name="CL_XMS_MAIN-WRITE_MESSAGE_LOG_TO_PERSIST" />  
    <Trace level="1" type="System_Error">Application-Error exception return from pipeline processing!</
    Trace level="3" type="T">No persisting of message after plsrv call, because of config</Trace>Trace level="3" type="T">Error of the prevous version:</TraceTrace level="3" type="T">Error ID APPLICATION_ERROR</Trace>
    tThere are repeating errors also.
    TThanks
    Regards
    kkaran

  • I play Zuma Blitz on FB; Ever since I upgraded to Firefox 4 I can't play the game the darn frog pauses before shooting and it's a mess; you know it's what I enjoy doing and it needs to be fixed can you help me with this??? Thanks

    Question
    I play Zuma Blitz on FB; Ever since I upgraded to Firefox 4 I can't play the game the darn frog pauses before shooting and it's a mess; you know it's what I enjoy doing and it needs to be fixed can you help me with this??? I am super frustrated ith the situationThanks

    Upgrading to firefox 5 and updating my plug-ins helped a bit. Frog is less 'sticky' now, but it's not solved the problem. Java needs to be up to speed or the frog goes into stasis....

  • We live in motel but my iMac is not connecting with the internet but my cousin has hp laptop that works perfectly fine in my room. So can you help me with this situation?

    We live in motel but my iMac is not connecting with the internet but my cousin has hp laptop that works perfectly fine in my room. So can you help me with this situation?

    Joining an encrypted WEP or WPA Wi-Fi network

Maybe you are looking for

  • How do I delete duplicate songs from my iPhone 5s?

    Almost all of my itunes music shows up twice on my iPhone, but not in my iTunes library. I've tried to delete one of the duplicates from my actual iPhone, but that doesn't work. How do I fix this?

  • IPod not showing up at all on Mac but works fine on Windows?

    I've been searching for an answer on these discussion boards for hours and have not yet found any situation that was quite like mine and I'm getting a bit frazzled and worried. I have a 120GB iPod classic, which I've used for two years with an ACER l

  • Cursor name visable property on xy graph: name overlays cursor point.

    I have an XY grpah set up, and I realized that when i apply the name visable attribute to the cursors programmiably, the name seems to overlay teh cursor, being right on top of it. Yet if i do it manualy through the cursor legend, it shows it on top.

  • SUBMIT BUTTON PROBLEMS

    How can I get the SUBMIT button to function as I want it to using Acrobat X?  I want to use a SUBMIT button to return the completed form  to a different email address than my own.  I entered a button on the form,  I entered the email address correctl

  • Fan going into full blast for no reason

    the fan in my macbook has been going to 6000 rpm for no reason. like when im not doing anything, suddenly i hear the fans start spinning. usually, at 2500(min speed for my mb) rpm, it is barely audible. then suddenly i hear this low hum, and i look a