应用程序不会在Eclipse模拟器上运行

时间:2014-11-13 03:26:58

标签: java android eclipse

我正在尝试检查我在Eclipse中编写的应用程序。由于某些原因,在模拟器上无法加载。除了“不幸的是你的应用已停止”之外,它不会提供额外的信息。我无法通过logcat找出原因。如果我能得到任何帮助,我将非常感激。

这是java代码:     package net.androidbootcamp.quickhealthysnackideasapp;

import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {
    Integer[] Snacks = {R.drawable.snack1, R.drawable.snack2, R.drawable.snack3, 
            R.drawable.snack4,R.drawable.snack5};
    ImageView pic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GridView gr = (GridView)findViewById(R.id.gridView1);
        final ImageView pic = (ImageView)findViewById(R.id.imgLarge);
        gr.setAdapter(new ImageAdapter(this)); 
        gr.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(getBaseContext(), "Selected Snacks" + (arg2+1),             Toast.LENGTH_SHORT).show();
                pic.setImageResource(Snacks[arg2]);
           }

        });

        }
    public class ImageAdapter extends BaseAdapter{
    private Context context;
    public ImageAdapter(Context c) 
    {
        // TODO Auto-generated constructor stub
        context = c;
    }

        @Override
        public int getCount() {
           // TODO Auto-generated method stub
           return Snacks.length;
        }

        @Override
         public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return null;
        }

       @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            // TODO Auto-generated method stub
            pic = new ImageView(context);
            pic.setImageResource(Snacks[arg0]);
            pic.setScaleType(ImageView.ScaleType.FIT_XY);
            pic.setLayoutParams(new GridView.LayoutParams(188,200));
            return pic;
        }

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

这是xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.androidbootcamp.quickhealthysnackideasapp.MainActivity" >

<GridView
    android:id="@+id/gridView1"
    android:layout_width="wrap_content"
    android:layout_height="250dp"
    android:numColumns="3"
    android:columnWidth="100dp"
    android:horizontalSpacing= "5dp"
    android:verticalSpacing= "5dp">
</GridView>

<Imageview
    android:id="@+id/imgLarge"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/imgLarge"/>

这是logcat:

11-12 22:14:59.444: E/AndroidRuntime(884): FATAL EXCEPTION: main
11-12 22:14:59.444: E/AndroidRuntime(884): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.androidbootcamp.quickhealthysnackideasapp/net.androidbootcamp.quickhealthysnackideasapp.MainActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class Imageview
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.os.Looper.loop(Looper.java:137)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.ActivityThread.main(ActivityThread.java:5103)
11-12 22:14:59.444: E/AndroidRuntime(884):  at java.lang.reflect.Method.invokeNative(Native Method)
11-12 22:14:59.444: E/AndroidRuntime(884):  at java.lang.reflect.Method.invoke(Method.java:525)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-12 22:14:59.444: E/AndroidRuntime(884):  at dalvik.system.NativeStart.main(Native Method)
11-12 22:14:59.444: E/AndroidRuntime(884): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class Imageview
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.Activity.setContentView(Activity.java:1895)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
11-12 22:14:59.444: E/AndroidRuntime(884):  at net.androidbootcamp.quickhealthysnackideasapp.MainActivity.onCreate(MainActivity.java:26)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.Activity.performCreate(Activity.java:5133)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-12 22:14:59.444: E/AndroidRuntime(884):  ... 11 more
11-12 22:14:59.444: E/AndroidRuntime(884): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Imageview" on path: DexPathList[[zip file "/data/app/net.androidbootcamp.quickhealthysnackideasapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/net.androidbootcamp.quickhealthysnackideasapp-1, /system/lib]]
11-12 22:14:59.444: E/AndroidRuntime(884):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
11-12 22:14:59.444: E/AndroidRuntime(884):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-12 22:14:59.444: E/AndroidRuntime(884):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
11-12 22:14:59.444: E/AndroidRuntime(884):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
11-12 22:14:59.444: E/AndroidRuntime(884):  ... 24 more
11-12 22:14:59.464: W/ActivityManager(286):   Force finishing activity net.androidbootcamp.quickhealthysnackideasapp/.MainActivity
11-12 22:14:59.814: I/WindowManager(286): Screenshot max retries 4 of Token{41b91b60 ActivityRecord{419a3ad0 u0 net.androidbootcamp.quickhealthysnackideasapp/.MainActivity}} appWin=Window{41a40c28 u0 Starting net.androidbootcamp.quickhealthysnackideasapp} drawState=4
11-12 22:14:59.814: W/WindowManager(286): Screenshot failure taking screenshot for (800x1280) to layer 21010
11-12 22:15:00.624: W/ActivityManager(286): Activity pause timeout for ActivityRecord{419a3ad0 u0 net.androidbootcamp.quickhealthysnackideasapp/.MainActivity}
11-12 22:15:00.794: I/Choreographer(286): Skipped 42 frames!  The application may be doing too much work on its main thread.
11-12 22:15:01.524: I/Choreographer(405): Skipped 57 frames!  The application may be doing too much work on its main thread.
11-12 22:15:02.334: I/Process(884): Sending signal. PID: 884 SIG: 9
11-12 22:15:02.394: I/ActivityManager(286): Process net.androidbootcamp.quickhealthysnackideasapp (pid 884) has died.
11-12 22:15:02.404: E/SoundPool(286): error loading /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: E/SoundPool(286): error loading /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: E/SoundPool(286): error loading /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: E/SoundPool(286): error loading /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: E/SoundPool(286): error loading /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
11-12 22:15:02.404: E/SoundPool(286): error loading /system/media/audio/ui/KeypressStandard.ogg
11-12 22:15:02.404: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
11-12 22:15:02.414: E/SoundPool(286): error loading /system/media/audio/ui/KeypressSpacebar.ogg
11-12 22:15:02.414: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
11-12 22:15:02.414: E/SoundPool(286): error loading /system/media/audio/ui/KeypressDelete.ogg
11-12 22:15:02.414: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
11-12 22:15:02.414: E/SoundPool(286): error loading /system/media/audio/ui/KeypressReturn.ogg
11-12 22:15:02.414: W/AudioService(286): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
11-12 22:15:02.414: W/AudioService(286): onLoadSoundEffects(), Error -1 while loading samples
11-12 22:15:03.144: W/InputMethodManagerService(286): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41a39458 attribute=null, token = android.os.BinderProxy@41a4a920
11-12 22:15:04.714: I/QSB.SuggestionsProviderImpl(825): chars:0,corpora:[web, apps, com.android.contacts/.activities.PeopleActivity]
11-12 22:15:04.754: I/QSB.SuggestionsProviderImpl(825): chars:0,corpora:[web, apps, com.android.contacts/.activities.PeopleActivity]
11-12 22:19:30.394: I/ActivityManager(286): No longer want android.process.acore (pid 452): empty for 1805s
11-12 22:19:30.455: I/ActivityManager(286): Kill com.android.quicksearchbox (pid 825): provider com.android.providers.applications.ApplicationsProvider in dying process android.process.acore
11-12 22:19:30.465: I/ActivityManager(286): Kill com.android.quicksearchbox (pid 825): provider com.android.providers.contacts.ContactsProvider2 in dying process android.process.acore
11-12 22:19:30.525: I/ActivityManager(286): Process com.android.quicksearchbox (pid 825) has died.

1 个答案:

答案 0 :(得分:2)

LOL :),将您的XML更改为

<ImageView

(以大写字母V)