有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java应用程序不会在Eclipse emulator上运行

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

以下是java代码: 包装网。安卓bootcamp。quickhealthysnackideasapp

import 安卓.support.v7.app.ActionBarActivity;
import 安卓.content.Context;
import 安卓.os.Bundle;
import 安卓.view.Menu;
import 安卓.view.MenuItem;
import 安卓.view.View;
import 安卓.view.ViewGroup;
import 安卓.widget.AdapterView;
import 安卓.widget.AdapterView.OnItemClickListener;
import 安卓.widget.BaseAdapter;
import 安卓.widget.GridView;
import 安卓.widget.ImageView;
import 安卓.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:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:paddingBottom="@dimen/activity_vertical_margin"
安卓:paddingLeft="@dimen/activity_horizontal_margin"
安卓:paddingRight="@dimen/activity_horizontal_margin"
安卓:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.安卓bootcamp.quickhealthysnackideasapp.MainActivity" >

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

<Imageview
    安卓:id="@+id/imgLarge"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓: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.安卓bootcamp.quickhealthysnackideasapp/net.安卓bootcamp.quickhealthysnackideasapp.MainActivity}: 安卓.view.InflateException: Binary XML file line #21: Error inflating class Imageview
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.ActivityThread.access$600(ActivityThread.java:141)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.os.Handler.dispatchMessage(Handler.java:99)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.os.Looper.loop(Looper.java:137)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.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.安卓.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.安卓.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: 安卓.view.InflateException: Binary XML file line #21: Error inflating class Imageview
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.安卓.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.Activity.setContentView(Activity.java:1895)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
11-12 22:14:59.444: E/AndroidRuntime(884):  at net.安卓bootcamp.quickhealthysnackideasapp.MainActivity.onCreate(MainActivity.java:26)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.Activity.performCreate(Activity.java:5133)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.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 "安卓.view.Imageview" on path: DexPathList[[zip file "/data/app/net.安卓bootcamp.quickhealthysnackideasapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/net.安卓bootcamp.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 安卓.view.LayoutInflater.createView(LayoutInflater.java:559)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
11-12 22:14:59.444: E/AndroidRuntime(884):  at com.安卓.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
11-12 22:14:59.444: E/AndroidRuntime(884):  at 安卓.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.安卓bootcamp.quickhealthysnackideasapp/.MainActivity
11-12 22:14:59.814: I/WindowManager(286): Screenshot max retries 4 of Token{41b91b60 ActivityRecord{419a3ad0 u0 net.安卓bootcamp.quickhealthysnackideasapp/.MainActivity}} appWin=Window{41a40c28 u0 Starting net.安卓bootcamp.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.安卓bootcamp.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.安卓bootcamp.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.安卓.internal.view.IInputMethodClient$Stub$Proxy@41a39458 attribute=null, token = 安卓.os.BinderProxy@41a4a920
11-12 22:15:04.714: I/QSB.SuggestionsProviderImpl(825): chars:0,corpora:[web, apps, com.安卓.contacts/.activities.PeopleActivity]
11-12 22:15:04.754: I/QSB.SuggestionsProviderImpl(825): chars:0,corpora:[web, apps, com.安卓.contacts/.activities.PeopleActivity]
11-12 22:19:30.394: I/ActivityManager(286): No longer want 安卓.process.acore (pid 452): empty for 1805s
11-12 22:19:30.455: I/ActivityManager(286): Kill com.安卓.quicksearchbox (pid 825): provider com.安卓.providers.applications.ApplicationsProvider in dying process 安卓.process.acore
11-12 22:19:30.465: I/ActivityManager(286): Kill com.安卓.quicksearchbox (pid 825): provider com.安卓.providers.contacts.ContactsProvider2 in dying process 安卓.process.acore
11-12 22:19:30.525: I/ActivityManager(286): Process com.安卓.quicksearchbox (pid 825) has died.

共 (1) 个答案

  1. # 1 楼答案

    LOL:),将XML更改为

    <ImageView
    

    (大写V)