millroy 0 Newbie Poster

hi

i am making a android app for a compass but i havew a great problem with Images cuz i m using images and i am new to android the problem occurs wen i call the ImageView constructor or try accessing any of its methods like setImageDrawable.

this is my code:

public class CompassAct extends Activity {

    ImageView a=new ImageView(this);


    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_compass);//the layout gets displayed if i remove constructor from Imageview



       }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_compass, menu);
        return true;
    }

Layout code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<ImageView
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
     />  



<ImageView
    android:id="@+id/compass"
    android:layout_width="240dp"
    android:layout_height="240dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"

    android:src="@drawable/compass" />

<ImageView
    android:id="@+id/needle"
    android:layout_width="180dp"
    android:layout_height="180dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"

    android:src="@drawable/needle" />

</RelativeLayout>

please help me i am trying for weeks
thank you

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.