HI everyone,i am a biginer in java and i need your help...i have write a prgram but i cant execute can anyone help me for execute it
the program is :
package sensor;

public class sensor {

	private String Id;
	private int Kordx;
	private int Kordy;
	private char[] getId;
	
	
	
	public static void main(String[] args) {
	sensor ob=new sensor ("first","1","1");
	System.out.println(ob.getId);
	System.out.println(ob.getKordx() + ob.getKordy());
	
	ob.setKordx("2");
	ob.setKordy("2");
	ob.setId("second");
	System.out.println(ob.getId);
	System.out.println(ob.getKordx() + ob.getKordy());
	

	}
public sensor (String id,int kordx,int kordy)
{
Id=id;
Kordx=kordx;
Kordy=kordy;

}
public String getId()
{
	return Id; 
}
public void setId (String id )
{
	Id=id;
}

public int getKordx()
{
	return Kordx;
}
public void setKordx (int kordx )
{
	Kordx=kordx;
}
public int getKordy()
{
	return Kordy;
}
public void setKordy (int kordy )
{
	Kordy=kordy;
}
}

i think the problem is in sensor ob=new sensor ("first","1","1"); but i dont know why,please help me!
REGARDS DHIJA22

Recommended Answers

All 12 Replies

The constructor defines its parameters as a String and two ints.
When you call it you pass three Strings.
"1" is a String, 1 is an int.

ps Next time, please post the exact error message that you get. It makes our lives a LOT easier!

thank u JamesCherrill i understand the wrong that i have made..i change i made string tipe and now the code is ok
code:

package sensor;


public class sensor {

	private String Id;
	private String Kordx;
	private String Kordy;
	private char[] getId;
	
	
	
	public static void main(String[] args) {
	sensor ob=new sensor ("first","1","1");
	System.out.println(ob.getId);
	System.out.println(ob.getKordx() + ob.getKordy());
	
	ob.setKordx("2");
	ob.setKordy("2");
	ob.setId("second");
	System.out.println(ob.getId);
	System.out.println(ob.getKordx() + ob.getKordy());
	

	}
public sensor (String id,String kordx,String kordy)
{
Id=id;
Kordx=kordx;
Kordy=kordy;

}
public String getId()
{
	return Id; 
}
public void setId (String id )
{
	Id=id;
}

public String getKordx()
{
	return Kordx;
}
public void setKordx (String kordx )
{
	Kordx=kordx;
}
public String getKordy()
{
	return Kordy;
}
public void setKordy (String kordy )
{
	Kordy=kordy;
}
}

but when i compile send me en error mesage like this:
at java.io.Writer.write(Unknown Source)
at java.io.PrintStream.write(Unknown Source)
at java.io.PrintStream.print(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at sensor.sensor.main(sensor.java:15)
what does this mean...
what i ought to do to take the right result???
please help me
thanx
regards dhija 22

I think you made the wrong change - it would have been better to change the calls to pass ints, rather than change the method to accept Strings, but never mind.

You have missed out the all-important first line of the error message, the one that tells you exactly what the error was.

oh ok thanx i will change again i lwill pass in int but...
sorry the error message is:
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Unknown Source)
at java.io.PrintStream.write(Unknown Source)
at java.io.PrintStream.print(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at sensor.sensor.main(sensor.java:15)

That's telling you
NullPointerException a variable isn't initialised, or a method has returned null when you expected it to return a value of some sort.
and
at sensor.sensor.main(sensor.java:15) that happened on line 15 of sensor's source code.
That line says
System.out.println(ob.getId);
getID is a method, but that's not a valid method call... (think about it)

sorry i dont understand ...what i ought to to that i can take right result?

Method calls always have a ( and a ) somewhere...

and what i oght to do ?!?!

Correct the syntax of your method call on line 15.
You have to work this out for yourself, or you'll learn nothing.
It's not hard.

Just to make things really confusing, you have a method and an array variable with the same name. The array variable is never initialised and seems to be useless. Based on what you have posted so far, you can/should get rid of it.

ok everything its ok i repair the errors
the right code is:

package sensor;
import java.util.*;

public class sensor {

	private String Id;
	private int Kordx;
	private int Kordy;

	
	
	
	public static void main(String[] args) {
	sensor ob=new sensor ("first",1,1);
	System.out.println(ob.getId());
	System.out.println(ob.getKordx() + " " + ob.getKordy());
	
	ob.setKordx(2);
	ob.setKordy(2);
	ob.setId("second");
	System.out.println(ob.getId());
	System.out.println(ob.getKordx() + " " + ob.getKordy());
	

	}
public sensor (String id,int kordx,int kordy)
{
Id=id;
Kordx=kordx;
Kordy=kordy;

}
public String getId()
{
	return Id; 
}
public void setId (String id )
{
	Id=id;
}

public int getKordx()
{
	return Kordx;
}
public void setKordx (int kordx )
{
	Kordx=kordx;
}
public int getKordy()
{
	return Kordy;
}
public void setKordy (int kordy )
{
	Kordy=kordy;
}
}

Yay! I knew you could do it! Mark this thread "solved" so others will know.

ps: Small point: Java coding standards say class names begin with a capital letter, variable names should begin with a lower-case letter.

hi JamesCherrill ,i am e newest user of this page i dont know how to mark this thread as solved..please tell me what i ought to do...
p.s Yes i know that class name begin with capital letrer and variable names should begin with a lower-case letter. i repair andh these :)
thank u
regards dhija22

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.