views:

404

answers:

2

I have a crash (Application Stopped Unexpectedly) problem with this main.xml is a "HelloWorld" type project (while testing and learning features I need for my app) :

I isolated the ImageButton as an issue, but I can't isolate any of the parameters...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" >

    <ImageButton android:id="@+id/picture"    
    android:layout_width="240dip"    
    android:layout_height="180dip"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/icon"
    android:adjustViewBounds="true"     
    android:cropToPadding="true"    
    android:clickable="true"    
    android:scaleType="fitCenter" />    

</LinearLayout>

icon.png exists in my resources... I can see the preview in the Layout tab, even though the image is not centered on the button, but I read that it was normal.

The code below works fine (as a regular Button). I can also do the same as an ImageView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" >

    <Button android:id="@+id/picture"
    android:layout_width="240dip"
    android:layout_height="180dip"
    android:layout_gravity="center_horizontal" />

</LinearLayout>

I use Eclipse and the AVD, and all my learning is done on 2.1 (SDK level 7). I can't test the app on an actual device yet as I don't have it yet.

Thanks in advance !

A: 

Thanks for your reply...

First batch:
04-22 01:33:43.609: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f060001
04-22 01:33:44.139: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f0700e5
04-22 01:33:44.139: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f020031
04-22 01:33:44.139: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f020030
04-22 01:33:44.149: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f050000
04-22 01:33:44.199: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f060000
04-22 01:33:44.209: WARN/ResourceType(709): Resources don't contain package for resource number 0x7f060001

Then, a little later in the log:
04-22 01:33:46.319: ERROR/AndroidRuntime(866): ERROR: thread attach failed
04-22 01:33:47.289: WARN/dalvikvm(878): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-22 01:33:47.289: ERROR/AndroidRuntime(878): Uncaught handler: thread main exiting due to uncaught exception
04-22 01:33:47.309: ERROR/AndroidRuntime(878): java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.mydomain.android/ca.mydomain.android.myapp}: java.lang.ClassCastException: android.widget.ImageButton
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.os.Handler.dispatchMessage(Handler.java:99)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.os.Looper.loop(Looper.java:123)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at java.lang.reflect.Method.invokeNative(Native Method)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at java.lang.reflect.Method.invoke(Method.java:521)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at dalvik.system.NativeStart.main(Native Method)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): Caused by: java.lang.ClassCastException: android.widget.ImageButton
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at ca.mydomain.android.myapp.onCreate(myapp.java:17)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-22 01:33:47.309: ERROR/AndroidRuntime(878): ... 11 more

It's all incomprehensible to me... Hope this helps. Thanks for your time.

J.

Joël
A: 

Oh bother !! It seems that it was a java error in my MyApp.java, when I was trying to declare the event for the button. Case closed. Sorry.

Joël