android imageview图片崩溃,添加ImageView时应用程序崩溃

我试图添加图像到我的应用程序,但它不断崩溃,我不能断定为什么。添加ImageView时应用程序崩溃

我在我的应用程序中有多个图像,但添加这一个图像似乎有问题。下面是我的XML(编辑:完整的XML(因为原来的布局的目的这种情况已经改变)):

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="match_parent" >

android:id="@+id/imageTextButton4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBaseline="@+id/imageTextButton3"

android:layout_alignBottom="@+id/imageTextButton3"

android:layout_alignLeft="@+id/imageTextButton2"

android:layout_alignRight="@+id/imageTextButton2"

android:drawableTop="@drawable/ic_launcher"

android:text="Progress" />

android:id="@+id/imageTextButton3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/imageTextButton1"

android:layout_alignRight="@+id/imageTextButton1"

android:layout_below="@+id/imageTextButton1"

android:layout_marginTop="85dp"

android:drawableTop="@drawable/ic_launcher"

android:text="Meal Plans" />

android:id="@+id/imageTextButton2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:layout_marginRight="22dp"

android:drawableTop="@drawable/ic_launcher"

android:text="Your Meals" />

android:id="@+id/imageView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="42dp"

android:src="@drawable/logo" />

android:id="@+id/imageTextButton1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_centerVertical="true"

android:layout_marginLeft="16dp"

android:drawableTop="@drawable/ic_launcher"

android:text="Meal of the Day" />

我的Java代码(浓缩为简洁起见):

package com.example.c3347115app;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.MenuInflater;

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

import android.content.Intent;

public class MainActivity extends Activity {

ImageView image;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

image = (ImageView) findViewById(R.id.imageView1);

的logcat:

05-10 01:55:30.718: W/dalvikvm(13140): threadid=1: thread exiting with uncaught exception (group=0x40a99228)

05-10 01:55:30.728: E/AndroidRuntime(13140): FATAL EXCEPTION: main

05-10 01:55:30.728: E/AndroidRuntime(13140): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.c3347115app/com.example.c3347115app.MainActivity}: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.ImageView

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.ActivityThread.access$600(ActivityThread.java:139)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.os.Handler.dispatchMessage(Handler.java:99)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.os.Looper.loop(Looper.java:156)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.ActivityThread.main(ActivityThread.java:4987)

05-10 01:55:30.728: E/AndroidRuntime(13140): at java.lang.reflect.Method.invokeNative(Native Method)

05-10 01:55:30.728: E/AndroidRuntime(13140): at java.lang.reflect.Method.invoke(Method.java:511)

05-10 01:55:30.728: E/AndroidRuntime(13140): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

05-10 01:55:30.728: E/AndroidRuntime(13140): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

05-10 01:55:30.728: E/AndroidRuntime(13140): at dalvik.system.NativeStart.main(Native Method)

05-10 01:55:30.728: E/AndroidRuntime(13140): Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.ImageView

05-10 01:55:30.728: E/AndroidRuntime(13140): at com.example.c3347115app.MainActivity.onCreate(MainActivity.java:22)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.Activity.performCreate(Activity.java:4538)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)

05-10 01:55:30.728: E/AndroidRuntime(13140): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)

任何人都可以弄清楚是什么问题?提前致谢。

2013-05-10

Ciaran

+0

您能提供logcat输出吗? –

2013-05-10 00:45:50

+0

什么是崩溃的堆栈跟踪? –

2013-05-10 00:45:52

+0

提供完整的xml –

2013-05-10 00:59:11

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值