I keep getting a null pointer exception for a linearlayout object that i defined on xml. The object was added to the layout that i set in the setcontentview() method. The linearlayout shows on the screen. I also apply an object animator to the linearlayout object and it moves as it should on the screen. I get the null pointer exception when i try to compute a calculation in a for loop with the getX() and getY() values of this xml linearlayout. This for loop resides inside an anonymous thread which is initialized inside a method. Well, here's the code. If you see the error please let me know:
LinearLayout xml_linearlayout
//inside onCreate
xml_linearlayout = (LinearLayout)getLayoutInflater.inflate(R.layout.mm,null);//i think here's problem
//here is my main layout called main. Its a relative layout
//this main layout was created programmatically not by xml format
main.addView(xml_linearlayout,parameters that have MATCH_PARENT= width and height);
//onCreate has ended
//method that attempts to use getX() and getY() of xml_linearlayout
public void methodCal(final float x, final float y){
float newX = x;
float newY = y;
new Thread(new Runnable(){
public void run(){
for(int i=0; i<30 ; i++){
double e = Math.pow(newX-xml_linearlayout.getX(),2.0);// NPE thrown here
}
}
}).start();
}