Pierpa wrote:
> Hello, I am new to android programming...so please be patient..
> 
> I am trying to load a custom  view (TracciaView) into an activity
> (Activitygps), where my custom view in defined as a subclass of an
> activty class. I created the following xml layout file for the
> activity containing the custom view:
> 
> ----
> <?xml version="1.0" encoding="utf-8"?>
> <view xmlns:android="http://schemas.android.com/apk/res/android";
> 
>  class="com.example.android.prova.Activitygps$TracciaView"
>             android:id="@+id/TracciaV"
>             android:layout_width="fill_parent"
>             android:layout_height="fill_parent"
> />
> ----
> this is the subclass TracciaView:
> 
>  public static class TracciaView extends View {
> 
>                private ShapeDrawable mDrawable;
> 
>                public TracciaView(Context context) {
>                   super(context);
> 
>                   int x = 10;
>                   int y = 10;
>                   int width = 300;
>                   int height = 200;
> 
>                   mDrawable = new ShapeDrawable(new OvalShape());
>                   mDrawable.getPaint().setColor(0xff74AC23);
>                   mDrawable.setBounds(x, y, x + width, y + height);
> 
> 
>                }
>                @Override protected void onDraw(Canvas canvas) {
> 
>                            mDrawable.draw(canvas);
>                            super.onDraw(canvas);
>                   }
> 
>        }
> 
> 
> What happens is I am keeping on getting runtime error (the app dies),
> looking in the LogCat I get:
> 
> I/ActivityManager(   53): Starting activity: Intent { comp=
> {com1.example.android.prova/com1.example.android.prova.Activitygps} }
> D/AndroidRuntime(  164): Shutting down VM
> W/dalvikvm(  164): threadid=3: thread exiting with uncaught exception
> (group=0x4000fe68)
> E/AndroidRuntime(  164): Uncaught handler: thread main exiting due to
> uncaught exception
> E/AndroidRuntime(  164): java.lang.RuntimeException: Unable to start
> activity ComponentInfo{com1.example.android.prova/
> com1.example.android.prova.Activitygps}:
> android.view.InflateException: Binary XML file line #2: Error
> inflating class com.example.android.prova.Activitygps$TracciaView
> E/AndroidRuntime(  164):      at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> 2141)
> E/AndroidRuntime(  164):      at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
> 2157)
> E/AndroidRuntime(  164):      at android.app.ActivityThread.access$1800
> (ActivityThread.java:112)
> E/AndroidRuntime(  164):      at android.app.ActivityThread$H.handleMessage
> (ActivityThread.java:1581)
> E/AndroidRuntime(  164):      at android.os.Handler.dispatchMessage
> (Handler.java:88)
> E/AndroidRuntime(  164):      at android.os.Looper.loop(Looper.java:123)
> E/AndroidRuntime(  164):      at android.app.ActivityThread.main
> (ActivityThread.java:3739)
> E/AndroidRuntime(  164):      at java.lang.reflect.Method.invokeNative
> (Native Method)
> E/AndroidRuntime(  164):      at java.lang.reflect.Method.invoke
> (Method.java:515)
> E/AndroidRuntime(  164):      at com.android.internal.os.ZygoteInit
> $MethodAndArgsCaller.run(ZygoteInit.java:739)
> E/AndroidRuntime(  164):      at com.android.internal.os.ZygoteInit.main
> (ZygoteInit.java:497)
> E/AndroidRuntime(  164):      at dalvik.system.NativeStart.main(Native
> Method)
> E/AndroidRuntime(  164): Caused by: android.view.InflateException:
> Binary XML file line #2: Error inflating class
> com.example.android.prova.Activitygps$TracciaView
> E/AndroidRuntime(  164):      at
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:575)
> E/AndroidRuntime(  164):      at android.view.LayoutInflater.inflate
> (LayoutInflater.java:385)
> E/AndroidRuntime(  164):      at android.view.LayoutInflater.inflate
> (LayoutInflater.java:320)
> E/AndroidRuntime(  164):      at android.view.LayoutInflater.inflate
> (LayoutInflater.java:276)
> E/AndroidRuntime(  164):      at
> com.android.internal.policy.impl.PhoneWindow.setContentView
> (PhoneWindow.java:231)
> E/AndroidRuntime(  164):      at android.app.Activity.setContentView
> (Activity.java:1567)
> E/AndroidRuntime(  164):      at
> com1.example.android.prova.Activitygps.onCreate(Activitygps.java:60)
> E/AndroidRuntime(  164):      at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
> 1122)
> E/AndroidRuntime(  164):      at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> 2104)
> E/AndroidRuntime(  164):      ... 11 more
> E/AndroidRuntime(  164): Caused by: java.lang.ClassNotFoundException:
> com.example.android.prova.Activitygps$TracciaView in loader
> dalvik.system.pathclassloa...@4339c200
> E/AndroidRuntime(  164):      at dalvik.system.PathClassLoader.findClass
> (PathClassLoader.java:215)
> E/AndroidRuntime(  164):      at java.lang.ClassLoader.loadClass
> (ClassLoader.java:453)
> E/AndroidRuntime(  164):      at java.lang.ClassLoader.loadClass
> (ClassLoader.java:421)
> E/AndroidRuntime(  164):      at android.view.LayoutInflater.createView
> (LayoutInflater.java:465)
> E/AndroidRuntime(  164):      at
> android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
> E/AndroidRuntime(  164):      ... 19 more
> I/Process (   53): Sending signal. PID: 164 SIG: 3
> I/dalvikvm(  164): threadid=7: reacting to signal 3
> I/dalvikvm(  164): Wrote stack trace to '/data/anr/traces.txt'
> I/ARMAssembler(   53): generated
> scanline__00000077:03515104_00000000_00000000 [ 27 ipp] (41 ins) at
> [0x26cfd8:0x26d07c] in 1686764 ns
> 
> 
> 
> I lost almost two days  trying to figure out what's wrong ...
> 
> Any help/hint will be very much appreciated...

Try not making it a static class and see if that helps.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to