Задать вопрос
@Krakenk
Android developer

Почему вылетает приложение Android Studio?

Вылетает приложение. Изначально у меня было уже два окна, помимо основного. Сделал третье, закодил всё по видео-уроку и исходникам с гит хаба. При тесте сборка была собрана, приложение запустилось, все предыдущие окна функционируют, а вот последнее созданное окно ,при нажатии открытия, крашит приложение полность.
Если нужно будет - скину ещё.
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button btnW,btnC,btnS,btnP;

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

    public void addListenerOnButton(){
        btnW = (Button)findViewById(R.id.btnweather);
        btnC = (Button)findViewById(R.id.btnclock);
        btnS = (Button)findViewById(R.id.btnstopwatch);
        btnP = (Button)findViewById(R.id.btnplaner);
        btnW.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent("android.intent.action.WeatherAct");
                        startActivity(intent);
                    }
                }
        );

        btnC.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast toast = Toast.makeText(getApplicationContext(),
                                "Тут ДОЛЖЕН БЫТЬ будильник!", Toast.LENGTH_SHORT);
                        toast.show();
                    }
                }
        );

        btnS.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent("android.intent.action.StopwatchActivity");
                        startActivity(intent);
                    }
                }
        );

        btnP.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent("android.intent.action.planer");
                        startActivity(intent);
                    }
                }
        );
    }
}


import android.os.Bundle;

import com.example.diplomchik.R;
import com.example.diplomchik.model.Note;
import com.example.diplomchik.screens.details.NoteDetailsActivity;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import java.util.List;

public class planer extends AppCompatActivity {

    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        recyclerView = findViewById(R.id.list);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

        final Adapter adapter = new Adapter();
        recyclerView.setAdapter(adapter);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NoteDetailsActivity.start(planer.this, null);
            }
        });

        MainViewModel mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
        mainViewModel.getNoteLivedata().observe(this, new Observer<List<Note>>() {
            @Override
            public void onChanged(List<Note> notes) {
                adapter.setItems(notes);
            }
        });
    }
}


60b9e407b7ce6931031706.png

2021-06-04 11:14:50.932 30947-30947/com.example.diplomchik D/AndroidRuntime: Shutting down VM
2021-06-04 11:14:50.934 30947-30947/com.example.diplomchik E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.diplomchik, PID: 30947
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.diplomchik/com.example.diplomchik.screens.main.planer}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3534)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3689)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2239)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:227)
        at android.app.ActivityThread.main(ActivityThread.java:7822)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
        at com.example.diplomchik.screens.main.planer.onCreate(planer.java:38)
        at android.app.Activity.performCreate(Activity.java:7963)
        at android.app.Activity.performCreate(Activity.java:7952)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3505)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3689) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2239) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:227) 
        at android.app.ActivityThread.main(ActivityThread.java:7822) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026) 
2021-06-04 11:14:50.972 30947-30947/com.example.diplomchik I/Process: Sending signal. PID: 30947 SIG: 9
  • Вопрос задан
  • 2510 просмотров
Подписаться 1 Простой Комментировать
Решения вопроса 1
@acwartz
Тут должна быть ваша реклама.
<b>recyclerView = findViewById(R.id.list);</b>
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
<b>recyclerView.setLayoutManager</b>(linearLayoutManager);

