What's the exception and stack trace when it crashes? You can see these by debugging, or using the "adb logcat" command.
I suspect that, at the minimum, the visibility on the constructor of your View subclass needs to be changed to public so that LayoutInflator can call it. On Sep 26, 2:39 pm, jdekeij <[email protected]> wrote: > I changed the xml in the following: > <view > android:id="@+id/ViewPaint" > class="com.example.android.helloactivity.HelloActivity$DrawingView" > android:layout_width="wrap_content" > android:layout_height="wrap_content"/> > > This makes the app crash. > > Changing it into > > <View > android:id="@+id/ViewPaint" > class="com.example.android.helloactivity.HelloActivity$DrawingView" > android:layout_width="wrap_content" > android:layout_height="wrap_content"/> > > Makes the app run but no view on screen :-( > > Jasper > > On Sep 24, 10:21 pm, Lance Nanek <[email protected]> wrote: > > > Theviewelement name in your XML needs to be entirely lower case, not > > capitalized. Should be "view", not "View". Capitalized gives you an > > android.view.Viewinstance, not your subclass. > > > On an unrelated note, I'm actually surprised what you posted isn't > > crashing on the lack of android:layout_width and android:layout_height > > attributes first. > > > On Sep 24, 10:34 am, jdekeij <[email protected]> wrote: > > > > Hoi > > > > I try to create my customviewinside a linearlayout. For example > > > > <View android:id="@+id/ViewPaint" > > >class="com.example.android.helloactivity.HelloActivity$DrawingView"/> > > > > In the java source I created a DrawingViewclasswhich extendsView. > > > Unfortunatly it does not get instantiated. I tried to overwrite the > > > ondraw() but without success :-( > > > > Help is very much appreciated. > > > Jasper > > > > Java Code > > > public staticclassDrawingView extendsView > > > { > > > private final Paint mPaint; > > > /* > > > * Constructor that is called when inflating aviewfrom XML. > > > */ > > > DrawingView(Context context, AttributeSet attrs){ > > > super(context,attrs); > > > > mPaint = new Paint(); > > > mPaint.setAntiAlias(true); > > > mPaint.setARGB(255, 255, 255, 255); > > > } > > > > @Override > > > protected void onDraw(Canvas canvas) { > > > float yPos; > > > float xPos; > > > int xOffset = 20; > > > int yOffset = 50; > > > int cxScreen = canvas.getWidth(); > > > int cyScreen = canvas.getHeight(); > > > int cx = cxScreen - (2*xOffset); > > > int cy = cyScreen - (2*yOffset); > > > int cxStepSize = cx/10 - 1; > > > int cyStepSize = cy/10 - 1; > > > > // Makes the complete screen white! > > > //canvas.drawColor(0xFFFFFFFF); > > > yPos = (float)yOffset; > > > xPos = (float)xOffset; > > > for (int i=0; i <= 10; i++) > > > { // xstart, ystrt,xend,yend > > > canvas.drawLine((float)xOffset, yPos, (float)cx, (float) > > > yPos, mPaint); > > > yPos += cyStepSize; > > > } > > > for (int i=0; i <= 10; i++) > > > { // xstart, ystrt,xend,yend > > > > canvas.drawLine((float)xPos, (float)yOffset, (float)xPos, > > > (float)cy, mPaint); > > > xPos += cxStepSize; > > > } > > > } > > > } > > > > XML: > > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > > > android" > > > android:orientation="vertical" > > > android:padding="10dip" > > > android:layout_width="fill_parent" > > > android:layout_height="wrap_content"> > > > > <TextView > > > android:layout_width="fill_parent" > > > android:layout_height="wrap_content" > > > android:layout_marginTop="10dip" > > > android:text="Please select a planet:" > > > /> > > > > <Spinner > > > android:id="@+id/spinner" > > > android:layout_width="fill_parent" > > > android:layout_height="wrap_content" > > > android:drawSelectorOnTop="true" > > > android:prompt="@string/planet_prompt" > > > /> > > > <TextView android:id="@+id/dateDisplay" > > > android:layout_width="wrap_content" > > > android:layout_height="wrap_content" > > > android:text="No date yet"/> > > > > <Button android:id="@+id/pickDate" > > > android:layout_width="wrap_content" > > > android:layout_height="wrap_content" > > > android:text="Change the date"/> > > > > <TextView android:id="@+id/timeDisplay" > > > android:layout_width="wrap_content" > > > android:layout_height="wrap_content" > > > android:text="No time yet"/> > > > > <Button android:id="@+id/pickTime" > > > android:layout_width="wrap_content" > > > android:layout_height="wrap_content" > > > android:text="Verander the time"/> > > > > <View android:id="@+id/ViewPaint" > > >class="com.example.android.helloactivity.HelloActivity$DrawingView"/> > > > </LinearLayout> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

