NullReferenceException by localRotation And Quaternion.Euler!??

I’m having A Trouble In Converting From JavaScript To C#, I Converted It And Until Now No Errors, But When I Entered Playmode, It Gave Me NullReferenceException Error, And Not 1 Line Only! Each Lines That Contain:

TRANSFORMNAME.localRotation = Quaternion.Euler(blah,blah,blah)

I Get:
NullReferenceException: Object reference not set to an instance of an object

And The Line That I Show You Now Is An Example Of The Error:

public Transform needle;
public float value = 0f;
public float maxValue = 100f;
	//(Math.Fit) And (angle.min - angle.max) Are From Another Script Which Are Imported By Adding "using SharedObjects;".
	if(needle.localRotation != Quaternion.Euler(needle.localEulerAngles.x,needle.localEulerAngles.y,Math.Fit(value,maxValue,angle.min,angle.max)))
		needle.localRotation = Quaternion.Euler(needle.localEulerAngles.x,needle.localEulerAngles.y,Math.Fit(value,maxValue,angle.min,angle.max));

Both Lines, In (If) Statement And Below Of The (If) Statement Send Errors!
Is There Anything I’ve Missed? Thanks…
Note: The Errors Are From Lines That Contain Quaternion.Euler And Not The TRANSFORM It Self! As At The Top There Is if(needle) Which Checks If The Transform Is Assigned!

localRotation being a property of an Object (class/reference type) requires that this object (“thisOne.localRotation”) is not null - otherwise it will throw exception. Your transform must be null


if( QuaternionA==QuaternionB )

is as bad idea as float==float (Quaternions are bunch of floats inside).
You compare quaternions like this:

Quaternion quaternionA;
Quaternion quaternionB;

if( Quaternion.Angle( quaternionA , quaternionB )<10f )
    //angle between quaternionA and quaternionB is less than 10 degrees

if( Quaternion.Dot( quaternionA , quaternionB )>0.9f )
     //difference between quaternionA and quaternionB is less than 5%
     //dot returns values ranging from -1f to 1f, where -1f is opposite direction and 1 for perfectly aligned (but again, these are floats, and you must test them using < and > and definately not ==)