Проверяйте смогли ли получить ожидаемый объект recyclerView, и только потом делайте работу. У вас ошибка о том что пытаетесь вызвать метод setLayoutManager у несуществующего объекта.
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@Krakenk Автор вопроса
Android developer
Логи прилагаю, сомневаюсь, что на скрине будет видно
2021-06-04 11:14:45.926 30947-30947/? E/mple.diplomchi: Unknown bits set in runtime_flags: 0x8000
2021-06-04 11:14:46.636 30947-30947/com.example.diplomchik W/mple.diplomchi: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-06-04 11:14:46.637 30947-30947/com.example.diplomchik W/mple.diplomchi: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-06-04 11:14:46.728 30947-30947/com.example.diplomchik I/SurfaceFactory: [static] sSurfaceFactory = com.mediatek.view.impl.SurfaceFactoryImpl@35bb057
2021-06-04 11:14:46.747 30947-30947/com.example.diplomchik D/WindowManager: Add to mViews: DecorView@faf3[MainActivity], this = android.view.WindowManagerGlobal@7d313b0,pkg= com.example.diplomchik
2021-06-04 11:14:46.757 30947-30947/com.example.diplomchik D/ViewRootImpl[MainActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
2021-06-04 11:14:46.765 30947-30947/com.example.diplomchik I/InputTransport: Create ARC handle: 0x7ca58fb000
2021-06-04 11:14:46.766 30947-30947/com.example.diplomchik V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@8a709ae, this = DecorView@faf3[MainActivity]
2021-06-04 11:14:46.856 30947-31037/com.example.diplomchik E/EGL-gift: Cannot load register apis
2021-06-04 11:14:46.865 30947-31037/com.example.diplomchik D/Surface: Surface::connect(this=0x7d3d9d8000,api=1)
2021-06-04 11:14:46.869 30947-31037/com.example.diplomchik D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2021-06-04 11:14:46.870 30947-31037/com.example.diplomchik D/Surface: Surface::setBufferCount(this=0x7d3d9d8000,bufferCount=4)
2021-06-04 11:14:46.870 30947-31037/com.example.diplomchik D/Surface: Surface::allocateBuffers(this=0x7d3d9d8000)
2021-06-04 11:14:46.912 30947-31037/com.example.diplomchik W/Gralloc3: mapper 3.x is not supported
2021-06-04 11:14:46.916 30947-31037/com.example.diplomchik E/gralloc: Arm Module v1.0
2021-06-04 11:14:46.917 30947-31037/com.example.diplomchik E/ion: ioctl c0044901 failed with code -1: Invalid argument
2021-06-04 11:14:46.918 30947-31037/com.example.diplomchik W/gralloc: WARNING: internal format modifier bits not mutually exclusive. AFBC basic bit is always set, so extended AFBC support bits must always be checked.
2021-06-04 11:14:47.151 30947-30947/com.example.diplomchik I/Choreographer: Skipped 32 frames!  The application may be doing too much work on its main thread.
2021-06-04 11:14:47.181 30947-30947/com.example.diplomchik I/Choreographer: Skipped 1 frames!  The application may be doing too much work on its main thread.
2021-06-04 11:14:50.788 30947-30947/com.example.diplomchik D/ColorViewRootUtil: nav bar mode ignore false downX 841 downY 1504 mScreenHeight 2400 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 0 rotation 0 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=841.0, y[0]=1504.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=603551068, downTime=603551068, deviceId=4, source=0x1002, displayId=0 }
2021-06-04 11:14:50.854 30947-30947/com.example.diplomchik I/Choreographer: Skipped 1 frames!  The application may be doing too much work on its main thread.
2021-06-04 11:14:50.874 30947-30947/com.example.diplomchik W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@56737a4
2021-06-04 11:14:50.932 30947-30947/com.example.diplomchik D/AndroidRuntime: Shutting down VM
2021-06-04 11:14:50.934 30947-30947/com.example.diplomchik E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.diplomchik, PID: 30947
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.diplomchik/com.example.diplomchik.screens.main.planer}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3534)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3689)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2239)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:227)
        at android.app.ActivityThread.main(ActivityThread.java:7822)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
        at com.example.diplomchik.screens.main.planer.onCreate(planer.java:38)
        at android.app.Activity.performCreate(Activity.java:7963)
        at android.app.Activity.performCreate(Activity.java:7952)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3505)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3689) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2239) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:227) 
        at android.app.ActivityThread.main(ActivityThread.java:7822) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026) 
2021-06-04 11:14:50.972 30947-30947/com.example.diplomchik I/Process: Sending signal. PID: 30947 SIG: 9
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы