Приложение вылетает при открытии в эмуляторе

#android #android-emulator #crash #android-studio

#Android #android-эмулятор #сбой #android-studio

Вопрос:

Всякий раз, когда я пытаюсь запустить это приложение в эмуляторе, оно всегда вылетает, и я не могу понять, почему!

PS Я очень новичок в разработке приложений для Android, поэтому, вероятно, уже допустил около дюжины ошибок, поэтому, пожалуйста, проявите понимание!

Logcat:

 06-29 01:16:30.719      392-406/system_process I/Choreographer﹕ Skipped 41 frames!  The application may be doing too much work on its main thread.
06-29 01:16:30.889    1195-1195/com.trial.contactmanager I/Process﹕ Sending signal. PID: 1195 SIG: 9
06-29 01:16:30.929      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.929      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.939      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.939      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
06-29 01:16:30.939      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/KeypressStandard.ogg
06-29 01:16:30.939      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
06-29 01:16:30.939      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/KeypressSpacebar.ogg
06-29 01:16:30.939      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
06-29 01:16:30.939      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/KeypressDelete.ogg
06-29 01:16:30.939      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
06-29 01:16:30.939      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/KeypressReturn.ogg
06-29 01:16:30.949      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
06-29 01:16:30.949      392-436/system_process E/SoundPool﹕ error loading /system/media/audio/ui/KeypressInvalid.ogg
06-29 01:16:30.949      392-436/system_process W/AudioService﹕ Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
06-29 01:16:30.949      392-436/system_process W/AudioService﹕ onLoadSoundEffects(), Error -1 while loading samples
06-29 01:16:31.109      392-407/system_process I/Choreographer﹕ Skipped 58 frames!  The application may be doing too much work on its main thread.
06-29 01:16:31.489      392-614/system_process I/ActivityManager﹕ Process com.trial.contactmanager (pid 1195) has died.
06-29 01:16:31.559      392-404/system_process W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b420dad0 attribute=null, token = android.os.BinderProxy@b4023778
06-29 01:30:01.049      392-431/system_process D/ConnectivityService﹕ Sampling interval elapsed, updating statistics ..
06-29 01:30:01.059      392-431/system_process D/ConnectivityService﹕ Done.
06-29 01:30:01.079      392-431/system_process D/ConnectivityService﹕ Setting timer for 720seconds
  

Вот мой код:

 package com.trial.contactmanager;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;

public class MainActivity extends Activity {

    EditText name, phone, email, address;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }

        name = (EditText) findViewById(R.id.name);
        phone = (EditText) findViewById(R.id.phone);
        email = (EditText) findViewById(R.id.email);
        address = (EditText) findViewById(R.id.address);
        final Button add_btn = (Button) findViewById(R.id.add_btn);
        TabHost tabHost = (TabHost) findViewById(R.id.tabHost);


        tabHost.setup();

        TabHost.TabSpec tabSpec = tabHost.newTabSpec("creator");
        tabSpec.setContent(R.id.tabCreate);
        tabSpec.setIndicator("Creator");
        tabHost.addTab(tabSpec);


        tabSpec = tabHost.newTabSpec("list");
        tabSpec.setContent(R.id.tabList);
        tabSpec.setIndicator("List");
        tabHost.addTab(tabSpec);







        name.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                add_btn.setEnabled(!name.getText().toString().trim().isEmpty());

            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }


    @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) {

        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}
  

Комментарии:

1. Ну, ошибка № 1 в том, что вы пропустили трассировку стека в logcat 🙂

2. Я думаю, что проблема заключается в использовании фрагмента и активности, как и у многих других пользователей, весь ваш виджет находится в fragment_activity, но вы пытаетесь получить это в классе activity,

3. Я понятия не имею, что все это значит! Как я уже сказал, я N00B