Here is the code:
public class beautiful extends Activity {
ImageView radar = (ImageView) findViewById(R.id.radar);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.beautiful);
Button search = (Button) findViewById(R.id.magnifier);
ImageView text = (ImageView) findViewById(R.id.text);
MediaPlayer siren = MediaPlayer.create(this, R.raw.siren);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Thread counter = new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
try{
Thread.sleep(2000);
radar.setImageResource(R.drawable.radar_new_full);
Thread.sleep(3000);
radar.setImageResource(R.drawable.radar_new_50);
Thread.sleep(2000);
radar.setImageResource(R.drawable.radar_new_found);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
}
}
});
counter.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.new_search:
startActivity(new Intent("com.zwiebel.MENU"));
}
return super.onMenuItemSelected(featureId, item);
}
}
And here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fccea8">
<Button
android:id="@+id/magnifier"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="right"
android:background="@drawable/searchmagnificer"
/>
<ImageView
android:id="@+id/radar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="5dp"
/>
<ImageView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
I haven’t seen any problem in the code, so I don’t know what’s the error.
It’s pretty obvious. You are trying to find a view before the view has been set.
change that to
and put
below the setContentView function