Форум программистов, компьютерный форум CyberForum.ru

Программирование Android

Войти
Регистрация
Восстановить пароль
 
VladimirFA51
7 / 2 / 1
Регистрация: 07.11.2015
Сообщений: 17
#1

FATAL EXCEPTION: main - Android

07.11.2015, 20:02. Просмотров 19. Ответов 0
Метки нет (Все метки)

Всем привет,решил сделать небольшое приложение.Возникла проблема с ListView.С главного экрана меня переправляет на main.class,в котором отображается main.xml. Там Я создаю лист и заполняю его данными,но выбивает ошибку FATAL EXCEPTION: main.Заранее спасибо!
Вот код:

menu.class:
Код
public class menu extends Activity {
    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);
        //Название строковых констант,которые мы будем брать для адаптера.
        final String IMAGE_OF_FOOD = "imageoffoods";
        final String DESCRIBE_OF_FOOD = "describeoffood";
        final String PRICE_OF_FOOD = "priceoffood";

        //Массивы с изображением,описанием,ценой блюда.
        int[] images = {R.drawable.fish, R.drawable.meat, R.drawable.pot, R.drawable.cocacola, R.drawable.tea};
        String[] descriptions = {"Запечёная рыба", "Мясо барбекю", "Картошка фри", "Кока-кола", "Фруктовый чай"};
        int[] prices = {200, 150, 150, 60, 50};

        //Листвью .
        ListView MenuList;


    //Создаём ArrayList длинной такой же , как и у descriptions массива.
        ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(descriptions.length);

        Map<String, Object> m; //Задаём m для облегчения записи

        for (int i = 0; i < descriptions.length; i++) { //Цикл "for".
            m = new HashMap<String, Object>(); //Создаём хешмап m.
            m.put(IMAGE_OF_FOOD, images[i]); //Упаковываем в IMAGE_OF_FOOD картинку[i]
            m.put(DESCRIBE_OF_FOOD, descriptions[i]);//Упаковываем в DESCRIBE_OF_FOOD описание[i]
            m.put(PRICE_OF_FOOD, prices[i]);//Упаковываем в PRICE_OF_FOOD цену[i]
            data.add(m); //Заносим хешмап в дату.
        }

        //Определяем массивы from[]
        String[] from = {IMAGE_OF_FOOD, DESCRIBE_OF_FOOD, PRICE_OF_FOOD};

        //И to[]
        int[] to = {R.id.imageoffood, R.id.description, R.id.price};

        //Создаём SimpleAdapter adapter.
        SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.items, from, to);
        //Находим ListView
        MenuList = (ListView) findViewById(R.id.listView);
        //Меняем адаптер.
        MenuList.setAdapter(adapter);
    }
}
items.xml
Код
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <ImageView
        android:layout_width="109dp"
        android:layout_height="35dp"
        android:id="@+id/imageoffood" />

    <TextView
        android:layout_width="90dp"
        android:layout_height="72dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/description"
        android:textStyle="bold"
        android:layout_weight="0.32" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="72dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/price"
        android:textStyle="bold" />

</LinearLayout>
menu.xml:
Код
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
Полный код ошибки:
Код
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime: FATAL EXCEPTION: main
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime: java.lang.OutOfMemoryError
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:501)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:354)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.content.res.Resources.loadDrawable(Resources.java:1970)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.content.res.Resources.getDrawable(Resources.java:660)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.ImageView.resolveUri(ImageView.java:616)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.ImageView.setImageResource(ImageView.java:349)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.SimpleAdapter.setViewImage(SimpleAdapter.java:240)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:190)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.AbsListView.obtainView(AbsListView.java:2159)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.ListView.makeAndAddView(ListView.java:1831)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.ListView.fillDown(ListView.java:674)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.ListView.fillFromTop(ListView.java:735)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.ListView.layoutChildren(ListView.java:1652)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.AbsListView.onLayout(AbsListView.java:1994)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.View.layout(View.java:14008)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4373)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.View.layout(View.java:14008)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4373)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.View.layout(View.java:14008)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4373)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.View.layout(View.java:14008)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4373)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.View.layout(View.java:14008)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4373)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:532)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:725)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5041)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-07 16:00:07.362 9204-9204/com.develope.vladimir.mycafeindallas E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
Similar
Эксперт
41792 / 34177 / 6122
Регистрация: 12.04.2006
Сообщений: 57,940
07.11.2015, 20:02     FATAL EXCEPTION: main
Посмотрите здесь:

Android FATAL EXCEPTION: main
FATAL EXCEPTION: main Android
FATAL EXCEPTION: main Android
Android FATAL EXCEPTION: main java.lang.NullPointerException
Android Fatal Exception: main
Android FATAL EXCEPTION: main
Android FATAL EXCEPTION: main, приложение компилируется, но не запускается
Android FATAL EXCEPTION: main
FATAL EXCEPTION: main - проклятая ошибка Android
FATAL EXCEPTION: main Android
E/AndroidRuntime: FATAL EXCEPTION: main Android
E/AndroidRuntime: FATAL EXCEPTION: main Android

Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума.
Ответ Создать тему
Опции темы

Текущее время: 00:01. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Рейтинг@Mail.ru