Problem with Point-Array
I made the following method:
Point[] makeLine (int length)
Point[] newLine = new Point[length];
for (int i = 0; i < newLine.length; i++)
newLine.x = i;
newLine[i].y = (int)Math.round(Math.random()*5+1);
return newLine;
to make a Line that randomly jumps and stuff.
Compiles fine, but when i want to run it i get a NullPointerExeption at
newLine.x = i;
when i comment that one out i get the same error on the line after .
I absolutely cant find the mistake, can anybody help me please?
Thanks in advance
You have defined an array, but you need to put objects into the array. i.e. when an array is created, every value is initlaised to null. The OO way to do this is
newLine[i] = new Point(i, (int) (Math.random()*5+1));Note round may not be the best choice as this will round down/up 50% of the time. This means each value does not have an equal chance of occuring.
Similar Messages
-
Problem with an array (Array index out of bounds)
Hey guys, i have a problem with an array, i just want to print a few things but it won't let me because of this error, here's my code
public static void MosDat()
int i;
for(i=0 ; i<n ; i++);
Client [ i ].print1();
Client [ i ].print2();
return;
}//MosDat
where "n" is a global variable, and client is .
I pretty much know how it woks, so i tried it like this and gave "n" the value of "1":
public static void MosDat()
int i;
for(i=0 ; i<n ; i++);
Client [ 0 ].print1();
Client [ 0 ].print2();
return;
}//MosDat
the printing methods i created worked prefectly when i tried it like that... so i really don't know where the problem could be... thanks anyone who can help me.for(i=0 ; i < n ; i++);I spy with my little eye,
one semicolon too many.Well-spotted. ;-)Practicing on those weird question marks is my secret training. -
Performance Problems with intrinsic array multiplikation in Fortran with Su
Hello,
I found a serious performance problem in my application with intrinsic array multiplikation. Therefore I wrote a small test program to check if this a general problem or only exists in my code.
The test program (as seen below) was compiled with Sunstudio12 und Solaris 5.10 on an 64 bit Amd Opteron Machine. First with high optimization (f95 -fast -g), and the second time with out optimization (f95 -O0 -g). In both cases the intrinsic array mupltiplication had a lot of tlb and L2 cache misses (I made some test with the performance analyzer) which caused a huge increase in computation time compared to the explicit loop. In the ideal case the compiler should create the nested loops from the intrinsic statement and both functions should use exactly the same computing time.
I also tried compiling with Studio11, the problem also occurs there. Maybe its a compiler bug but I'm not sure.
Greetings
Michael Kroeger
program test
!Test zur Ausfuehrung einer einfachen array Multiplikation
implicit none
real,dimension(:,:,:),pointer::check1,check2
integer i,j,k,ni,nj,nk,status
ni=1000
nj=1000
nk=100
allocate(check1(0:ni,0:nj,0:nk),STAT=status)
write(*,*)status
allocate(check2(0:ni,0:nj,0:nk),STAT=status)
write(*,*)status
check1(i,j,k)=25
check2(i,j,k)=25
call intrinsic_f(check1)
call withloop(check2,i,j,k)
deallocate(check1,check2)
contains
subroutine intrinsic_f(check1)
real, dimension(:,:,:),pointer::check1
check1=check1*5
end subroutine intrinsic_f
subroutine withloop(check2,ni,nj,nk)
real, dimension(:,:,:),pointer::check2
integer i,j,k,nk,nj,ni
do k=0,nk
do j=0,nj
do i=0,ni
check2(i,j,k)=check2(i,j,k)*5
enddo
enddo
enddo
end subroutine withloop
end programI will try the large pages, but what me puzzles is, that the intrinsic function has cache misses, but the loop function has not. All documentation says, that the compiler would expand the intrinsic function into 3 nested loops, so that both functions should be essential the same (and the compiler says it has created 3 loops from the intrinsic). Since they are not the same, this is a severe problem.
I have a fairly large code for high performance simulations, and this intrinsic functions are a significant bottle neck. If it is not a compiler bug, I would have to rewrite all intrinsic functions into loops. -
I got a problem with cloning a Point[] Array.
for example i have 2 Point-Arrays declared as Membervariables:
Point[] array1;
Point[] array2;then in the constructor i filled array1 with random Point Objects
and then
array2 = (Point[])(array1.clone());then i, for example, add 5 to the x-coordinate of every Point in array2.
for (int i = 0; i < array2.length; i++)
array2.x += 5;
But array1's Point objects are also changed when i do that!
Shouldnt clone copy the whole array and leave no connection between them?
Thanks in advanceso i made a method copyArray where every point object's x and y value is copied into the new Array's new Point Object, but as it seems that isnt where the error comes from.
(That method works fine, the arrays are identical after that, but shouldnt reference to the same chunk of memory, right?)
then i run the following method on array2
array2 = (Point[])addFive(array2);
Point[] addFive(Point[] array)
array[0].x += 5;
return line;
}Hence array2[0].x is instead of, e.g., zero 5
But array1[0] .x is 5 intead of 0 too!
Where's the mistake, where's the reference left? =X (and how do i fix it? :)) -
Problems with an array (attachMovie)
I've created a 20 x 20 grid of objects (openCircles). They're set to 'alpha = 0', then 'alpha = 100' on rollover. This works for all of them except for the final one at the coordinate T,20 in the bottom right corner, as I'm not able to rollover over it. To test whether or not they all existed, I set them all to an initial value of 'alpha = 100' and they did all appear, but I'm still unable to rollover the one at T20.
The other problem is that when an 'openCircle' is clicked, a 'filledCircle' (set up as another grid of invisible objects in the same place) is supposed to appear in its place. That doesn't happen. All of the objects are created and exist, using attachMovie, so it's maybe due to some logical error. See code:-
I'd be grateful for any help. Many thanks.
stop();
//The purpose of this experiment is to locate a trap of oil. Only 30 exploration holes are allowed.
//Use the grid coordinate to locate the borehole and then plot the depth
//Drilled is set to false in the 1st(previous) frame
//Rolling over a grid coordinate will reveal a borehole (open circle).
//Click on the borehole (open circle) to start drilling
//open circle will be removed
//drilled is set to true for that coordinate
//filled circle will appear in its place
//set up variables for grid array of open circles (undrilled) and closed circles (drilled)
var spacing:Number = 5.75;
var cols:Number = 20; // number of columns in grid
var rows:Number = 20; // number of rows in grid
var leftMargin:Number = 154;
var topMargin:Number = 169;
var currentRow:Number = 0;
var currentCol:Number = 0;
for (i=1; i<=rows; i++) {
for (j=1; j<=cols; j++) {
current = attachMovie("openCircle_mc", "openCircle_mc"+i+"_"+j,getNextHighestDepth());
current._x = leftMargin + ((i-1) * (spacing + current._width));
current._y = topMargin + ((j-1) * (spacing + current._height));
current2 = attachMovie("filledCircle_mc", "filledCircle_mc"+i+"_"+j, getNextHighestDepth());
current2._x = leftMargin + ((i-1) * (spacing + current2._width));
current2._y = topMargin + ((j-1) * (spacing + current2._height));
//open circle initially invisible, then visible on rollOver
current._alpha = 0;
//filled circles initially invisible
currentCol2=(current2._x-leftMargin)/(spacing + current2._width);
currentRow2=(current2._y-topMargin)/(spacing + current2._height);
if (drilled[currentCol,currentRow]==true){
current2._alpha = 100;
}else{
current2._alpha=0;
//open circle visible on rollover
current.onRollOver = function() {
this._alpha = 100;
currentCol=(this._x-leftMargin)/(spacing + current._width);
trace("current column ="+currentCol);
currentRow=(this._y-topMargin)/(spacing + current._height);
trace("current row ="+currentRow);
if (drilled[currentCol,currentRow]==false){
trace("Click on the grid point to drill at "+rowLabel[currentRow]+","+colLabel[currentCol]);
}else{
trace("Click on the grid point to review the core at "+rowLabel[currentRow]+","+colLabel[currentCol]);
} //end 'if-else'
//open circle invisible on rollout
current.onRollOut = function() {
this._alpha = 0;
trace("No grid point selected")
//click on open circle - variable drilled becomes true
current.onRelease=function(){
drilled[currentCol,currentRow]=true;
trace(drilled[currentCol,currentRow]);
this.removeMovieClip();
This is an image of the grid showing an 'openCircle' visible when rolled overThanks for the explanation. That was very helpful.
However, I am having problems with the variables. I did as you suggested though and extended the (grid) layer, but had to create a separate keyframe for the code layer, as that code had to execute first before moving into the next frame. See below (I've also attached the fla, but if you need any more information, please let me know):
In frame 2 of the animation, if an open circle mc is clicked, that mc is deactivated (removed), drilled becomes true for that coordinate, a filled circle becomes visible in its place and you enter another frame(3) (this is currently just a test frame), to later be used to implement the drilling animation for a clicked coordinate.
It all seems to be working as it should, until the open circle is clicked and you enter frame 3. See below:
All the instances of the openCircle mc's are still active in frame 3, so I guess I need to use removeMovieClip(). I know how to do that for a single instance, but howdo I execute that if they're in an array?
I also don't want any instances of the filledCircles from frame 2 to be visible in frame 3. I'm not sure how to hide them temporarily in frame 3 and then have them visible again in frame 2?
When I go back to frame 2 (using a back button), all of the filled circles in the array are visible, whereas only the ones that have been previously clicked (drilled = true) should be visible. However, when I return to frame 2 and do a trace to find out which coordinates are set to true/false, it seems that a whole row is now set to (drilled = true), whereas it should just be a single coordinate set to true. Oddly enough, the variable seems to working properly in frame 2 when the code is first executed, but then when I go to frame 3 and then re enter frame 2, it's not working as it should do. Below is the trace code that I've used:
if (drilled[currentCol,currentRow] == false) {
trace("Click on the grid point to drill at " + rowLabel[currentRow] + "," + colLabel[currentCol]);
} else {
trace("Click on the grid point to review the core at " + rowLabel[currentRow] + "," + colLabel[currentCol]);
If you could help, I'd be very grateful! Very many thanks.
http://synergese.co.uk/boreholes15.fla
Message was edited by: Pippa01
Sorry, Although the original question was correct, I've just unmarked it as correct. Maybe, I should have started it as a new thread? -
Problem with building array inside a case statement
I have a problem with my build array.
Iam trying to construct a build array when ever I see a new element in my parent array during run time.
Using shift registers, search array and If- case structure, inside a while loop. Iam implementing this logic (I dont want to use Event structure).
Iam able to achieve most part of it, but have a problem with the first element. Except the first element of my parrent array, every thing is appending in to the build array. Can any one look at my vi and suggest me what Iam doing wrong here.
Thank you
Attachments:
debug.vi 12 KBI think you need to replace the tunnels (carrying the array) in the for loop with a shift register.
Lynn -
i have problem with my program i implement saveing method
but when i open file( game.txt) it does not update my board it return same postion every time i same game
chess class Jframe(Jfilechooser)(call an board array)---->
Gui Japplet class( call and board array------------>
Board(class Jpanel have board array)
it does not update borad array
it just call it once in start and return the same value every time
classChess(){
ChessPlayer java = new ChessPlayer();
public void saveData()
File file = null;
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File("."));
fc.setDialogTitle("Save Text As...");
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{ file = fc.getSelectedFile();
try
{ PrintWriter out =
new PrintWriter(
new BufferedWriter(
new FileWriter(file)));
//while for all the moves in the array>
for (int i=0;i<120;i++)
out.println( java.saveDAta(i));
out.println("\n");
out.close();
catch (IOException e) {
// Some error has occured while trying to read the file.
// Show an error message.
JOptionPane.showMessageDialog(this,
"Sorry, some error occurred:\n" + e.getMessage());}
public static void main(String[] args) {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
JFrame frame = new ChessMan();
Container content = frame.getContentPane();
ChessMan f = new ChessMan();
//japplet
ChessPlayer javaAppletication = new ChessPlayer();
javaAppletication.init();
javaAppletication.start();
}Gui
[Gui]
class Gui{
int [] board = new int [120];
int [] boardcolor = new int [120];
Board check = new Board(this,false);
{public void init()
{ // Create new Border
contentPane = getContentPane();
bboard = new Board(this,false);
public String saveDAta(int i)
String l=check. save(i);
return (l);
and finally board Jpanel
class Board extends JPanel
{public Board (JApplet useapplet,boolean bool) {
setup();
{ public String save(int i)
{ String l;
if (color==1)
{System.out.println("notpossible");}
l = board[i]+"$"+boardColor;
return l;
thanks guysMy Jframe
public class ChessMan extends JFrame implements ActionListener, WindowListener {
JMenuItem saveItem, loadItem, copyItem, pasteItem;
JMenu fileMenu, editMenu;
JMenuBar bar;
ChessPlayer java = new ChessPlayer();
public ChessMan() { setTitle("CHESS PLAYER GAME" );
setSize(200,300);
System.out.println("\n"); }
addWindowListener(new java.awt.event.WindowAdapter()
{ public void windowClosing(java.awt.event.WindowEvent e)
{ System.exit(0); } });
JMenu fileMenu = new JMenu("File");
saveItem = new JMenuItem("Save");
saveItem.setActionCommand("save");
saveItem.setAccelerator( KeyStroke.getKeyStroke("ctrl S"));
saveItem.addActionListener(this);
fileMenu.add(saveItem);
loadItem = new JMenuItem("Load");
loadItem.setActionCommand("load");
loadItem.setAccelerator( KeyStroke.getKeyStroke("ctrl L"));
loadItem.addActionListener(this);
fileMenu.add(loadItem);
JMenu editMenu = new JMenu("About");
copyItem = new JMenuItem("Help");
copyItem.setActionCommand("Help");
copyItem.setAccelerator( KeyStroke.getKeyStroke("ctrl H"));
copyItem.addActionListener(this);
editMenu.add(copyItem);
pasteItem = new JMenuItem("Exit");
pasteItem.setActionCommand("Exit");
pasteItem.setAccelerator( KeyStroke.getKeyStroke("ctrl E"));
pasteItem.addActionListener(this);
editMenu.add(pasteItem);
JMenuBar bar = new JMenuBar();
bar.add(fileMenu);
bar.add(editMenu);
setJMenuBar(bar);
setVisible(true);
setLocation(0,0);
public void actionPerformed(ActionEvent e) {
JMenuItem item = (JMenuItem)e.getSource();
String ac = item.getActionCommand();
System.out.println("ac = "+ ac);
// you can use action commands to track menu item events
if(ac.equals("save"))
{System.out.println("ac.equals(\"save\") = "+ ac.equals("save"));
saveData();}
if(ac.equals("load"))
{System.out.println("ac.equals(\"load\") = "+ ac.equals("load"));
loadingData();}
if(ac.equals("Help"))
{System.out.println("ac.equals(\"load\") = "+ ac.equals("Help"));
if(ac.equals("Exit"))
{System.out.println("ac.equals(\"load\") = "+ ac.equals("Exit"));
Exit();}
// the event origin
if(item == saveItem)
System.out.println("item = "+ item.toString().substring
(item.toString().indexOf("text=") + 5, item.toString().lastIndexOf("]")));
if(item == loadItem)
System.out.println("item = "+ item);
// System.out.print( java.saveDAta());
public void saveData()
File file = null;
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File("."));
fc.setDialogTitle("Save Text As...");
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{ file = fc.getSelectedFile();
try
{ PrintWriter out =
new PrintWriter(
new BufferedWriter(
new FileWriter(file)));
//while for all the moves in the array>
for (int i=0;i<120;i++)
out.println( java.saveDAta(i));
out.println("\n");
out.close();
catch (IOException e) {
// Some error has occured while trying to read the file.
// Show an error message.
JOptionPane.showMessageDialog(this,
"Sorry, some error occurred:\n" + e.getMessage());}
public void loadingData()
File loadfile = null;
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("OpenFile...");
fc.setCurrentDirectory(new File("."));
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{ loadfile = fc.getSelectedFile();
try
{ PrintWriter out =
new PrintWriter(
new BufferedWriter(
new FileWriter(loadfile)));
//while for all the moves in the array>
out.println("�����������������");
out.println("\n");
out.close();
catch (IOException e) {
// Some error has occured while trying to read the file.
// Show an error message.
JOptionPane.showMessageDialog(this,
"Sorry, some error occurred:\n" + e.getMessage());}
public void Exit()
System.exit(0);
public static void main(String[] args) {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
JFrame frame = new ChessMan();
Container content = frame.getContentPane();
ChessMan f = new ChessMan();
f.setLocation(300,300);
f.show();
ImageIcon customImageIcon = new ImageIcon("ac516.gif");
Image customImage = customImageIcon.getImage();
frame.setIconImage(customImage);
//japplet
ChessPlayer javaAppletication = new ChessPlayer();
// i could not put my constructor here <Static>
javaAppletication.init();
javaAppletication.start();
// for(int i=0; i < .length(); i++)
content.add(javaAppletication, BorderLayout.CENTER);
frame.getContentPane();
javaAppletication.setBackground (Color.black);
frame.setVisible(true);
frame.show();
frame.pack(); // invokes getPreferredSize()
// invokes paint();
public void windowOpened(WindowEvent e) {
fileMenu.doClick();
public void windowClosing(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
My Japplet Class
class ChessPlayer extends JApplet
implements ActionListener,MouseListener
int c;
//Reference for new Board
Board bboard;
//Reference for Button
JButton newgame,undo,onePlayer,TwoPlayer,NormalPieceSet,
FuunyPieceSet,startButton,stopButton;
//Reference for Label
JLabel message;
//Reference for new Panel
JPanel buttonpanel2,buttonpanel,messagepanel,buttonpane;
//Initilize the Applet
DemoAnimation Demo;
Container contentPane;
Board check = new Board(this,false);
int [] board = new int [120];
int [] boardcolor = new int [120];
public void init()
// Create new Border
contentPane = getContentPane();
check = new Board(this,false);
bboard = new Board(this,false);
bboard.setPreferredSize(new Dimension(500,400));
bboard.setBorder(BorderFactory.createLineBorder( Color.red ) );
contentPane.add(bboard);
final ImageIcon image = new ImageIcon("ac516.gif");
bboard.addMouseListener(this);
bboard.setBackground (Color.black);
BorderLayout text=new BorderLayout();
Demo = new DemoAnimation( this );
Demo.setPreferredSize(new Dimension(160, 500));
contentPane.add(Demo);
// Set Background Black
contentPane.setBackground (Color.black);
contentPane.setLayout (new BorderLayout (50,50));
// set new Font "TimesRoman"
Font Text= new Font("TimesRoman", Font.BOLD,15);
//panel to keep buttons together
buttonpanel=new JPanel();
buttonpanel.setLayout(new GridLayout(1,2,6,0));
buttonpanel.add(newgame=new JButton("new game",image));
newgame.addActionListener(this);
buttonpanel.add(undo=new JButton("undo"));
undo.addActionListener(this);
// Create new Choice Panel
buttonpanel2 = new JPanel();
buttonpanel2.setLayout(new GridLayout(6,1,0,10));
buttonpanel2.add(onePlayer=new JButton("Change Colour"));
onePlayer.addActionListener(this);
buttonpanel2.add(TwoPlayer=new JButton("Statistic"));
TwoPlayer.addActionListener(this);
buttonpanel2.add(NormalPieceSet=new JButton("Quit"));
NormalPieceSet.addActionListener(this);
buttonpanel2.add(FuunyPieceSet=new JButton("Change Piece"));
FuunyPieceSet.addActionListener(this);
buttonpanel2.add(startButton = new JButton("Start Animation"));
startButton.addActionListener(this);
buttonpanel2.add(stopButton = new JButton("Stop Animation"));
stopButton.addActionListener(this);
contentPane.add(BorderLayout.WEST, demopanel);
// Set Font For Text Message
setFont(Text);
messagepanel=new JPanel();
messagepanel.setBorder(BorderFactory.createLineBorder( Color.red ) );
messagepanel.setBackground(Color.black);
// essagepanel.setLayout(new GridLayout(1,1));
// Create new Label
messagepanel.add(message = new JLabel());
setMessage("Welcome");
// Postion panels in Layout
contentPane.add("North",buttonpanel);
contentPane.add("East",buttonpanel2);
contentPane.add ("South",messagepanel);
contentPane.add ("Center",bboard);
contentPane.add("West",Demo);
public void mouseReleased(java.awt.event.MouseEvent e)
{ statuseChange();}
public void mouseClicked(java.awt.event.MouseEvent e)
public void mouseEntered(java.awt.event.MouseEvent e) {
public void mouseExited(java.awt.event.MouseEvent e) {
public void mouseMoved(java.awt.event.MouseEvent e) {
statuseChange();
public void mousePressed(java.awt.event.MouseEvent e)
{statuseChange();
public void actionPerformed(ActionEvent e)
Object source=e.getSource();
if (source == newgame)
{ bboard.newgame();
yellow();
setMessage("try again");
pause(100);
c=add(c);
else if (source==undo)
yellow();
bboard.undo();
setMessage("Undo");
else if (source== TwoPlayer )
//bboard.setup();
yellow();
setMessage("Starting new Game");
setMessage("Change Color");
else if(source == FuunyPieceSet)
{yellow();
setMessage("game played::" +c);
bboard.PieceChange();
else if(source == NormalPieceSet)
{yellow();
setMessage("GOODBYE");
destroy();
else if(source == startButton)
{yellow();
setMessage("Start Animation");
Demo.start();
else if(source == stopButton)
{yellow();
setMessage("Stop Animation");
Demo.stop();
else if(source == onePlayer)
{setMessage("");
bboard.changePiece();
setMessage("Change Color");
public void statuseChange()
switch (bboard.gameStatus())
case 1:
red();
setMessage("White won");
break;
case 2:
red();
setMessage("Black won");
break;
case 3:
red();
setMessage("DRAW");
Demo.changeAnimation(2);
break;
case 4:
white();
setMessage("White Turn");
Demo.changeAnimation(1);
break;
case 5:
green();
setMessage("Black turn");
Demo.changeAnimation(3);
break;
case 6:
red();
setMessage(" Check");
Demo.changeAnimation(4);
break;
case 7:
red();
setMessage("Check");
Demo.changeAnimation(4);
break;
case 8:
yellow();
setMessage("I Hope you enjoyed it");
public String saveDAta(int i)
String l=check.save(i);
return (l);
public void LoadData(String load)
public void setMessage(String s)
/*The string s will be shown to the user.*/
Font Text= new Font("Courier", Font.BOLD,30);
message.setText(s);
message.setFont(Text);
public void white()
{ message.setForeground(Color.white);}
public void green()
message.setForeground(Color.green);
public void red()
message.setForeground(Color.red);
public void yellow()
message.setForeground(Color.yellow);
// pause method
void pause(int time)
try {Thread.sleep(time);
} catch (InterruptedException e)
// Create new inset Object
public Insets getInsets()
return new Insets(50,220,150,200);
public void destroy()
contentPane.remove(buttonpanel2);
contentPane.remove(buttonpanel);
contentPane.remove(bboard);
contentPane.repaint();
Demo.start();
public int add(int x)
{ int b=x+1;
return b;
}tanx man i dont the other two because they are to long
my is when i open jframe
i think Japplet and Jframe can not commuinicate to each other -
Aperture performance problems with Lacie array
I have an iMac with 32GB memory and, due to space requirements, an external LaCie 2Big2 disk array, with 2 x 6GB disks in a RAID-1 (mirroring) configuration and attached via USB3.
This has in the past worked extremely quickly. The iMac has a 1TB Fusion drive.
In recent weeks something has changed. It now takes about a minute for Aperture to start up and open a library of photographs. It used to take 3-4 seconds. In the meantime I get a spinning beachball, but can happily use other applications. The manager software for the array says it's working fine. I am more than a little puzzled and frustrated.
I'd appreciate suggestions on how to track down the root cause of the problem, and then how to fix it!
I am on the latest version of Mavericks, with no outstanding software updates.Dear Leonie
Thank you very much for your reply. Here are the answers:
What exactly has changed?
I don't know exactly. Something changes every day on a working system! However I have not installed any new software or hardware.
Did this start after a software update?
Not that I am aware of. In the last 30 days my only software updates have been Epson driver software, a digital RAW compatibility update to Aperture and a Safari update. The Aperture update does not apply to any of the equipment I have.
Or after you moved the library to the Lacie Array?
No. I should have been clearer. The Lacie array was installed several months ago and has been working well.
Did you import new photos?
I import new photos almost every day. However I have several photo libraries and this problem occurs across all of them, even the ones unchanged for months or years.
Did you enable Photo Stream?
No
Does Aperture launch more quickly, if you hold down the Shift key while Aperture is launching? This will defer the generation of previews.
If Aperture is launching more quickly this way, you may have imported a corrupted video or image file, that you need to find and to remove.
No. I have just tested this.
Other possible reasons:
Check the file system on your array. If the filesystem is not MacOS Extended (Journaled), you may have problems with ambigious filenames.
The file system is MacOS Extended (Journaled)
Do you have Photo Stream enabled? Aperture may be hanging while trying to load photos from My Photo Stream.
No, Photo Stream is not enabled.
Thank you again for your help. -
Help: Problem With Seperate Arrays Overwriting Each Other!
Hi,
I have this function that randomly allocates free time to coursework blocks. This method works because I have tested numerous times and it always prints of different allocations of time every time its called.
The problem that I have is that I have this method that called this method twice to store each different call within a separate ArrayList.
When I make the first call the block are assigned to the array fine. But when I called it a second time to store the next result within a separate Array the first Array result are overwritten . Any body have any idea why this is happening, I have asked numerous friends and even my supervisor and he can't find anything wrong with it. Any help would be very helpful...
Code:
public ArrayList<CourseworkTimeBlock> courseworkAllocation(ArrayList timetable, ArrayList<CourseworkTimeBlock> cCourseworkBlocks){
// Calculates and stores the free "time blocks" that can be used
// to allocate coursework.
ArrayList<Integer> freeTimeBlocks = new ArrayList<Integer>();
freeTimeBlocks = freeBlocks(timetable);
Random random = new Random();
ArrayList<CourseworkTimeBlock> courseworkTimeBlocks = new ArrayList<CourseworkTimeBlock>();
for(int i = 0; i < cCourseworkBlocks.size(); i++){
int allocateTo = -100;
int randomPoint = 0;
CourseworkTimeBlock courseworkBlock;
courseworkBlock = cCourseworkBlocks.get(i);
while(allocateTo < 0){
randomPoint = random.nextInt(freeTimeBlocks.size());
allocateTo = freeTimeBlocks.get(randomPoint);
courseworkBlock.setBlockAllocated(allocateTo);
courseworkTimeBlocks.add(courseworkBlock);
freeTimeBlocks.set(randomPoint, -1 );
for( int i = 0; i < courseworkTimeBlocks.size(); i++){
System.out.println("CW: " + courseworkTimeBlocks.get(i).getBlockAllocated());
return courseworkTimeBlocks;
}These are the calls I make in a separate method:
ArrayList<CourseworkTimeBlock> courseworkTimetableOne = new ArrayList<CourseworkTimeBlock>();
ArrayList<CourseworkTimeBlock> courseworkTimetableTwo = new ArrayList<CourseworkTimeBlock>();
courseworkTimetableOne = courseworkAllocation(fixedTimetable, courseworkBlocks);
courseworkTimetableTwo = courseworkAllocation(fixedTimetable, courseworkBlocks);Edited by: ChrisUK on Mar 1, 2008 9:11 AMChrisUK wrote:
Thanks for the reply.
In terms of the:
courseworkTimetableOne = courseworkAllocation(fixedTimetable, courseworkBlocks);
courseworkTimetableTwo = courseworkAllocation(fixedTimetable, courseworkBlocks);They are both supposed to pass in the fixedTimetable object, the reason being is that this is a timetable and is passed through in order to find it "free time" blocks.
The courseworkTimetableOne and courseworkTimetableTwo are just different representations of how the coursework time blocks could be allocated to that given fixedtimetable. You're calling the same method with the same parameters, so both references are going to point to the same object. It's the same as if you just replaced the second line with courseworkTimetableTwo = courseworkTimetableOne.
You've got two references pointing to the same object.
The fact that you do this first:
ArrayList<CourseworkTimeBlock> courseworkTimetableOne = new ArrayList<CourseworkTimeBlock>();
ArrayList<CourseworkTimeBlock> courseworkTimetableTwo = new ArrayList<CourseworkTimeBlock>();means nothing. You create the two new ArrayLists, but then this
courseworkTimetableOne = courseworkAllocation(fixedTimetable, courseworkBlocks);
courseworkTimetableTwo = courseworkAllocation(fixedTimetable, courseworkBlocks);gets rid of them. The new ArrayLists you just created are lost.
Remember when you assign to a reference variable such as courseworkTimetableOne =, all that does is copy a reference so now courseworkTimetableOne is pointing to the same object that whatever is on the RHS is pointing to.
If you want two different lists, then either courseworkAllocation should make a copy of its internal list and return that, or else the caller should do it.
>
By the way what does "SSCCE" mean?[http://mindprod.com/jgloss/sscce.html|http://mindprod.com/jgloss/sscce.html]
[http://homepage1.nifty.com/algafield/sscce.html|http://homepage1.nifty.com/algafield/sscce.html] -
Problem with instantiating array
Hi, so my problem is 2 fold :)
First off, here are my constructors:
public class ArrayBag implements BagADT<Object> {
public Object[] bag;
private int bagSize = size();
public ArrayBag() {
bag = new Object[100];
public ArrayBag(int c) {
if (c >= 0) {
bag = new Object[c];
}For some reason, netbeans doesnt recognize that the bag has been instantiated unless i change it to Object arrayBag[] = new Object[100] all on the same line.. I wrote a tester program which so far consists of arrayBag(100); and yeah...i get a null pointer error which poitns at the following method:
public int size() {
int count = 0;
while (count < bag.length && bag[count] != null) {
count++;
}//end while
return count;
} The error directly points at the line containing the while statment...But if i DO change the instantiation to a single line, then this error doesnt happen. Im sure that these errors are interconnected with one and other...just unsure how to fix them.
Thanks!
Paul
Edited by: Toadums on Jan 20, 2009 6:07 PMah of course! Thanks!
I do have another question though.
So what my teacher did...he sent the part of the code which he wrote as a class file...we had to import it into the library and all that jazz...when i try to run my program i get some lines of errors:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
at MemoryGame.init(MemoryGame.java:128)
at MemoryGame.<init>(MemoryGame.java:57)
at MemoryGame.main(MemoryGame.java:47)
Java Result: 1like that....and im just wondering, since i cant look at the code that he gave us...how am i supposed to test, cause im not sure where the error is O.o -
Problem With Referenced Array Loading
Hi. I'm working on the final lab for my java class at the moment, and I'm to create a program which reads a file containing transaction records, stores each record as an array element, and then prints various types of reports using the array of transactions. I've created a class called Transaction which stores all the data for each transaction, and the array used in my program is of type Transaction.
I'm not having any problems in writing the program, except there's something going wrong with my attempt to write a method to load the array. The method declaration is:
* Method to accept a file from the user and load its data into an array.
* Returns the number of elements added to the array.
public static int loadArray(Transaction[] transactionArray, int size) throws ExceptionNow, I'm under the impression (and my teacher confirmed this) that arrays are passed by reference. So I'm assuming that by creating an array in my main method, passing it into loadArray(), and changing the values within the method, all the data will be present in the array within main without having to explicitly return the loaded array.
However, as soon as I try to do anything with the loaded array, I get a NullPointerException. I opened up the debug mode, set a breakpoint in my main right after loadArray() is called, and it shows that every element in my array is null. I am at a loss as to why. If anyone can help me figure out why my reference array isn't staying updated as it's edited elsewhere, it would be greatly appreciated.
Here is my loadArray() code in case it would help, but there is no error in it's execution, as the same code directly in my main method works fine.
public static int loadArray(Transaction[] transactionArray, int size) throws Exception
int logicalSize = 0; // the number of transactions loaded into the array
int itemID; // the item ID involved in the transaction
int units; // the number of units in the transaction
double unitCost; // the cost of each unit in the transaction
char type; // the type of the transaction
String date; // the date of the transaction
String fileName; // the name of the user selected file
String record; // the current record in the file
Scanner file; // reads input from a user selected file
Scanner parse; // reads input from the file's current record
transactionArray = new Transaction[size]; // creates a new array for the new data
System.out.print("Please enter a file name: ");
fileName = input.nextLine();
file = new Scanner(new File(fileName));
record = file.nextLine(); // discards the initial line of headers
while(file.hasNext())
// grab the next record and parse all its data
record = file.nextLine();
parse = new Scanner(record).useDelimiter(",");
date = parse.next();
itemID = parse.nextInt();
type = parse.next().toUpperCase().charAt(0);
units = parse.nextInt();
unitCost = parse.nextDouble();
transactionArray[logicalSize] = new Transaction(date, itemID, type, units, unitCost); // loads the current transaction into the array
logicalSize++;
return logicalSize;
}Thanks!
Oh, I guess I should also add that the variable input is a global variable of type Scanner.
static Scanner input = new Scanner(System.in); // reads input from keyboardMessage was edited by:
Kristofer.WardNow, I'm under the impression (and my teacher confirmed this) that arrays are
passed by reference.Java passes references to arrays by value.
So I'm assuming that by creating an array in my main method, passing it into
loadArray(), and changing the values within the method, all the data will be present
in the array within main without having to explicitly return the loaded array.Bearing in mind my statement above, what really happens is that a reference to
the array you created is passed to loadArray() by value. What I mean by that
last bit is that your loadArray() is free to assign a reference to a completely
different array to its argument variable and the caller will not notice the change.
That's what's happening here:public static int loadArray(Transaction[] transactionArray, int size) throws Exception
// declarations of local variables
* The argument variable is now assigned a reference to a completely
* new array. When this function returns the variable the caller used to
* invoke this method will have exactly the same value it did before this
* method was invoked. Ie it will *still* refer to an array of nulls.
transactionArray = new Transaction[size];
// more stuff - that involves changing the contents of
// the newly created array, not the one the caller has
// a reference to.
return logicalSize;
} -
Problem with bidim Array - increases to double why ? Anyone plz???
Hey , same problem but now its BETA version =P
So...the board woks fine just for one letter, but if i call it more than once...it will increase the number of line and columns..don't want that.. number of lines are 28 and columns are 48..it will have to insert the letter (any letters) inside that size lol ...he's not doin....what is wrong? :S
public class Tabuleiro {
public void drawboard(int x, int y, String letter){
String [][] h = new String[this.numLines+1][this.numColu+1];
for(int i =1; i != h.length; i++){
for(int j= 1; j != h.length; j++){
if (i == x && j == y) {
h[i][j] = " "+letter+" " ;
System.out.print(h[x][y]);
} else
System.out.print(h[i][j] = " . ");
System.out.println();
public static void main(String[] xxx){
Tabuleiro tabu = new Tabuleiro();
// String [][]y = new String[numLines][numColu];
tabu.drawboard(20, 40, "L");
tabu.drawboard(14, 10, "A");
tabu.drawboard(7,18,"P");
private final int numLines = 28;
private final int numColu = 48;
I think it could be easier if i create a method just for the board populated with "." and then if is it possible , create another method that receive 3 arguments ( x, y, letter) and insert them in the board ( is it possible to do that? ) one method only to the board ( that receive de number of lines and columns) and another method that call that board and receive those 3 arguments.
can i do that? how?
Anyone????
thanks
Message was edited by:
Java__Estudantepublic class Tabuleiro {
public void drawboard(int x, int y, String letter) {
for (int i = 0; i < h.length; i++) {
for (int j = 0; j < h.length; j++) {
if (i == x && j == y) {
h[i][j] = " " + letter + " ";
} else if (h[i][j] == null) {
h[i][j] = " . ";
public void printToConsole() {
// Try to figure out what to write here by using the field 'h'
// and methods: System.out.print() and System.out.println()
public static void main(String[] xxx) {
Tabuleiro tabu = new Tabuleiro();
tabu.drawboard(20, 40, "L");
tabu.drawboard(14, 10, "A");
tabu.drawboard(7, 18, "P");
tabu.printToConsole();
private final int numLines = 28;
private final int numColu = 48;
private final String[][] h = new String[numLines][numColu]; -
I am needing help on a inventory program for a class that was due a couple of days ago. The program needs to use an array to store items, output should display the value on the entire inventory, and use a method to calculate the inventory and sort the array items by name. This is one of the errors I am receiving.
72: incompatible types
found : Product[]
required: int[]
DVD = new Product [5];
Here is the code I have so far, thanks to any help anyone can provide.
import java.util.Scanner; //program uses Scanner
class DVD
private double itemNumber; // class variable that stores the item number
private double unitsInStock; // class variable that stores the number of units in stock
private double pricePerUnit; // class variable that stores price of each unit
private String nameOfDvd; //class variable for the name of DVD
public DVD() // Constructor for the DVD class
itemNumber = 0.0;
unitsInStock = 0.0;
pricePerUnit = 0.0;
nameOfDvd = "";
public void setitemNumber(double number) // Method to set the item number
itemNumber = number;
public double getitemNumber() // Method to get the item number
return itemNumber;
public void setunitsInStock(double units) // Method to set the units in stock
unitsInStock = units;
public double getunitsInStock() // Method to get the units in stock
return unitsInStock;
public void setpricePerUnit(double price) // Method to set the price per unit
pricePerUnit = price;
public double getpricePerUnit() //Method to get price per unit
return pricePerUnit;
public void setnameOfDvd(String name) // Method to set the name of DVD
nameOfDvd = name;
public double calculateInventoryValue() // Method to calculate inventory value
return unitsInStock * pricePerUnit;
}//end class DVD
public class Inventory2Array
// main methods begins execution of java application
public static void main( String args[])
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
// Instantiate product array
int[] DVD;
DVD = new Product [5];
// Instantiate objects for the array
DVD[0] = new Product("The Faculty", 1, 10, 10.00);
DVD[1] = new Product("Shaun of the Dead", 2, 10, 10.00);
DVD[2] = new Product("Spider Man 3", 3, 20, 20.00);
DVD[3] = new Product("House M.D. Season 3", 4, 10, 45.00);
DVD[4] = new Product("Clerks Special Edition", 5, 10, 25.00);
// Print out a screen title
System.out.printf("DVD Inventory\n\n");
// call the sort
Arrays.sort( inventory );
System.out.println( DVD.toString() );
for(j=0; j<3; ++j)
System.out.printf("Inventory %s Products $ %.2f\n\n\n",
inventory[j].getnameOfDvd(),
inventory[j].calculateInventoryValue() );
//display the inventory value
} // end main method
public static void sortProduct(Product[] inventory)
Product temp = new Product();
int i, j;
for (i=1; i < inventory.length; i++)
for (j=0; j < inventory.length-i; j++)
if (inventory[j].getnameOfDvd().compareTo(inventory[j+1].getnameOfDvd())>0)
// exchange elements
temp = inventory[j];
inventory[j] = inventory[j+1];
inventory[j+1] = temp;
}I see what you mean. Can you tell me if I am on the right track with my code, I am receiving an error that states "cannot find symbol Arrays.sort(dvds); here is my code:
{code}import java.util.Scanner; //program uses Scanner
class DVD
private double itemNumber; // class variable that stores the item number
private double unitsInStock; // class variable that stores the number of units in stock
private double pricePerUnit; // class variable that stores price of each unit
private String nameOfDvd; //class variable for the name of DVD
public DVD() // Constructor for the DVD class
itemNumber = 0.0;
unitsInStock = 0.0;
pricePerUnit = 0.0;
nameOfDvd = "";
public void setitemNumber(double number) // Method to set the item number
itemNumber = number;
public double getitemNumber() // Method to get the item number
return itemNumber;
public void setunitsInStock(double units) // Method to set the units in stock
unitsInStock = units;
public double getunitsInStock() // Method to get the units in stock
return unitsInStock;
public void setpricePerUnit(double price) // Method to set the price per unit
pricePerUnit = price;
public double getpricePerUnit() //Method to get price per unit
return pricePerUnit;
public void setnameOfDvd(String name) // Method to set the name of DVD
nameOfDvd = name;
public double calculateInventoryValue() // Method to calculate inventory value
return unitsInStock * pricePerUnit;
}//end class DVD
class Inventory2Array
// main methods begins execution of java application
public static void main( String args[])
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
// Instantiate product array
Product [] dvds;
dvds = new Product [5];
// Instantiate objects for the array
dvds[0] = new Product("The Faculty", 1, 10, 10.00);
dvds[1] = new Product("Shaun of the Dead", 2, 10, 10.00);
dvds[2] = new Product("Spider Man 3", 3, 20, 20.00);
dvds[3] = new Product("House M.D. Season 3", 4, 10, 45.00);
dvds[4] = new Product("Clerks Special Edition", 5, 10, 25.00);
// Print out a screen title
System.out.printf("DVD Inventory\n\n");
// call the sort
Arrays.sort(dvds);
System.out.println(dvds);
public class InventoryProgram1
//main method begins execution of Java
public static void main (String args [])
//create Scanner to obtain input from command window
Scanner input = new Scanner (System.in);
double itemNumber = 0.0; // variable that stores the item number
double unitsInStock = 0.0; // variable that stores the units in stock
double pricePerUnit = 0.0; // variable that stores the price per unit
double InventoryValue = 0.0; // variable that stores inventory value
String nameOfDvd = ""; // DVD name
//create InventoryProgram1 object and assign to myInventoryProgram1
InventoryProgram1 myInventoryProgram1 = new InventoryProgram1 ();
System.out.print ("Item Number:\n");
System.out.print("DVD Name:\n");
System.out.print("Units In Stock:\n");
System.out.print("Price Per Unit:\n");
InventoryValue = unitsInStock * pricePerUnit; // calculate inventory value
System.out.println("Inventory Value: $100.00\n"); // display inventory value
{code} -
Hello
I don't know how to iniatialize an array of a specific class (Myclass1):
public class Myclass2
Myclass1 m[] ;
public Myclass2()
Myclass1 m[] =new Myclass1() ;
// I think it's wrong but the problem is that i don't have the array
// size so i can't write :
// for (int i=0;i<m.length;i++) {Myclasse1 m[i] = new Myclass1() ;}
If you ve got an idea or advices can you tell me please .Thank for your help.I don't know how to iniatialize an array of a specificTo Initialize an Object array, you would use the same declaration as any other array..
Myclass1 m[] =new Myclass1[0];
or
Myclass1 m[] =new Myclass1[10];
// I think it's wrong but the problem is that i don't
have the array
// size so i can't write :If you do not know the array size you could use an ArrayList or some other data structure(http://java.sun.com/j2se/1.4/docs/api/java/util/package-summary.html) and later convert that data structure to Array. -
Sql loader problem with point data
I am struggling to import bulk point data.
Example line from data file
2 1 Highest mountain on Skye with steep faces and narrow ridges. 4 32 3001 8307 57.206116 -6.223032 992
So its all tab deliminated
3001 is sdo_gtype
8307 is sdo_srid
57.xxx is my X point
-6.xxx is my Y point
992 is my Z point
I can import all of the data apart from the final section, and my loader looks like:
GEOM COLUMN OBJECT
SDO_GTYPE INTEGER EXTERNAL TERMINATED BY X'09' ,
SDO_SRID INTEGER EXTERNAL TERMINATED BY X'09',
SDO_POINT_TYPE(X,Y,Z) INTEGER EXTERNAL TERMINATED BY ','
Any help? I simply need it take the last three numbers and assign them to x,y,z of point_type.
Need any more info?TSEdinburgh,
Try
LOAD DATA INFILE * APPEND INTO TABLE MyTable
FIELDS TERMINATED BY X'09' TRAILING NULLCOLS
MyCol1,
MyCol2,
description,
MyCol3,
MyCol4,
geom COLUMN OBJECT (
sdo_gtype INTEGER EXTERNAL,
sdo_srid INTEGER EXTERNAL,
sdo_point COLUMN OBJECT (
x FLOAT EXTERNAL,
y FLOAT EXTERNAL,
z FLOAT EXTERNAL
)Regards,
Noel
Maybe you are looking for
-
Wifi disconnects on highish throughput
Hi, I've got wireless problems with the combination of my router and my laptop. Whenever I download something more than say 1MB the connection drops. This happens with Youtube, Google Image search and Pacman updates. The connection re-establishes aft
-
I am frustrated. With the no squint, which has a mind of its own, then some pages are fine, in others the type is too big or too small for the frames. If I use the default Firefox zoom that is no better. I have to set things for like 130 percent and
-
Open Sales order is Consumed and after it shipped it Unconsumed
Hi All apprcate you help on the issue bellow : we manage the forecast Via Oracle forecast set Form name is : MRPFFDIF we set the prpfile MRP:Consume Fcst Set Summary to Yes Customer expectation is that when running consumption only open sales orders
-
DS XI3.2 SP1 - Problem when starting RFC server from management console
Hi, We're using DataServices XI 3.2 SP1 FP1 on a windows 2008 server 64bits to load SAP BW. We have set up an external system in SAP BW called "DI_SOURCE" and then successfully created a RFC server interface (DI_SOURCE) within the management console.
-
Tab delimited file, to populate JTable
Hey all As Java is fairly new for me I have come into several problems. First of all i have a program making a tab delimited file, for example like this: Mig 12345 You Gig 12345 DouNow i want to read the file and populate each line in