Hi Jark,

Here is my code

package com.android.table;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.graphics.Rect;

public class GameDemo extends Activity {
        public static int idLayout = 1;
        public static int screenheight = 0;
        public static int screenwidth = 0;
        public AddPegHoles adp = new AddPegHoles(this);
        public Hole h;
        public static int holeid = 0;
        Hole[] holeArray = new Hole[33];
        FrameLayout l1,l2,l3,l4,;
        RelativeLayout layout;
        /** Called when the activity is first created. */
        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        layout=(RelativeLayout) findViewById(R.id.tableviewback);
        layout.setBackgroundResource(R.drawable.woodenbackground);

        Display display;
        display =
((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
        screenheight = display.getHeight();
        screenwidth = display.getWidth();

        l1=(FrameLayout)findViewById(R.id.frame1);
        adp.addPegHoles(l1, 1,0);
        createHole(holeid,true,R.id.frame1,1);
        l2=(FrameLayout)findViewById(R.id.frame2);
        adp.addPegHoles(l2, 1, leftpadding+l1.getWidth());
        holeid++;       createHole(holeid,true,R.id.frame2,1);
        l3=(FrameLayout)findViewById(R.id.frame3);
        adp.addPegHoles(l3, 1, leftpadding+l1.getWidth());
        holeid++;       createHole(holeid,true,R.id.frame3,1);


        int  leftpadding=(screenwidth/7);
        int  toppadding=(screenheight/7);




On Mon, Mar 23, 2009 at 5:28 PM, Jark Reijerink
<jark.reijer...@gmail.com> wrote:
> Hello,
>
> Are you sure you're getting a valid FrameLayout?
>
> Because if findViewById doesnt finds a valid view it returns null. Which
> could explain the NullPointerException.
>
> Also: are you setting your xml layout with setContentView in your onCreate
> method? If so try putting your code after that method call.
>
> Jark
>
> 2009/3/23 kavitha <kavith...@gmail.com>
>>
>> Hii All,
>>
>> I am developing a game in android and i want to capture screen
>> coordinates of a view(ImageView) which is embedded in frame.
>>
>> Hierarchy is
>> <LinearLayout android android:layout_height="fill_parent"
>> android:layout_width="fill_parent" >
>>     <RelativeLayout android:layout_height=fill_parent"
>> android:layout_width="fill_parent" >
>>           <FrameLayout android:layout_height="wrap_content"
>> android:layout_width="wrap_content"
>> android:id="@+id/frame14"></FrameLayout>
>>   </RelativeLayout>
>> </LinearLayout>
>>
>> At run time i am attaching two image views for frame layout.I wanted
>> to capture screen coordinates of frame layout.But Couldnt do it.if i
>> say
>>
>> (FrameLayout) f=(FrameLayout)findViewById(R.id.frame14);
>> int[] loc = new int[2];
>> f.getLocationOnScreen(loc);
>> System.out.println(loc[0]);
>> System.out.println(loc[1]);
>>
>> I get Null Pointer Exception for getLocationOnScreen() method.
>>
>> If I try to get f.getLeft() and f.getRight() they return as 0
>> coordinates.
>>
>> Can anyone please tell me how to find location on screen of a view.
>>
>> I tried even in onStart() method,,,still i get Null Pointer Exception.
>>
>> Please tell me how to get screen coordinates of a view in android.
>>
>> It is very urgent.Please help.
>>
>> Thanks
>> Kavitha
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to