Android Forums

Go Back   Android Forums > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Display Modes
Old 04-22-2009, 03:04 AM   #1
Junior Member
 
Join Date: Apr 2009
Posts: 1
Friends: 0
View pierpa's Profile   View pierpa's Photo Album   View pierpa's Blog   View Social Groups
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$Tracc iaView"
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(A ctivityThread.java:2141)
E/AndroidRuntime( 164): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2157)
E/AndroidRuntime( 164): at android.app.ActivityThread.access$1800(ActivityThr ead.java:112)
E/AndroidRuntime( 164): at android.app.ActivityThread$H.handleMessage(Activit yThread.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.jav a: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$MethodAndArgsCa ller.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(Layo utInflater.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.setCo ntentView(PhoneWindow.java:231)
E/AndroidRuntime( 164): at android.app.Activity.setContentView(Activity.java: 1567)
E/AndroidRuntime( 164): at com1.example.android.prova.Activitygps.onCreate(Ac tivitygps.java:60)
E/AndroidRuntime( 164): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1122)
E/AndroidRuntime( 164): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.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.PathClassLoader@4339c200
E/AndroidRuntime( 164): at dalvik.system.PathClassLoader.findClass(PathClassL oader.java:215)
E/AndroidRuntime( 164): at java.lang.ClassLoader.loadClass(ClassLoader.java:4 53)
E/AndroidRuntime( 164): at java.lang.ClassLoader.loadClass(ClassLoader.java:4 21)
E/AndroidRuntime( 164): at android.view.LayoutInflater.createView(LayoutInfla ter.java:465)
E/AndroidRuntime( 164): at android.view.LayoutInflater.createViewFromTag(Layo utInflater.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...

Pp
pierpa is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 10-14-2009, 03:22 PM   #2
gnk
Junior Member
 
Join Date: Oct 2009
Posts: 1
Friends: 0
View gnk's Profile   View gnk's Photo Album   View gnk's Blog   View Social Groups
Ciao...
scrivo in inglese...I'm getting the same problem. Did you find a solution?

Thank you!!

Grazie..
gnk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 11-11-2009, 08:45 AM   #3
Junior Member
 
Join Date: Nov 2009
Posts: 4
Friends: 0
View DukaSrbija's Profile   View DukaSrbija's Photo Album   View DukaSrbija's Blog   View Social Groups
First hint: redefine all constructors of View (there are three I think)
Second hint:
in layout try

<?xml version="1.0" encoding="utf-8"?>
<com.example.android.prova.TracciaView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TracciaV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
DukaSrbija is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 08-01-2010, 12:36 AM   #4
New Member
 
Join Date: Aug 2010
Posts: 1
Friends: 0
View NumfarVera's Profile   View NumfarVera's Photo Album   View NumfarVera's Blog   View Social Groups
Hello, I'm new to Android as well and encountered a similar error. My error was caused by the spelling of my package name in my layout xml.
NumfarVera is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection error? dtwalkerfl HTC Smart Mobility 8 12-02-2009 08:23 AM
How to set the layout from java code? liviu1988 Android Development, Answers, Tutorials, and Code Snippets 0 03-26-2009 07:28 AM
Signing APK file issues.... arcarocket Android Development, Answers, Tutorials, and Code Snippets 5 02-22-2009 05:41 PM
Broken Pipe Error beeson76 Android Games And Applications 1 02-01-2009 04:54 AM
File Management and ringtones JackD3ath Android Chat 1 12-28-2008 10:48 AM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 10:40 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.