Null Pointer... ? I can't spot it.
just to preface this, st[r].getRow()returns an int[] which I'm sure is populated as it works elsewhere
in my code. I think it might have something to do with casting to a byte because that's the line that it says
the null pointer exception is on. Is there an easy way to represent an integer with 4 bytes maybe?
byte[] ba = null;
int bc = 0;
for(int r = 0; r < 10; r++){
int[] tmp = st[r].getRow();
for(int c = 0;c < 6; c++){
ba[bc] = (byte) tmp[c];
bc++;
System.out.println(ba[bc]);
System.out.println(ba);
You're welcome.
then why does my IDE suggest that I initialize it to null?At compile time you can't use the variable (except to assign to) unless it has been initialised to something - however, as you've seen, initialising it to null will cause a runtime error if you try and dereference it.
Similar Messages
-
Exception in thread "main" Null Pointer exception.
Hi
I am Having a problem creating objects and storing them in an arraylist. I have no problem doing this with regular arrays, but whenever I try to use an arraylist I get the error:
Thiis is part of my code . any help is appreciated.
import java.util.*;
public class MonthlySchedule
private ArrayList <Request> monthlyschedule;
Request req = new Request(null, null, null, 0, 0);
* Constructor which initialises the arraylist
public MonthlySchedule()
ArrayList<Request> monthlyschedule= new ArrayList<Request>() ;
/*Adds a name to the arraylist
* @param request- the name to be added to the arraylist
public boolean add(Request request)
int time1=GregorianCalendar.HOUR;
for(Request request1:monthlyschedule)
int time2=GregorianCalendar.HOUR;
if(time1 !=time2)
monthlyschedule.add(request1);
return true;
else
return false;
return true;
* The method to cancel a name
* @param name--the name to be removed from the array list
public boolean cancel (String name)
for(int i=0;i<monthlyschedule.size();i++)
String element =req.getName();
if((name)==element)
monthlyschedule.remove(name);
return true;
else
return false;
return false;// just to compile
in the main method(which is not included yet, i'll add it if u request) when i try to add or cancel any request am getting a null pointer exception. can u please help me out. Thanks in advanceYou define a local ArrayList here:public MonthlySchedule()
ArrayList<Request> monthlyschedule= new ArrayList<Request>() ;
}Just instanciate the instance variable. -
Null Pointer Exception Error's in WebDynpro Java
Hi All,
How Types are coming Null Pointer Exception Error's in WebDynpro Java, Please provide the types.of Errors.
Ex. Cardinality Type not correct etc...
Thanks,
Bye,
Vijay Hari.HI
Null Pointer Exception can occur in may instances , for suppose
1) when you create a Value Node with some attribute which has cardinality , and you have not
initialized the Node , then it would through Null Pointer exception ,
2) when you integrate the RFC and parameters you pass as input to the RFC are not set correctly
then there could be null pointer when you execute the RFC
3>or may be when you doesnot bind the node when using webservice then there could be null pointer exception
and there could be many occurances for the exception -
Why do i get a null pointer exception
import javax.swing.*;
class Rental
public static void main (String [] args)
int custCounter = 0; // counts the customers created so far
Customer[] customers = new Customer[100]; // creates an array of 100 customers
DomesticAssistant[] assistants = new DomesticAssistant[3]; // creates an array of [3] domestic assistants
assistants[0] = new DomesticAssistant("Lazy", 20, 100, 90, 300); // creates the domestic assistant and stores it in the array at position [0]
assistants[0].setReservedFrom(0, 0, 0); // sets the reserved from date to zero
assistants[0].setReservedTo(0, 0, 0); // sets the reserved to date to zero
assistants[1] = new DomesticAssistant("Average", 30, 150, 135, 400); // creates the domestic assistant and stores it in the array at position [1]
assistants[1].setReservedFrom(0, 0, 0); // sets the reserved from date to zero
assistants[1].setReservedTo(0, 0, 0); // sets the reserved to date to zero
assistants[2] = new DomesticAssistant("Excellent", 50, 250, 220, 750); // creates the domestic assistant and stores it in the array at position [2]
assistants[2].setReservedFrom(0, 0, 0); // sets the reserved from date to zero
assistants[2].setReservedTo(0, 0, 0); // sets the reserved to date to zero
String firstChoice = JOptionPane.showInputDialog("MAIN MENU\n--------------------\n\nPlease enter a number based on the following: \n[1] Add New Customer\n[2] Login\n[3] Exit"); // the main menu
if(firstChoice.equals("1")) // if the user enteres "1" in the main menu (add a new customer)
String custName = JOptionPane.showInputDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nName: "); // asks for name and stores in variable custName
String custAddress = JOptionPane.showInputDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nAddress: "); // asks for sddress and stores in variable custAddress
String custPostCode = JOptionPane.showInputDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nPost Code: "); // asks for post code and stores in variable custPostCode
String custPhoneNo = JOptionPane.showInputDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nTelephone Number: "); // asks for phone number and stores in variable custPhoneNo
String custEmail = JOptionPane.showInputDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nEmail: "); // asks for email and stores in variable custEmail
String startingBalance = JOptionPane.showInputDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nStarting Credit: "); // asks for credit to start account with and stores in variable startingBalance
int sBalance = Integer.parseInt(startingBalance); // converts startingBalance from a string into an integer
customers[custCounter] = new Customer(custName, custAddress, custPostCode, custPhoneNo, custEmail, sBalance); // creates a customer with the variables/details entered above
JOptionPane.showMessageDialog(null, "NEW CUSTOMER MENU\n--------------------\n\nWelcome" + custName + ".\nYour details were sucessfully added to the system.\nYour ID number is: " + customers[custCounter].getIdNumber() + "\nYour password is: " + customers[custCounter].getPassword()); // greets the new customer as well as giving them their id number and password
custCounter++; // increments the customer sounter by 1
else if(firstChoice.equals("2")) // if the user enters "2" in the main menu (login)
String checkIdNo = JOptionPane.showInputDialog(null, "LOGIN\n--------------------\n\nPlease enter your ID Number: ");
int checkIdNum = Integer.parseInt(checkIdNo);// asks user to enter their id number
int position = 0; //variable to store where we are in the array of customers so we know which customer we are dealing with
for(int i = 0; i < customers.length; i++) // loops through the array of customers
-----> if(customers.getIdNumber() == checkIdNum) // when the id number entered is found
position = i; // set the position variable to that customer (the position in the customers array)
else // if the id number is not found
JOptionPane.showMessageDialog(null, "LOGIN\n--------------------\n\nThat ID Number does not exist. "); // tell the user that the id number wasnt found
System.exit(0); // then exit the system
[\code]
Can anyone help. when i run the program i get a null pointer exception
can you tell me why, and possibly tell me how i can search through the array of customers searching for an id number
am i doing it a way that will work (not the best way) but just so it works
thanks in advance
D_HNevertheless, when you get to the loop where your exception occurs, you may have created any number of customers, but probably not 100.
The loop tries to go through all 100 spaces in the array, and as soon as it gets to a space you haven't assigned a Customer too, you'll get the exception.
Either make sure the loop doesn't go higher than you cutomercounter - 1 (to compensate for 0-based index of array), or check if the customer[i] == null before you try to call a method on it.
Does that make sense?
/D -
Help in null pointer exception
I have a null pointer exception and i cant figure out which variable is null,
This is my servlet code.
ArrayList pmArray = pDAO.getPlacemarkByRegion(northEastLong, northEastLat, southWestLat, southWestLat);
//loop through the placemark
for ( int i=0; i< pmArray.size();i++) {
Placemark pm = (Placemark)pmArray.get(i);
// parse string
String pmId = pm.getPlacemarkid()+"";
String pmLat = pm.getLatitude()+"";
String pmLong = pm.getLongtitude()+"";
String s = "{\"markers\":[ " +
"{\"placemarkid\" : + pmId , \"latitude\" : + pLat , \"longtitude\": + pmLong} + ]}";
System.out.println(s);This is my DAO class
public ArrayList getPlacemarkByRegion(double northEastLong, double northEastLat, double southWestLong, double southWestLat)When i get the placemark andNullPointerException appear. I think that my Arraylist is incorrect, I have also try-catch exception in the servlet but it still show me null pointer. Can anyone please kindly guide me?
Message was edited by:
peebuhmm, i have solved my sql syntext already, but i still manage to get pmArray null.
I have check through my codes but pmArray is still null.
try{
pDAO = new PlacemarkDAO();
ArrayList pmArray = pDAO.getPlacemarkByRegion(northEastLong,northEastLat,southWestLong, southWestLat);
if(pmArray!=null && pmArray.size()>0){ //Check if the method pDao.getPlacemarkByRegion return a null to pmArray
for ( int i=0; i< pmArray.size();i++) {
Placemark pm = (Placemark)pmArray.get(i);
if(pm!=null){ //check if the instance pm is null
String pmId = pm.getPlacemarkid()+"";
String pmLat = pm.getLatitude()+"";
String pmLong = pm.getLongtitude()+"";
out.println("{\"markers\" : [ {\"placemarkid\":, \"latitude\" :, \"longtitude\" :}," +
"{\"placemarkid\" :, \"latitude\":, \"longtitude\" :}," +
"{\"placemarkid\" :, \"latitude\" :, \"longtitude\" :}" +
}else{
System.out.println("Error in: "+i + " element"); //if pm instance is null then return the element position of the pmArray
}else{
System.out.println("pmArray is null");
catch(Exception e)
e.printStackTrace();
out.close();
}Hmm, anyone can tell me why is it still null ? is it still related to my DAO class? Or i have lacked out something?Can anyone please give me pointers and guide me along? -
Can't Find Null Pointer Exception
Hey, guys! I've spent a couple of hours trying to figure this out, and I've been unable. When I run my program, I get a long list of errors that basically says I have a NullPointerException at Line 160 in LevelRenderer. I can't figure out what is null after tons of analyzing and experimenting, so I was wondering if one of you could assist me with this.
First, here is the runtime error code:
Game Update Error: java.lang.NullPointerException
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at LevelRenderer.paint(LevelRenderer.java:160)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:6
93)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
EventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessCo
ntrolContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)Here's the code for the classes that are relevant to the issue. The runtime code is pointing me to the paint method's call of myLevel.drawLevel(gr, 0, 0):
Here's the class that is giving me the error:
/* This class's job is to render a level object.
* The class will keep track of the top left coordinate of the space in which the player is moving
* and how far the right side of the screen is. It will then draw the player always in the center
* of the screen and allow the player to move the character. The character will animate with calls
* to the Player class and also detect collision against the character. If there are collisions, then the
* player will either fall or be unable to move. It will keep the screen image a little bit rendered
* beyond the screen so that when the player moves, it will be able to still be visible until the next tile
* is reached. It will update the screen every time the player moves and reference the level's collision
* map for all of the collisions.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.JFrame;
import javax.swing.*;
import java.util.Random;
import java.awt.Color;
public class LevelRenderer extends JFrame
// CONSTANTS
private final int TILE_SIZE = 14;
private final int SCREEN_WIDTH = 1280;
private final int SCREEN_HEIGHT = 768;
// END OF CONSTANTS
// will be used as a buffer before everything is drawn to the screen
private BufferedImage buffer;
// character object
private Player myPlayer;
// level object
private Level myLevel;
// screen object
private Screen s;
// graphics object of the buffer
private Graphics gr;
// boolean to determine when to end the game
private boolean endGame;
// CONSTRUCTOR
public LevelRenderer()
setPreferredSize(new Dimension(1280, 768));
setFocusable(true);
requestFocus();
setResizable(false);
addKeyListener( new KeyAdapter()
public void keyPressed(KeyEvent e)
processKey(e);
public void keyReleased(KeyEvent e)
processRelease(e);
buffer = new BufferedImage(1280, 768, BufferedImage.TYPE_INT_ARGB);
buffer.createGraphics();
gr = buffer.getGraphics();
myPlayer = new Player();
Level myLevel = new Level("obstaclemap");
endGame = false;
// method to simply load an image from a path
public static BufferedImage loadImage(String ref)
BufferedImage bimg = null;
try
bimg = ImageIO.read(new File(ref));
catch (Exception e)
e.printStackTrace();
return bimg;
// Run method for class
public void run(DisplayMode dm)
setBackground(Color.WHITE);
s = new Screen();
try
s.setFullScreen(dm, this);
catch (Exception ex)
System.out.println("Error creating rendered tiles!");
while (!endGame)
try
Thread.sleep(2);
catch (Exception ex)
System.err.println("Error: " + ex);
try
myPlayer.animatePlayer();
myLevel.renderLevel();
catch (NullPointerException ex)
System.err.println("Game Update Error: " + ex);
try
repaint();
catch (Exception ex)
System.err.println("Repaint Error: " + ex);
s.restoreScreen();
// method to draw the tiles on the screen
public void paint(Graphics g)
// draw the level and then the player
myLevel.drawLevel(gr, 0, 0);
myPlayer.drawPlayer(gr, (SCREEN_WIDTH / 2) - TILE_SIZE / 2, (SCREEN_HEIGHT / 2) - TILE_SIZE);
g.drawImage(buffer, 0, 0, null);
// method to handle inputs and adjust the player accordingly
public void processKey(KeyEvent e)
int keyCode = e.getKeyCode();
boolean moved = false;
int xDisplace, yDisplace;
// termination key
if (keyCode == KeyEvent.VK_ESCAPE)
endGame = true;
// 1 - up
// 2 - left
// 3 - right
// 4 - down
// 5 - jump
if (keyCode == KeyEvent.VK_UP)
try
myPlayer.updatePlayer(0);
myLevel.updateLevel(0);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_LEFT)
try
myPlayer.updatePlayer(1);
myLevel.updateLevel(1);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_RIGHT)
try
myPlayer.updatePlayer(2);
myLevel.updateLevel(2);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_DOWN)
try
myPlayer.updatePlayer(3);
myLevel.updateLevel(3);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_SPACE)
try
myPlayer.updatePlayer(4);
myLevel.updateLevel(4);
catch (Exception ex)
System.err.println("Error: " + ex);
// method to handle inputs and adjust the player accordingly
public void processRelease(KeyEvent e)
int keyCode = e.getKeyCode();
boolean moved = false;
int xDisplace, yDisplace;
// 1 - up
// 2 - left
// 3 - right
// 4 - down
// 5 - jump
if (keyCode == KeyEvent.VK_UP)
try
myPlayer.updatePlayer(0);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_LEFT)
try
myPlayer.updatePlayer(5);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_RIGHT)
try
myPlayer.updatePlayer(6);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_DOWN)
try
myPlayer.updatePlayer(3);
catch (Exception ex)
System.err.println("Error: " + ex);
if (keyCode == KeyEvent.VK_SPACE)
try
myPlayer.updatePlayer(4);
catch (Exception ex)
System.err.println("Error: " + ex);
}And then here's the other class that is calling the drawLevel method that the compiler is pointing me in the direction of (where it's saying the NullPointerException is stemming from):
/* The purpose of this class will be to load and manage a level, including its camera. */
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.*;
public class Level
// CONSTANTS
private final int TILE_SIZE = 14;
private final int SCREEN_WIDTH = 1280;
private final int SCREEN_HEIGHT = 768;
// END OF CONSTANTS
// stores the pixel image of the current level
private BufferedImage levelImage;
// stores the width and height of the level
private int width, height;
// stores the name of the level
private String levelName;
// stores collision map for level
private LevelCollisions myCollisions;
// stores the tile types in an array as assigned by colors
private int levelTiles[][];
// image used as the sheet for the level's tiles
private BufferedImage tileSheet;
// image array used to store the different tiles
private BufferedImage[] tiles;
// the image which represents the current view of the level
private BufferedImage cameraImage;
// Graphics context of the camera image
private Graphics cameraG;
// variables to represent the level's offset from the top left corner while moving
private int offsetX, offsetY;
// variables to represent the level's pixel map coordinate
private int coordX, coordY;
// STATIC COLOR VARIABLES
private static final int SPACE_COLOR = 0xFF000000;
private static final int WALL_COLOR = 0xFFFFFFFF;
// END OF STATIC COLOR VARIABLES
// CONSTRUCTOR
public Level(String level)
// load level image and collision map
levelName = level;
levelImage = loadImage(level + ".png");
myCollisions = new LevelCollisions(level + "Collision");
levelTiles = loadLevel();
// create blank camera canvas
cameraImage = new BufferedImage(1280, 768, BufferedImage.TYPE_INT_ARGB);
cameraImage.createGraphics();
cameraG = cameraImage.getGraphics();
// offsets start at 0
offsetX = offsetY = 0;
// coordinate starts at bottom right
coordX = 700;
coordY = 400;
// fill tile images
tileSheet = loadImage("obstacletiles.png");
tiles = splitImage(tileSheet, 1, 2);
this.renderLevel();
// method to load the color values into an array
public int[][] loadLevel()
height = levelImage.getHeight();
width = levelImage.getWidth();
int levelValues[][] = new int[width][height];
// fill array with color values layer by layer
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
levelValues[x][y] = levelImage.getRGB(x, y);
return levelValues;
// method to get the tile color from a given tile
public int getTile(int x, int y)
return levelTiles[x][y];
// method to draw the current camera view of the level on the screen
public void drawLevel(Graphics gr, int x, int y)
gr.drawImage(cameraImage, x, y, null);
// method to render the actual image before drawing it
public void renderLevel()
// keeps track of graphics coordinate
int x, y;
// keeps track of tile to draw
int tileX, tileY;
tileY = coordY;
// draw all the tiles based on offsets, layer by layer
for (y = offsetY; y < SCREEN_HEIGHT + offsetY; y += TILE_SIZE)
tileX = coordX;
for (x = offsetX; x < SCREEN_WIDTH + offsetX; x += TILE_SIZE)
// determine which tile to draw based on tile color in array
switch (this.getTile(tileX, tileY))
case SPACE_COLOR:
cameraG.drawImage(tiles[0], x, y, null);
break;
case WALL_COLOR:
cameraG.drawImage(tiles[1], x, y, null);
break;
tileX++;
// steps to take in case of an offset
if (offsetX > 0)
if (offsetX < 0)
if (offsetY < 0)
if (offsetY > 0)
// method to update the level's current position for the camera
public void updateLevel(int input)
switch (input)
// up
case 0:
break;
// left
case 1:
// update offset to the left if not too far left
if (coordX > 30)
offsetX--;
// if a tile has been moved, then offset becomes 0 and coordX is decreased
if (offsetX <= -TILE_SIZE)
offsetX = 0;
coordX--;
break;
// right
case 2:
// update offset to the right if not too far right
if (coordX < width - 30)
offsetX++;
// if a tile has been moved, then offset becomes 0 and coordX is increased
if (offsetX >= TILE_SIZE)
offsetX = 0;
coordX++;
break;
// down
case 3:
break;
// jump
case 4:
break;
// method to simply load an image from a path
public static BufferedImage loadImage(String ref)
BufferedImage bimg = null;
try
bimg = ImageIO.read(new File(ref));
catch (Exception e)
e.printStackTrace();
return bimg;
// method to create a tile array for tile sets
public static BufferedImage[] splitImage(BufferedImage img, int cols, int rows)
int w = img.getWidth() / cols;
int h = img.getHeight() / rows;
int num = 0;
BufferedImage imgs[] = new BufferedImage[w * h];
for (int y = 0; y < rows; y++)
for (int x = 0; x < cols; x++)
imgs[num] = new BufferedImage(w, h, img.getType());
Graphics2D g = imgs[num].createGraphics();
g.drawImage(img, 0, 0, w, h, w * x, h * y, w * x + w, h * y + h, null);
g.dispose();
num++;
return imgs;
// image-loading method that will also alpha the color key for each tile
public static BufferedImage makeColorTransparent(String ref, int color)
BufferedImage image = loadImage(ref);
BufferedImage dimg = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = dimg.createGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(image, null, 0, 0);
g.dispose();
for (int i = 0; i < dimg.getHeight(); i++)
for (int j = 0; j < dimg.getWidth(); j++)
if (dimg.getRGB(j, i) == color)
dimg.setRGB(j, i, 0x8F1C1C);
return dimg;
}Sorry for the long post, but since there are several objects involved in what could be the error, I didn't want to leave anything out of this one. Help is greatly appreciated! Thank you guys very much.
Colton
Edited by: coltonoscopy on Oct 2, 2011 11:57 PMException in thread "AWT-EventQueue-0" java.lang.NullPointerException
at LevelRenderer.paint(LevelRenderer.java:160)
// method to draw the tiles on the screen
public void paint(Graphics g)
// draw the level and then the player
myLevel.drawLevel(gr, 0, 0);
myPlayer.drawPlayer(gr, (SCREEN_WIDTH / 2) - TILE_SIZE / 2, (SCREEN_HEIGHT / 2) - TILE_SIZE);
g.drawImage(buffer, 0, 0, null);
}So one of those three lines is line 160, and whichever line it is, is dereferencing a null pointer. So one of 'myLevel', 'myPlayer', or 'g' is null. Probably not 'g' as you received it as a parameter from Swing. Pretty much cuts it down.
There's nothing here you couldn't have worked out for yourself. The line number was all you needed. -
I can't figure out why I'm getting a Null Pointer Exception
I'm writing a program that calls Bingo numbers. I got that part of the program to work but when I started adding Swing I kept getting a Null Pointer Exception and I don't know how to fix it. The Exception happens on line 15 of class Panel (g = image.getGraphics();). Here is the code for my classes. I'm still not finished with the program and I can't finish it until I know that this issue is resolved.
package Graphics;
import java.awt.Graphics;
import javax.swing.JFrame;
public class DrawFrame extends JFrame{
public Panel panel;
public DrawFrame(int x, int y, String s) {
super(s);
this.setBounds(0, 0, x, y);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setPreferredSize(getSize());
panel = this.getPanel();
this.getContentPane().add(panel);
panel.init();
this.setVisible(true);
public Graphics getGraphicsEnvironment(){
return panel.getGraphicsEnvironment();
Panel getPanel(){
return new Panel();
package Graphics;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
public class Panel extends JPanel{
Graphics g;
Image image;
public void init() {
image = this.createImage(this.getWidth(), this.getHeight());
g = image.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
Graphics getGraphicsEnvironment() {
return g;
public void paint(Graphics graph) {
if (graph == null)
return;
if (image == null) {
return;
graph.drawImage(image, 0, 0, this);
package Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Keys extends KeyAdapter{
public int keyPressed; //creates a variable keyPressed that stores an integer
public void keyPressed(KeyEvent e) { //creates a KeyEvent from a KeyListner
keyPressed = e.getKeyCode(); //gets the key from the keyboard
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import Graphics.*;
public class Bingo {
static Ball balls[][] = new Ball[5][15]; //creates a 2D 5 by 15 array
public static void main(String[] args) {
DrawFrame frame = new DrawFrame(1500, 500, "Welcome to the automated Bingo Caller."); //creates instance of DrawFrame that is 1000 pixels wide and 500 pixels high
Graphics g = frame.getGraphicsEnvironment(); //calls the getGraphicsEnvironment method in the DrawFrame class
Keys key = new Keys(); //creates instance of the Key class
frame.addKeyListener(key); //adds a KeyListener called Key
for (int x = 0; x < 5; x++) { //fills rows
for (int y = 0; y < 15; y++) { //fills columns
balls[x][y] = new Ball(x, y+1); //fills array
frame.pack(); //adjusts the size of the frame so everything fits
g.setColor(Color.black); //sets the font color to black
g.setFont(new Font("MonoSpace", Font.PLAIN, 20)); //creates new font
for(int y=0;y<balls.length;y++){ //draws all possible balls
g.drawString(balls[y][0].s, 0, y*100); //draws numbers
for(int x=0;x<balls[y].length;x++){ //draws all possible balls
g.drawString(balls[y][x].toString(), (x+1)*100, y*100); //draws letters
do {
frame.repaint(); //repaints the balls when one is called
int x, y; //sets variables x and y as integers
boolean exit; //sets a boolean to the exit variable
do {
exit = false; //exit is set to false
x = (int)(Math.random() * 5); //picks a random number between 0 and 4 and stores it as x
y = (int)(Math.random() * 15); //picks a random number between 0 and 14 stores it as y
if (!balls[x][y].called) { //checks to see if a value is called
exit = true; //changes exit to true if it wasn't called
balls[x][y].called = true; //sets called in the Ball class to true if it wasn't called
System.out.println(balls[x][y]); //prints value
} while (!exit); //if exit is false, returns to top of loop
int count = 0; //sets a count for the number of balls called
for(int z=0;z<balls.length;z++){ //looks at balls
g.setColor(Color.black); //displays in black
g.drawString(balls[z][0].s, 0, z*100); //draws balls as a string
for(int a=0;a<balls[z].length;a++){ //looks at all balls
if (balls[z][a].called){ //if a ball is called
g.setColor(Color.red); //change color to red
count++; //increments count
} else {
g.setColor(Color.black); //if it isn't called stay black
g.drawString(balls[z][a].toString(), (a+1)*100, y*100); //draws balls as string
do {
if (key.keyPressed == KeyEvent.VK_R||count==5*15) { //if R is pressed or count = 5*15
count=5*15; //changes count to 5*15
for(int z=0;z<balls.length;z++){ //recreates rows
g.setColor(Color.black); //sets color to black
g.drawString(balls[z][0].s, 0, z*100); //redraws rows
for(int a=0;a<balls[z].length;a++){ //recreates columns
balls[z][a] = new Ball(z, a+1); //fills array
g.drawString(balls[z][a].toString(), (a+1)*100, z*100); //redraws columns
} while (key.keyPressed!=KeyEvent.VK_ENTER || count == 5 * 15); //determines if the key was pressed or counter is 5*15s
} while (key.keyPressed == KeyEvent.VK_ENTER);
public class Ball {
String s; //initiates s that can store data type String
int i; //initiates i that can store data as type integer
boolean called = false; //initiates called as a boolean value and sets it to false
public Ball(int x, int y) {
i = (x * 15) + y; //stores number as i to be passed to be printed
switch (x) { //based on x value chooses letter
case 0:
s = "B";
break;
case 1:
s = "I";
break;
case 2:
s = "N";
break;
case 3:
s = "G";
break;
case 4:
s = "O";
public String toString() { //overrides toString method, converts answer to String
return s + " " + i; //returns to class bingo s and i
}The javadoc of createImage() states that "The return value may be null if the component is not displayable."
Not sure, but it may be that you need to call init() after this.setVisible(true). -
I'm trying to edit a talking head video and want to find an straightforward way to mark a spot at the end of a statement made by the subject and then cut the clip at that point. Can you help? Thanks.
I don't know how to mark a clip the way you want without adding an audio clip and putting in markers and then splitting the clip. You would think that hitting M would be the logical way to do things, but...
But, one can just click before the place one wants to edit, hit the spacebar and hit it again when the exact place is reached. Then go to the clip menu and click split clip. That works, but one really needs to keep the cursor out of both the timeline and the event browser, or the place in the timeline gets changed..
Are you really still using iMovie 08? That drove me nuts...a year later iMovie 09 came out with some needed improvements, and iMovie 11 with its audio adjustments is even better.
Personally, I edit iMovie with kind of a meat axe. I grab whole chunks of video and put it into the project, then edit the ends to get the frame I want. I got too frustrated otherwise.
Hugh -
How can i create a NULL-Pointer
Hello,
how can i create a NULL-pointer (like in C) to call a DLL-function in Labview 8?
I have this function:
XXXXXX FuncName(int32 handle,
char * aCharName,
void * aVoidName,
int32 aInt32Name,
char * Msg);
and have to call it like this:
rc=InitCasRunF(&handle, NULL, NULL, NULL, msg);
When running the vi i get a popup with this message:
Labview: An exception occured within the external code called by a Call Library Function Node.
This might have corrupted Labview´s memory. Save any work to a new location and restart Labview.
VI "......." was stopped at Call Library Function Node Call Library FuncName 0x13E0 of subVI.
Democall.vi
The attached democall.vi is not the original but its like that.
Thanks for any help how i have to create thi NULL-pointer
Message Edited by NewOne on 01-25-2006 03:42 AM
Attachments:
democall.vi 8 KBThx for your help. Meanwhile it works. It was a stupid, easy thing i didnt see all the time.
I had to change the first parameter as--> Pass: "Pointer to value" instead of "Value". Thats all.
All NULL-values are passed as Int32-value.
One new problem occurs now: After runnning the function Labview crashes down.
Error-report is attached if someone can read someting in this.
When running the dll-function in a c-program it works
When calling the dll-function it in teststand it also works.
Message Edited by NewOne on 01-26-2006 05:14 AM
Attachments:
dce5_appcompat.txt 47 KB -
Action Script 3, can someone spot where my code is wrong?
I want to have my characters controlled separately, with 'FireBoy' moving using the left, up and right keys and with 'WaterGirl' moving with the a, w and d keys. However upon editing my code somehow WaterGirl now moves with the right key instead of the d key. Please can someone spot where I have made a mistake and advise me on how to resolve the problem.
My code for main.as is:
package
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
* @author Harry
public class Main extends Sprite
private var leftDown:Boolean = false;
private var rightDown:Boolean = false;
private var aDown:Boolean = false;
private var dDown:Boolean = false;
private var FireBoy:Hero = new Hero();
public var StartButton:Go;
public var WaterGirl:Female = new Female();
public var Door1:Firedoor;
public var Door2:Waterdoor;
public var Fire:Lava;
public var Water:Blue;
public var Green:Gem;
public function Main():void
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
public function init(e:Event = null):void
StartButton = new Go();
StartButton.x = 100;
StartButton.y = 5;
addChild(StartButton);
StartButton.addEventListener(MouseEvent.CLICK, startgame);
private function startgame(e:Event = null):void
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
removeChild(StartButton);
FireBoy.y = 495;
addChild(FireBoy);
stage.addEventListener(Event.ENTER_FRAME, HerocheckStuff);
stage.addEventListener(KeyboardEvent.KEY_DOWN, HerokeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP, HerokeysUp);
WaterGirl.x = 70;
WaterGirl.y = 495;
addChild(WaterGirl);
stage.addEventListener(Event.ENTER_FRAME, FemalecheckStuff);
stage.addEventListener(KeyboardEvent.KEY_DOWN, FemalekeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP, FemalekeysUp);
Door1 = new Firedoor();
stage.addChild(Door1);
Door1.x = 5;
Door1.y = 62;
Door2 = new Waterdoor();
stage.addChild(Door2);
Door2.x = 100;
Door2.y = 62;
Fire = new Lava();
stage.addChild(Fire);
Fire.x = 160;
Fire.y = 570;
Water = new Blue();
stage.addChild(Water);
Water.x = 350;
Water.y = 160;
Green = new Gem()
stage.addChild(Green);
Green.x = 500;
Green.y = 100;
graphics.beginFill(0x804000, 1);
graphics.drawRect(0, 0, 800, 40);
graphics.endFill();
graphics.beginFill(0x804000, 1);
graphics.drawRect(0, 170, 600, 40);
graphics.endFill();
graphics.beginFill(0x804000, 1);
graphics.moveTo(800, 200);
graphics.lineTo(800, 700);
graphics.lineTo(400, 700);
graphics.lineTo(100, 700);
graphics.endFill();
graphics.beginFill(0x804000, 1);
graphics.drawRect(0, 580, 800, 40);
graphics.endFill();
public function Collision():void
if (WaterGirl.hitTestObject(Fire))
WaterGirl.x = 70;
WaterGirl.y = 495;
if (FireBoy.hitTestObject(Water))
FireBoy.x = 15;
FireBoy.y = 495;
public function HerocheckStuff(e:Event):void
if (leftDown)
FireBoy.x -= 5;
if (rightDown)
FireBoy.x += 5;
FireBoy.adjust();
Collision();
Check_Border();
public function HerokeysDown(e:KeyboardEvent):void
if (e.keyCode == 37)
leftDown = true;
if (e.keyCode == 39)
rightDown = true;
if (e.keyCode == 38)
FireBoy.grav = -15;
Collision();
Check_Border();
public function HerokeysUp(e:KeyboardEvent):void
if (e.keyCode == 37)
leftDown = false;
if (e.keyCode == 39)
rightDown = false;
public function FemalecheckStuff(e:Event):void
if (aDown)
WaterGirl.x -= 5;
if (rightDown)
WaterGirl.x += 5;
WaterGirl.adjust2();
Collision();
Check_Border();
public function FemalekeysDown(e:KeyboardEvent):void
if (e.keyCode == 65)
aDown = true;
if (e.keyCode == 68)
dDown = true;
if (e.keyCode == 87)
WaterGirl.grav = -15;
Collision();
Check_Border();
public function FemalekeysUp(e:KeyboardEvent):void
if (e.keyCode == 65)
aDown = false;
if (e.keyCode == 68)
dDown = false;
public function Check_Border():void
if (FireBoy.x <= 0)
FireBoy.x = 0;
else if (FireBoy.x > 750)
FireBoy.x = 750;
if (WaterGirl.x <= 0)
WaterGirl.x = 0;
else if (WaterGirl.x > 750)
WaterGirl.x = 750;
My code for Hero.as (FireBoy) is:
package
import flash.display.Bitmap;
import flash.display.Sprite;
public class Hero extends Sprite
[Embed(source="../assets/FireBoy.jpg")]
private static const FireBoy:Class;
private var FireBoy:Bitmap;
public var grav:int = 0;
public var floor:int = 535;
public function Hero()
FireBoy = new Hero.FireBoy();
scaleX = 0.1;
scaleY = 0.1;
addChild(FireBoy);
public function adjust():void
this.y += grav;
if(this.y+this.height/2<floor)
grav++;
else
grav = 0;
this.y = floor - this.height / 2;
if (this.x - this.width / 2 < 0)
this.x = this.width / 2;
if (this.x + this.width / 2 > 800)
this.x = 800 - this.width / 2;
And finally my code for Female.as (WaterGirl) is:
package
import flash.display.Bitmap;
import flash.display.Sprite;
* @author Harry
public class Female extends Sprite
[Embed(source="../assets/WaterGirl.png")]
private static const WaterGirl:Class;
private var WaterGirl:Bitmap;
public var grav:int = 0;
public var floor:int = 535;
public function Female()
WaterGirl = new Female.WaterGirl();
scaleX = 0.1;
scaleY = 0.1;
addChild(WaterGirl);
public function adjust2():void
this.y += grav;
if(this.y+this.height/2<floor)
grav++;
else
grav = 0;
this.y = floor - this.height / 2;
if (this.x - this.width / 2 < 0)
this.x = this.width / 2;
if (this.x + this.width / 2 > 800)
this.x = 800 - this.width / 2;You should make use of the trace function to troubleshoot your processing. Put traces in the different movement function conditionals to see which is being used under which circumstances. You might consider putting the movement code into one function since they all execute when you process a keyboard event anyways.
-
Problems with Overlay Layout - can anyone spot something wrong/missing?
Hi folks, I'm developing a tool that allows you to draw rectangles around objects on an image. The rectangles are then saved, and you can move between images. For some reason, though my rectangles are not drawing on the panel. I am using the Overlay Layout. Can anyone spot what I'm doing wrong? (The TopPanel canvas appears to be there, as it's taking input from the mouse - the problem is simply that the red rectangles are not drawing on the panel). Please help!!
So you know, there is a JFrame in another class which adds an instance of the ObjectMarker panel to it. It also provides buttons for using the next and previous Image methods.
Any other general advice is appreciated too.
* Object_Marker.java
* Created on 07 April 2008, 15:38
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.OverlayLayout;
import javax.swing.event.MouseInputAdapter;
* @author Eric
public class ObjectMarker extends javax.swing.JPanel {
private static final long serialVersionUID = 6574271353772129556L;
File directory;
String directory_path;
Font big = new Font("SansSerif", Font.BOLD, 18);
List<File> file_list = Collections.synchronizedList(new LinkedList<File>());
String[] filetypes = { "jpeg", "jpg", "gif", "bmp", "tif", "tiff", "png" };
// This Hashmap contains List of Rectangles, allowing me to link images to collections of rectangles through the value 'index'.
public static HashMap<Integer, List<Rectangle>> collection = new HashMap<Integer, List<Rectangle>>();
BufferedImage currentImage;
Thread thread;
Integer index = 0;
OverlayLayout overlay;
private TopPanel top;
private JPanel pictureFrame;
String newline = System.getProperty("line.separator");
* Creates new form Object_Marker
* @throws IOException
public ObjectMarker(File directory) {
System.out.println("Got in...");
this.directory = directory;
File[] temp = directory.listFiles();
directory_path = directory.getPath();
// Add all the image files in the directory to the linked list for easy
// iteration.
for (File file : temp) {
if (isImage(file)) {
file_list.add(file);
initComponents();
try {
currentImage = ImageIO.read(file_list.get(index));
} catch (IOException e) {
System.out.println("There was a problem loading the image.");
// 55 pixels offsets the height of the JMenuBar and the title bar
// which are included in the size of the JFrame.
this.setSize(currentImage.getWidth(), currentImage.getHeight() + 55);
public String getImageList() {
// Allows me to build the string gradually.
StringBuffer list = new StringBuffer();
list.append("Image files found in directory: \n\n");
for (int i = 0; i < file_list.size(); i++) {
list.append((((File) file_list.get(i))).getName() + "\n");
return list.toString();
private void initComponents() {
top = new TopPanel();
pictureFrame = new javax.swing.JPanel();
OverlayLayout ol = new OverlayLayout(this);
this.setLayout(ol);
this.add(top);
this.add(pictureFrame);
* private void initComponents() {
* javax.swing.GroupLayout pictureFrameLayout = new
* javax.swing.GroupLayout(pictureFrame);
* pictureFrame.setLayout(pictureFrameLayout);
* pictureFrameLayout.setHorizontalGroup(
* pictureFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
* .addGap(0, 497, Short.MAX_VALUE) ); pictureFrameLayout.setVerticalGroup(
* pictureFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
* .addGap(0, 394, Short.MAX_VALUE) );
* javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
* this.setLayout(layout); layout.setHorizontalGroup(
* layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
* .addComponent(pictureFrame, javax.swing.GroupLayout.DEFAULT_SIZE,
* javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) );
* layout.setVerticalGroup(
* layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
* .addComponent(pictureFrame, javax.swing.GroupLayout.DEFAULT_SIZE,
* javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); }
* This function returns the extension of a given file, for example "jpg" or
* "gif"
* @param f
* The file to examine
* @return String containing extension
public static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
} else {
ext = "";
return ext;
public String getDetails() {
saveRectangles();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < file_list.size(); i++) {
try{
int count = collection.get(i).size();
if (count > 0) {
sb.append(file_list.get(i).getPath() + " "); // Add the
// filename of
// the file
sb.append(count + " "); // Add the number of rectangles
for (int j = 0; j < collection.get(i).size(); j++) {
Rectangle current = collection.get(i).get(j);
String coordinates = (int) current.getMinX() + " "
+ (int) current.getMinY() + " ";
String size = ((int) current.getMaxX() - (int) current
.getMinX())
+ " "
+ ((int) current.getMaxY() - (int) current
.getMinY()) + " ";
String result = coordinates + size;
sb.append(result);
sb.append(newline);
} catch (NullPointerException e){
// Do nothing. "int count = collection.get(i).size();"
// will try to over count.
return sb.toString();
private boolean isImage(File f) {
List<String> list = Arrays.asList(filetypes);
String extension = getExtension(f);
if (list.contains(extension)) {
return true;
return false;
/** Draw the image on the panel. * */
public void paint(Graphics g) {
if (currentImage == null) {
g.drawString("No image to display!", 300, 240);
} else {
// Draw the image
g.drawImage(currentImage, 0, 0, this);
// Write the index
g.setFont(big);
g.drawString(index + 1 + "/" + file_list.size(), 10, 25);
public void nextImage() throws IOException {
if (index < file_list.size() - 1) {
printOutContents();
System.out.println("Index: " + index);
saveRectangles();
index++;
currentImage = ImageIO.read(file_list.get(index));
this
.setSize(currentImage.getWidth(),
currentImage.getHeight() + 55);
top.setSize(this.getSize());
top.rectangle_list.clear();
if (collection.size() > index) {
loadRectangles();
repaint();
private void saveRectangles() {
// If the current image's rectangles have not been changed, don't do
// anything.
if (collection.containsKey(index)) {
System.out.println("Removing Index: " + index);
collection.remove(index);
collection.put(index, top.getRectangleList());
System.out.println("We just saved " + collection.get(index).size()
+ " rectangles");
System.out.println("They were saved in HashMap Location " + index);
System.out.println("Proof: ");
List<Rectangle> temp = collection.get(index);
for (int i = 0; i < temp.size(); i++) {
System.out.println("Rectangle " + (i + 1) + ": " + temp.get(i));
// If the rectangle list has changed, set the list the current index
// as the new list.
private void loadRectangles() {
System.out.println("We just loaded index " + index
+ " into temporary memory.");
System.out.println("Proof: ");
List<Rectangle> temp = collection.get(index);
top.rectangle_list = collection.get(index);
for (int i = 0; i < temp.size(); i++) {
System.out.println("Rectangle " + (i + 1) + ": " + temp.get(i));
private void printOutContents() {
System.out.println();
System.out.println("Contents printout...");
for (int i = 0; i < collection.size(); i++) {
for (Rectangle r : collection.get(i)) {
System.out.println("In collection index: " + i + " Rectangle "
+ r.toString());
System.out.println();
public void previousImage() throws IOException {
if (index >= 1) {
printOutContents();
System.out.println("Index: " + index);
saveRectangles();
index--;
currentImage = ImageIO.read(file_list.get(index));
this
.setSize(currentImage.getWidth(),
currentImage.getHeight() + 55);
top.setSize(this.getSize());
top.rectangle_list.clear();
if (index >= 0) {
loadRectangles();
repaint();
public void removeLastRectangle() {
// This method removes the most recent rectangle added.
try {
int length = collection.get(index).size();
collection.get(index).remove(length - 1);
} catch (NullPointerException e) {
try {
top.rectangle_list.remove(top.rectangle_list.size() - 1);
} catch (IndexOutOfBoundsException ioobe) {
JOptionPane.showMessageDialog(this, "Cannot undo any more!");
* Class developed from SSCCE found on Java forum:
* http://forum.java.sun.com/thread.jspa?threadID=647074&messageID=3817479
* @author 74philip
class TopPanel extends JPanel {
List<Rectangle> rectangle_list;
private static final long serialVersionUID = 6208367976334130998L;
Point loc;
int width, height, arcRadius;
Rectangle temp; // for mouse ops in TopRanger
public TopPanel() {
setOpaque(false);
rectangle_list = Collections
.synchronizedList(new LinkedList<Rectangle>());
TopRanger ranger = new TopRanger(this);
addMouseListener(ranger);
addMouseMotionListener(ranger);
public List<Rectangle> getRectangleList() {
List<Rectangle> temporary = Collections
.synchronizedList(new LinkedList<Rectangle>());
temporary.addAll(rectangle_list);
return temporary;
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.red);
// Draw all the rectangles in the rectangle list.
for (int i = 0; i < rectangle_list.size(); i++) {
g2.drawRect(rectangle_list.get(i).x, rectangle_list.get(i).y,
rectangle_list.get(i).width, rectangle_list.get(i).height);
if (temp != null) {
g2.draw(temp);
public void loadRectangleList(List<Rectangle> list) {
rectangle_list.addAll(list);
public void addRectangle(Rectangle r) {
rectangle_list.add(r);
class TopRanger extends MouseInputAdapter {
TopPanel top;
Point offset;
boolean dragging;
public TopRanger(TopPanel top) {
this.top = top;
dragging = false;
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
top.temp = new Rectangle(p, new Dimension(0, 0));
offset = new Point();
dragging = true;
top.repaint();
public void mouseReleased(MouseEvent e) {
dragging = false;
// update top.r
System.out.println(top.getRectangleList().size() + ": Object added: "
+ top.temp.toString());
top.addRectangle(top.temp);
top.repaint();
public void mouseDragged(MouseEvent e) {
if (dragging) {
top.temp.setBounds(top.temp.x, top.temp.y, e.getX() - top.temp.x, e
.getY()
- top.temp.y);
top.repaint();
}Regards,
EricAlright so I fixed it! I created a new class called BottomPanel extends JPanel, which I then gave the responsibility of drawing the image. I gave it an update method which took the details of the currentImage and displayed it on the screen.
If anybody's interested I also discovered/solved a problem with my mouseListener - I couldn't drag backwards. I fixed this by adding tests looking for negative widths and heights. I compensated accordingly by reseting the rectangle origin to e.getX(), e.getY() and by setting the to original_origin.x - e.getX() and original_origin.y - e.getY().
No problem! -
Null pointer error if not started with 1st in string
hi, this little pratice is about building a simple shopping cart. the TOAD.JSP will display the item list and quantity, user could check item and input the quantity that they want. if the user input larger quantity than database, servlet will sent the back to TOAD.jsp and show message. now it works if selected from 1 item, but if selected 2nd or 3rd, it will have null pointer error over here:
for(int i=0; i<ItemList.size(); i++)
newit = (ItemBean)ItemList.get(i);
if (item != null && item.equals(newit.getItem()) )
%>
<tr>
<td ><input type="checkbox" name = "item" value="<%= newit.getItem() %>"><b><%= newit.getItem() %> </b><br></td>
<td><input type=text name="<%= newit.getItem() %>Qty" value="<%= orderQty%>"></td>
</tr>
<tr><td colspan = 2>
<font size="3" color="red">
The item <%= newit.getItem() %> is NOT available in stock</font>
</td>
</tr>
<%
} else {
%>
<tr>
<td ><input type="checkbox" name = "item" value="<%= newit.getItem() %>"><b><%= newit.getItem() %> </b><br></td>
<td><b><input type=text name="<%= newit.getItem() %>Qty" value="<%= newit.getQty()%>"></b> </td>
</tr>
<%
%>
thanks for your time!You have prvided unsufficent information and poorly formatted code and as such no meaningful answer can given you at present.
But here is the best that one can guess at.
You have a null somewhere.
Is it coming from this code? I am going to say no.
Where does it come from? I don't know.
Where should you look? In the code that does processing to see what happens when yuo have more than one item.
What should you do next? Start putting in some debugging and tracing statements to see where you are heading off into the null abyss. -
Adding a new UDF throws a null pointer exception and modifying user.xml
Hello,
I have a two part question.
i. I am trying to add a UDF (using Advanced>User Configuration..Attributes) to a fully configured OIM i.e. oim with reconciliation and provisioning from and to resources but it throws a null pointer exception. Look at the log, I see
===============Excerpt form the log file==========
[2012-01-26T11:28:14.447-05:00] [oim_server1] [NOTIFICATION] [] [oracle.iam.platform.authz.impl] [tid: [ACTIVE].ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: xelsysadm] [ecid: 0000JKQq8vZ8dpC5nFk3yZ1Evvpt000LzY,0] [APP: oim#11.1.1.3.0] [dcid: c62f3a4b80d21e6f:ef93519:134587d39c4:-7ffd-0000000000022a3e] [[
---Stack Trace Begins[[This is not an exception. For debugging purposes]]---
oracle.iam.platform.authz.impl.OESAuthzServiceImpl.doCheckAccess(OESAuthzServiceImpl.java:210)
oracle.iam.platform.authz.impl.OESAuthzServiceImpl.hasAccess(OESAuthzServiceImpl.java:188)
oracle.iam.platform.authz.impl.OESAuthzServiceImpl.hasAccess(OESAuthzServiceImpl.java:180)
oracle.iam.platform.authz.impl.AuthorizationServiceImpl.hasAccess(AuthorizationServiceImpl.java:173)
oracle.iam.configservice.impl.ConfigManagerImpl.checkAuthorization(ConfigManagerImpl.java:1899)
oracle.iam.configservice.impl.ConfigManagerImpl.addAttribute(ConfigManagerImpl.java:177)
oracle.iam.configservice.api.ConfigManagerEJB.addAttributex(Unknown Source)
... 21 lines skipped..
oracle.iam.configservice.api.ConfigManager_5u0nrx_ConfigManagerRemoteImpl.addAttributex(ConfigManager_5u0nrx_ConfigManagerRemoteImpl.java:864)
... 13 lines skipped..
oracle.iam.configservice.api.ConfigManagerDelegate.addAttribute(Unknown Source)
oracle.iam.configservice.agentry.config.CreateAttributeActor.perform(CreateAttributeActor.java:266)
oracle.iam.consoles.faces.mvc.canonic.Model.perform(Model.java:547)
oracle.iam.consoles.faces.mvc.admin.Model.perform(Model.java:324)
oracle.iam.consoles.faces.mvc.canonic.Controller.doPerform(Controller.java:255)
oracle.iam.consoles.faces.mvc.canonic.Controller.doSelectAction(Controller.java:178)
oracle.iam.consoles.faces.event.NavigationListener.processAction(NavigationListener.java:97)
... 24 lines skipped..
oracle.iam.platform.auth.web.PwdMgmtNavigationFilter.doFilter(PwdMgmtNavigationFilter.java:115)
... weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
oracle.iam.platform.auth.web.OIMAuthContextFilter.doFilter(OIMAuthContextFilter.java:100)
... 15 lines skipped..
weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
---Stack Tracefor this call Ends---
[2012-01-26T11:28:14.447-05:00] [oim_server1] [NOTIFICATION] [IAM-1010010] [oracle.iam.platform.authz.impl] [tid: [ACTIVE].ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: xelsysadm] [ecid: 0000JKQq8vZ8dpC5nFk3yZ1Evvpt000LzY,0] [APP: oim#11.1.1.3.0] [dcid: c62f3a4b80d21e6f:ef93519:134587d39c4:-7ffd-0000000000022a3e] [arg: 1] [arg: null] [arg: USER_MANAGEMENT_CONFIG] [arg: CREATE_ATTRIBUTE] ********** Entering the Authorization Segment with parameters:: LoggedInUserId = 1, target resourceID = null, Feature = USER_MANAGEMENT_CONFIG, Action = CREATE_ATTRIBUTE **********
[2012-01-26T11:28:14.448-05:00] [oim_server1] [NOTIFICATION] [IAM-1010021] [oracle.iam.platform.authz.impl] [tid: [ACTIVE].ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: xelsysadm] [ecid: 0000JKQq8vZ8dpC5nFk3yZ1Evvpt000LzY,0] [APP: oim#11.1.1.3.0] [dcid: c62f3a4b80d21e6f:ef93519:134587d39c4:-7ffd-0000000000022a3e] [arg: [InternalObligation: name: noop, values: [true], convertToObligation: false, InternalObligation: name: noop, values: [true], convertToObligation: false]] Validating the Internal Obligations: [InternalObligation: name: noop, values: [true], convertToObligation: false, InternalObligation: name: noop, values: [true], convertToObligation: false]
[2012-01-26T11:28:14.448-05:00] [oim_server1] [NOTIFICATION] [IAM-1010022] [oracle.iam.platform.authz.impl] [tid: [ACTIVE].ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: xelsysadm] [ecid: 0000JKQq8vZ8dpC5nFk3yZ1Evvpt000LzY,0] [APP: oim#11.1.1.3.0] [dcid: c62f3a4b80d21e6f:ef93519:134587d39c4:-7ffd-0000000000022a3e] ---------- The list of Internal Obligation is satisfied, returning TRUE ----------
[2012-01-26T11:28:14.448-05:00] [oim_server1] [NOTIFICATION] [IAM-1010026] [oracle.iam.platform.authz.impl] [tid: [ACTIVE].ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: xelsysadm] [ecid: 0000JKQq8vZ8dpC5nFk3yZ1Evvpt000LzY,0] [APP: oim#11.1.1.3.0] [dcid: c62f3a4b80d21e6f:ef93519:134587d39c4:-7ffd-0000000000022a3e] [arg: Decision :PERMIT\nObligations from policy: ] ********** Exiting the Authorization Segment with result Decision :PERMIT[[
=============Excerpt ends==============
Is there a reason why this is and how do I get by it.
ii. Can I just add the field directly within the MDS>file/user.xml? Would there be an issue with changing an existing attribute metadata using the user.xml?Pradeep thank you for your response. it was helpful. However, I also found the responses to both my questions.
i. The null pointer exception was due to using a complex query I was using in the LOV query. I tried a simple query and that worked fine.
ii. For modifying the user defined attributes one can consult the following forum post:
OIM 11g - Change UDF Field Type form String to LOV
Thanks -
Why am I receiving Null pointer Exception Error.
why am I receiving Null pointer Exception Error.
Hi I am developing a code for login screen. There is no syntex error as such ut I am receving the aove mentioned error. Can some one please help me ??
------------ Main.java------------------
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Main implements ActionListener
Frame mainf;
MenuBar mb;
MenuItem List,admitform,inquiry,exit,helpn;
Menu newm,update,help;
Inquiry iq;
Admit ad;
// HosHelp hp;
Howuse hu;
Register reg;
Main()
mainf=new Frame(" Engg College V/S Mumbai University ");
mb=new MenuBar();
newm=new Menu(" New ");
update=new Menu(" Update ");
help=new Menu(" Help ");
List=new MenuItem("List");
admitform=new MenuItem("Admit");
inquiry=new MenuItem("Inquiry");
exit=new MenuItem("Exit");
helpn=new MenuItem("How to Use?");
newm.add(List);
newm.add(admitform);
newm.add(inquiry);
newm.add(exit);
help.add(helpn);
mb.add(newm);
mb.add(update);
mb.add(help);
mainf.setMenuBar(mb);
exit.addActionListener(this);
List.addActionListener(this);
inquiry.addActionListener(this);
admitform.addActionListener(this);
helpn.addActionListener(this);
mainf.setSize(400,300);
mainf.setVisible(true);
public void actionPerformed(ActionEvent ae)
if (ae.getSource()==List)
reg=new Register();
if(ae.getSource()==inquiry)
iq=new Inquiry();
if(ae.getSource()==admitform)
ad=new Admit();
if(ae.getSource()==helpn)
hu=new Howuse();
if(ae.getSource()==exit)
mainf.setVisible(false);
public static void main(String args[])
new Main();
-------------Register.java---------------------------
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Register implements ActionListener//,ItemListener
Label id,name,login,pass,repass;
Button ok,newu,cancel,check;
Button vok,iok,lok,mok,sok; //buttons for dialog boxes
TextField idf,namef,loginf,passf,repassf;
Dialog valid,invlog,less,mismat,acucreat;
Frame regis;
Checkbox admin,limit;
CheckboxGroup type;
DBconnect db;
Register()
db=new DBconnect();
regis=new Frame("Registeration Form");
type=new CheckboxGroup();
admin=new Checkbox("Administrator",type,true);
limit=new Checkbox("Limited",type,false);
id=new Label("ID :");
name=new Label("Name :");
login=new Label("Login :");
pass=new Label("Password :");
repass=new Label("Retype :");
idf =new TextField(20); idf.setEnabled(false);
namef=new TextField(30); namef.setEnabled(false);
loginf=new TextField(30); loginf.setEnabled(false);
passf=new TextField(30); passf.setEnabled(false);
repassf=new TextField(30); repassf.setEnabled(false);
ok=new Button("OK"); ok.setEnabled(false);
newu=new Button("NEW");
cancel=new Button("Cancel");
check=new Button("Check Login"); check.setEnabled(false);
vok=new Button("OK");
iok=new Button("OK");
lok=new Button("OK");
mok=new Button("OK");
sok=new Button("OK");
valid=new Dialog(regis,"Login name is valid !");
invlog=new Dialog(regis,"Login name already exist!");
less=new Dialog(regis,"Password is less than six characters !");
mismat=new Dialog(regis,"password & retyped are not matching !");
acucreat=new Dialog(regis,"You have registered successfully !");
regis.setLayout(null);
// regis.setBackground(Color.orange);
valid.setLayout(new FlowLayout());
invlog.setLayout(new FlowLayout());
less.setLayout(new FlowLayout());
mismat.setLayout(new FlowLayout());
acucreat.setLayout(new FlowLayout());
id.setBounds(35,50,80,25); //(left,top,width,hight)
idf.setBounds(125,50,40,25);
name.setBounds(35,85,70,25);
namef.setBounds(125,85,150,25);
login.setBounds(35,120,80,25);
loginf.setBounds(125,120,80,25);
check.setBounds(215,120,85,25);
pass.setBounds(35,155,80,25);
passf.setBounds(125,155,80,25);
repass.setBounds(35,190,80,25);
repassf.setBounds(125,190,80,25);
admin.setBounds(35,225,100,25);
limit.setBounds(145,225,100,25);
ok.setBounds(45,265,70,25);
newu.setBounds(135,265,70,25);
cancel.setBounds(225,265,70,25);
passf.setEchoChar('*');
repassf.setEchoChar('*');
regis.add(id);
regis.add(idf);
regis.add(name);
regis.add(namef);
regis.add(login);
regis.add(loginf);
regis.add(check);
regis.add(pass);
regis.add(passf);
regis.add(repass);
regis.add(repassf);
regis.add(ok);
regis.add(newu);
regis.add(cancel);
regis.add(admin);
regis.add(limit);
valid.add(vok);
invlog.add(iok);
less.add(lok);
mismat.add(mok);
acucreat.add(sok);
ok.addActionListener(this);
newu.addActionListener(this);
check.addActionListener(this);
cancel.addActionListener(this);
// limit.addItemListener(this);
//admin.addItemListener(this);
vok.addActionListener(this);
iok.addActionListener(this);
lok.addActionListener(this);
mok.addActionListener(this);
sok.addActionListener(this);
regis.setLocation(250,150);
regis.setSize(310,300);
regis.setVisible(true);
public void actionPerformed(ActionEvent ae)
if(ae.getSource()==check)
try{
String s2=loginf.getText();
ResultSet rs=db.s.executeQuery("select* from List");
while(rs.next())
if(s2.equals(rs.getString(2).trim()))
// invlog.setBackground(Color.orange);
invlog.setLocation(250,150);
invlog.setSize(300,100);
cancel.setEnabled(false);
ok.setEnabled(false);
check.setEnabled(false);
invlog.setVisible(true);
break;
else
// valid.setBackground(Color.orange);
valid.setLocation(250,150);
valid.setSize(300,100);
cancel.setEnabled(false);
ok.setEnabled(false);
check.setEnabled(false);
valid.setVisible(true);
}catch(Exception e)
e.printStackTrace();
if(ae.getSource()==newu)
try{
ResultSet rs=db.s.executeQuery("select max(ID) from List");
while(rs.next())
String s1=rs.getString(1).trim();
int i=Integer.parseInt(s1);
i++;
String s2=""+i;
idf.setText(s2);
newu.setEnabled(false);
namef.setText(""); namef.setEnabled(true);
loginf.setText(""); loginf.setEnabled(true);
passf.setText(""); passf.setEnabled(true);
repassf.setText(""); repassf.setEnabled(true);
ok.setEnabled(true);
check.setEnabled(true);
}catch(Exception e)
e.printStackTrace();
if(ae.getSource()==ok)
try
String s1=idf.getText();
String s2=loginf.getText();
String s3=passf.getText();
String s4=repassf.getText();
int x=Integer.parseInt(s1);
int t;
if(type.getSelectedCheckbox()==admin)
t=1;
else
t=0;
ResultSet rs=db.s1.executeQuery("select* from List");
while(rs.next())
if(s2.equals(rs.getString(2).trim()))
invlog.setBackground(Color.orange);
invlog.setLocation(250,150);
invlog.setSize(300,100);
cancel.setEnabled(false);
ok.setEnabled(false);
check.setEnabled(false);
invlog.setVisible(true);
break;
else
if (s3.length()<6)
less.setBackground(Color.orange);
less.setLocation(250,150);
less.setSize(300,100);
ok.setEnabled(false);
cancel.setEnabled(false);
check.setEnabled(false);
less.setVisible(true);
else if(!(s3.equals(s4)))
mismat.setBackground(Color.orange);
mismat.setLocation(250,150);
mismat.setSize(300,100);
ok.setEnabled(false);
cancel.setEnabled(false);
check.setEnabled(false);
mismat.setVisible(true);
else
db.s1.execute("insert into User values("+x+",'"+s2+"','"+s3+"',"+t+")");
acucreat.setBackground(Color.orange);
acucreat.setLocation(250,150);
acucreat.setSize(300,100);
regis.setVisible(false);
acucreat.setVisible(true);
}//else
}//while
} //try
catch(Exception e1)
// e1.printStackTrace();
if (ae.getSource()==cancel)
regis.setVisible(false);
if (ae.getSource()==vok)
ok.setEnabled(true);
cancel.setEnabled(true);
check.setEnabled(true);
valid.setVisible(false);
if (ae.getSource()==iok)
ok.setEnabled(true);
cancel.setEnabled(true);
check.setEnabled(true);
invlog.setVisible(false);
if (ae.getSource()==lok)
less.setVisible(false);
cancel.setEnabled(true);
ok.setEnabled(true);
check.setEnabled(true);
if (ae.getSource()==mok)
mismat.setVisible(false);
cancel.setEnabled(true);
ok.setEnabled(true);
check.setEnabled(true);
if (ae.getSource()==sok)
acucreat.setVisible(false);
ok.setEnabled(false);
newu.setEnabled(true);
regis.setVisible(true);
public static void main(String args[])
new Register();
-----------DBConnect.java------------------------------------
import java.sql.*;
public class DBconnect
Statement s,s1;
Connection c;
public DBconnect()
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("jdbc:odbc:Sonal");
s=c.createStatement();
s1=c.createStatement();
catch(Exception e)
e.printStackTrace();
----------Login.java----------------
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Login implements ActionListener
Frame log;
Label login,pass;
TextField loginf,passf;
Button ok,cancel;
Dialog invalid;
Button iok;
Register reg;
DBconnect db;
Main m;
Login()
db=new DBconnect();
log=new Frame();
log.setLocation(250,210);
login=new Label("Login :");
pass=new Label("Password :");
loginf=new TextField(20);
passf=new TextField(20);
passf.setEchoChar('*');
ok=new Button("OK");
// newu=new Button("New User");
cancel=new Button("CANCEL");
iok=new Button(" OK ");
invalid=new Dialog(log,"Invalid User!");
//log.setBackground(Color.cyan);
//log.setForeground(Color.black);
log.setLayout(null);
// iok.setBackground(Color.gray);
invalid.setLayout(new FlowLayout());
login.setBounds(35,50,70,25); //(left,top,width,hight)
loginf.setBounds(105,50,100,25);
pass.setBounds(35,85,70,25);
passf.setBounds(105,85,70,25);
ok.setBounds(55,130,70,25);
// newu.setBounds(85,120,80,25);
cancel.setBounds(145,130,70,25);
log.add(login);
log.add(loginf);
log.add(pass);
log.add(passf);
log.add(ok);
// log.add(newu);
log.add(cancel);
invalid.add(iok);//,BorderLayout.CENTER);
ok.addActionListener(this);
// newu.addActionListener(this);
cancel.addActionListener(this);
iok.addActionListener(this);
log.setSize(300,170);
log.setVisible(true);
public void actionPerformed(ActionEvent a)
if(a.getSource()==ok)
try{
String l=loginf.getText();
String p=passf.getText();
ResultSet rs=db.s.executeQuery("select * from List");
while(rs.next())
if(l.equals(rs.getString(2).trim())&& p.equals(rs.getString(3).trim()))
String tp=rs.getString(4).trim();
int tp1=Integer.parseInt(tp);
log.setVisible(false);
if(tp1==1)
m=new Main();
// m.List.setEnabled(true);
else
m=new Main();
m.List.setEnabled(false);
break;
else
invalid.setBackground(Color.orange);
invalid.setSize(300,100);
invalid.setLocation(250,210);
cancel.setEnabled(false);
ok.setEnabled(false);
invalid.setVisible(true);
}catch(Exception e1)
e1.printStackTrace();
if (a.getSource()==cancel)
log.setVisible(false);
if (a.getSource()==iok)
invalid.setVisible(false);
loginf.setText("");
passf.setText("");
cancel.setEnabled(true);
ok.setEnabled(true);
public static void main(String[] args)
new Login();
-------------inquiry.java---------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
public class Inquiry implements ActionListener
Frame inqry;
Label name,addr;
TextField namef,addrf;
Button ok,cancel,dok;
Dialog invalid;
Frame result; //Result of the inquiry....
Label lrname,lraddr,lward,lrdate,lcdate;
TextField rname,raddr,ward,rdate,cdate;
Date d;
DateFormat df;
Button rok,rcancel;
Dialog success;
Button rdok;
DBconnect db;
Inquiry()
db=new DBconnect();
inqry=new Frame("Inquiry Form");
inqry.setLayout(null);
inqry.setBackground(Color.cyan);
name=new Label(" NAME ");
addr=new Label("ADDRESS");
namef=new TextField(20);
addrf=new TextField(20);
ok=new Button("OK");
cancel=new Button("CANCEL");
dok=new Button("OK");
invalid=new Dialog(inqry,"Invalid Name or Address !");
invalid.setSize(300,100);
invalid.setLocation(300,180);
invalid.setBackground(Color.orange);
invalid.setLayout(new FlowLayout());
result=new Frame(" INQUIRY RESULT "); //Result Window......
result.setLayout(null);
result.setBackground(Color.cyan);
lcdate=new Label(" DATE ");
lrname=new Label(" NAME ");
lraddr=new Label(" ADDRESS ");
lward=new Label(" WARD ");
lrdate=new Label(" ADMIT-DATE ");
cdate=new TextField(10);
rname=new TextField(20);
rname.setEnabled(false);
raddr=new TextField(20);
raddr.setEnabled(false);
ward=new TextField(20);
ward.setEnabled(false);
rdate=new TextField(10);
rdate.setEnabled(false);
cdate=new TextField(20);
d=new Date();
df=DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.KOREA);
cdate.setText(df.format(d));
cdate.setEnabled(false);
rok=new Button(" OK ");
rcancel=new Button("CANCEL");
name.setBounds(40,50,50,25);
namef.setBounds(120,50,130,25);
addr.setBounds(40,100,60,25);
addrf.setBounds(120,100,80,25);
ok.setBounds(60,145,70,25);
cancel.setBounds(140,145,70,25);
lcdate.setBounds(200,50,60,25); //Result Window......
cdate.setBounds(270,50,80,25);
lrname.setBounds(35,85,70,25);
rname.setBounds(140,85,180,25);
lraddr.setBounds(35,120,80,25);
raddr.setBounds(140,120,100,25);
lward.setBounds(35,155,80,25);
ward.setBounds(140,155,100,25);
lrdate.setBounds(30,190,80,25);
rdate.setBounds(140,190,80,25);
rok.setBounds(70,240,70,25);
rcancel.setBounds(170,240,70,25);
inqry.add(name);
inqry.add(namef);
inqry.add(addr);
inqry.add(addrf);
inqry.add(ok);
inqry.add(cancel);
invalid.add(dok);
result.add(lcdate); //Result Window......
result.add(cdate);
result.add(lrname);
result.add(rname);
result.add(lraddr);
result.add(raddr);
result.add(lward);
result.add(ward);
result.add(lrdate);
result.add(rdate);
result.add(rok);
result.add(rcancel);
ok.addActionListener(this);
cancel.addActionListener(this);
dok.addActionListener(this);
rok.addActionListener(this); //Result Window......
rcancel.addActionListener(this);
inqry.setSize(280,180);
inqry.setLocation(300,180);
inqry.setVisible(true);
result.setSize(400,280); //Result Window......
result.setLocation(200,150);
result.setVisible(false);
public void actionPerformed(ActionEvent ae)
if(ae.getSource()==ok)
try
String nm=namef.getText();
String ad=addrf.getText();
inqry.setVisible(false);
ResultSet rs=db.s.executeQuery("select * from Billinformation");
while(rs.next())
String nm1=rs.getString(2).trim();
String ad1=rs.getString(3).trim();
int k=0;
if((nm1.equals(nm))&&(ad1.equals(ad)))
String adm=rs.getString(5).trim();
String wr=rs.getString(6).trim();
String bd=rs.getString(8).trim();
String wrb=wr+"-"+bd;
result.setVisible(true);
rname.setText(nm1);
raddr.setText(ad1);
ward.setText(wrb);
rdate.setText(adm);
k=1;
break;
}//if
else if(k==1)
invalid.setVisible(true);
}//while
}//try
catch(Exception e)
e.printStackTrace();
} //getsource ==ok
if(ae.getSource()==cancel)
inqry.setVisible(false);
if(ae.getSource()==rok) //Result Window......
namef.setText("");
addrf.setText("");
result.setVisible(false);
inqry.setVisible(true);
if(ae.getSource()==rcancel)
result.setVisible(false);
if(ae.getSource()==dok)
namef.setText("");
addrf.setText("");
invalid.setVisible(false);
inqry.setVisible(true);
public static void main(String args[])
new Inquiry();
PLease Help me !!
I need this urgently.can you explain what your program tries to do... and
at where it went wrong..Sir,
We are trying to make an project where we can make a person register in our data base & after which he/she can search for other user.
The logged in user can modify his/her own data but can view other ppl's data.
We are in a phase of registering the user & that's where we are stuck. The problem is that after the login screen when we hit register (OK- button) the data are not getting entered in the data base.
Can u please help me??
I am using "jdk1.3' - studnet's edition.
I am waiting for your reply.
Thanks in advance & yr interest. -
Null Pointer Exception and Illegal Arguement when ran with Wireless Toolkit
The following code throws a null pointer exception after it tried to initialize the textBox. I am not sure if there is something I am not importing, or if it's just because I'm sick and my head is cloudy. :-}.
I am using Wireless Toolkit 2.2 and Java 5.0
Anyhelp would be appreicated. Thank You.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TacticalTestMain extends MIDlet implements CommandListener {
private Display display;
private Form formMain;
private TextBox tbHelp; //Text Box for help Command
private Command cmExit; //A button to exit midLet
private Command cmBack; //Go "back" to main form
private Command cmHelp; //Ask for help
public TacticalTestMain()
display = Display.getDisplay(this);
formMain = new Form("Tactical Survey Program");
cmExit = new Command("Exit", Command.SCREEN, 1);
cmBack = new Command("Back", Command.BACK, 1);
cmHelp = new Command("Help", Command.HELP, 1);
formMain.addCommand(cmExit);
formMain.addCommand(cmBack);
formMain.addCommand(cmHelp);
formMain.setCommandListener(this);
System.out.println("Before Create Text Box");
//Create the help textBox with a max of 25 charecters
tbHelp = new TextBox("HeLp", "You can press the back button", 25, 0);
tbHelp.addCommand(cmBack);
tbHelp.setCommandListener(this);
System.out.println("AfTER Create Text Box");
}//end constructor
public void startApp()
System.out.println("Inside StartApp()");
display.setCurrent(formMain);
}//end startApp()
public void pauseApp()
}//end pauseApp
public void destroyApp(boolean unconditional)
notifyDestroyed();
}//end destroyApp()
//Check to see if the exit button was selected
public void commandAction(Command c, Displayable d)
System.out.println("Inside commandAction()");
String sLabel = c.getLabel();
if(sLabel.equals("Exit"))
destroyApp(true);
Errors from the KToolbar:
Running with storage root DefaultColorPhone
Before Create Text Box
Unable to create MIDlet TacticalTestMain
java.lang.IllegalArgumentException
at javax.microedition.lcdui.TextField.setChars(+105)
at javax.microedition.lcdui.TextField.setString(+27)
at javax.microedition.lcdui.TextField.<init>(+134)
at javax.microedition.lcdui.TextBox.<init>(+74)
at TacticalTestMain.<init>(+134)
at java.lang.Class.runCustomCode(+0)
at com.sun.midp.midlet.MIDletState.createMIDlet(+19)
at com.sun.midp.midlet.Selector.run(+22)
Execution completed.
743701 bytecodes executed
23 thread switches
741 classes in the system (including system classes)
4071 dynamic objects allocated (120440 bytes)
2 garbage collections (91412 bytes collected)Hi zoya,
Here is the problem:
tbHelp = new TextBox("HeLp", "You can press the back button", 25, 0);
This line declares a maximum textbox size of 25 but in reality he is declaring a textbox of size 29.
Thats why it is throwing the illegal argument.
happy coding :)
Maybe you are looking for
-
Why doesn't the dictionary spell colour correctly?
I'm English, I bought my iPhone in England, it's set to English (British) But it STILL tells me there is no U in colour or rumor or honor oar anything else. It tells me I spell everything incorrectly like aluminium just because I put all the letters
-
How can I create a PDF with flowing columns?
I need to write a script that takes my input data and creates a PDF file that has flowing columns - that is to say, where I give it a long chunk of text and that text is automatically broken into two columns where the text flows down column 1 and whe
-
Is there a way to dynamically figure out the FIRSTROW & LASTROW using Bulk Insert?
I noticed most of my files follow a certain convention, so I can use Bulk Insert with this: FIRSTROW = 2, LASTROW = 224 However a few files have many more records. I'd like SQL Server to dynamically figure out the first and last rows with data, but
-
"I am doing a data acquisition project using a 16 channel N.I. series 6020E card where I want to capture respective current and voltage sinusoidal signals. I am planning on capturing four pairs of matching current and voltage signals. I planned on ta
-
Replacing sap isu tax code with sap r/3 while transferring documents
we are using different tax code in SAP ISU then the one used in SAP CORPORATE..is there any way we can replace the tax code used in SAP ISU with the one used SAP R 3 while transferring the documents through ALE we have used sabstituation rules to pop