your programing

불행히도 MyApp이 중지되었습니다.

lovepro 2020. 9. 29. 08:16
반응형

불행히도 MyApp이 중지되었습니다. 어떻게 해결할 수 있습니까?


응용 프로그램을 개발 중이며 실행할 때마다 다음 메시지가 표시됩니다.

불행히도 MyApp이 중지되었습니다.

이 문제를 해결하려면 어떻게해야합니까?


이 질문에 대해-분명히 스택 추적이란 무엇이며 애플리케이션 오류를 디버깅하는 데 어떻게 사용할 수 있습니까? , 추가 세부 사항없이 응용 프로그램이 충돌했음을 나타내는 많은 질문이 있습니다. 이 질문은 초보자 Android 프로그래머에게 문제를 스스로 해결하거나 올바른 질문을하는 방법을 가르치는 데 목적이 있습니다.


이 답변은 스택 추적을 검색하는 프로세스를 설명합니다. 이미 스택 추적이 있습니까? " 스택 추적이란 무엇이며이를 사용하여 애플리케이션 오류를 디버그하려면 어떻게해야합니까? " 에서 스택 추적에 대해 읽어보십시오.

문제

잡히지 않은 항목 RuntimeException이 발생 하여 응용 프로그램이 종료되었습니다 .
이들 중 가장 일반적인 것은 NullPointerException.

그것을 해결하는 방법?

Android 애플리케이션 (또는 해당 문제에 대한 모든 Java 애플리케이션)이 충돌 할 때마다 Stack trace콘솔 (이 경우 logcat)에 a 가 기록됩니다. 이 스택 추적에는 문제 해결을위한 중요한 정보가 포함되어 있습니다.

안드로이드 스튜디오

Android Studio에서 스택 추적 찾기

창의 하단 표시 줄에서 Logcat버튼을 클릭 합니다. 또는 alt+ 를 누를 수 있습니다 6. Devices패널 에서 에뮬레이터 또는 장치가 선택되어 있는지 확인하십시오 . 다음으로 빨간색으로 표시된 스택 추적을 찾으십시오. logcat에 로그인 된 항목이 많을 수 있으므로 약간 스크롤해야 할 수 있습니다. 스택 추적을 찾는 쉬운 방법은 logcat을 지우고 (오른쪽의 휴지통 사용) 앱이 다시 충돌하도록하는 것입니다.

스택 추적을 찾았습니다. 이제 무엇입니까?

예이! 문제 해결의 중간입니다.
스택 추적을 분석하여 정확히 애플리케이션 충돌을 일으킨 원인을 알아 내면됩니다.

" 스택 추적이란 무엇이며이를 사용하여 애플리케이션 오류를 디버그하려면 어떻게해야합니까? " 에서 스택 추적에 대해 읽어보십시오.

여전히 문제를 해결할 수 없습니다!

당신 Exception과 그것이 발생한 라인을 찾았 지만 여전히 그것을 고치는 방법을 찾을 수 없다면 , 주저하지 말고 StackOverflow에 질문하십시오.

가능한 한 간결하게 작성하십시오. 스택 추적 및 관련 코드를 게시하십시오 (예 :를 던진 행까지 몇 행 Exception).


당신이 사용할 수있는 구글의 ADB 도구를 얻기 위해 Logcat file문제를 분석 할 수 있습니다.

adb logcat > logcat.txt

logcat.txt파일을 열고 응용 프로그램 이름을 검색하십시오. 실패한 이유, 줄 번호, 클래스 이름 등에 대한 정보가 있어야합니다.


먼저 앱이 충돌 한 지점 ( Unfortunately, MyApp has stopped.)을 확인합니다. 이를 위해를 사용할 Log.e("TAG", "Message");수 있으며이 줄을 사용하면 logcat에서 앱 로그인을 볼 수 있습니다.

그 후에 앱이 중지 된 지점을 발견하면 사용자 측에서 해결하기가 매우 쉽습니다.


log cat에서 오류를 확인하십시오.

Eclipse에서 log cat 옵션을 얻습니다.

window-> show view-> others-> Android-> Logcat

로그 고양이에 오류가 있습니다.

그렇지 않으면 디버그 모드에서 응용 프로그램을 실행하여 오류를 확인할 수도 있습니다. 먼저 다음을 수행하여 중단 점을 설정하십시오.

project-> debug as-> Android application을 마우스 오른쪽 버튼으로 클릭하십시오.


참고 : 이 답변은 Android Studio 2.2.2를 사용하고 있습니다.

참고 2 : 귀하의 장치가 성공적으로 연결되었다고 생각하고 있습니다.


애플리케이션이 충돌 할 때 가장 먼저하는 일은 LogCat을 살펴 보는 것입니다. Android Studio 하단에는 메뉴 목록이있는 툴바가 있습니다.

영상

"안드로이드 모니터"를 클릭하세요. (위 이미지에 밑줄이 그어진 것입니다. ^)

이제 다음과 같은 결과를 얻을 수 있습니다.

영상

" Verbose"을 " Error"로 변경하십시오. 이제 기록 된 오류 만 표시됩니다. 지금 이러한 모든 오류에 대해 걱정하지 마십시오 (발생한 경우).

영상

확인. 이제 앱을 충돌시키기 위해 한 일을하십시오. 앱이 다운되면 logcat으로 이동합니다. 새 충돌을 많이 가지고 로그 찾을 수 있어야 at:x.x.x하고 : Caused by: TrumpIsPresidentException예 :. Caused by:logcat의 해당 진술로 이동 하십시오.

영상

다음에Caused By:, 일어난 예외가 있어야한다. 제 경우에는 a RuntimeException이고 그 아래에는 다음 과 같은 파란색 링크 가 포함 된 줄이 있어야합니다 .

영상

Caused by:그 아래 어딘가에 파란색 텍스트가있는 줄이 없으면 다른 줄을 찾으십시오 Caused by:.

파란색 링크를 클릭 합니다. 문제가 발생한 위치로 이동해야합니다. 제 경우에는 다음 줄 때문입니다.

throw new RuntimeException();

이제 나는 그것이 왜 충돌하는지 압니다. 내가 직접 예외를 던지기 때문입니다. 이것은 명백한 오류 였습니다.


그러나 다른 오류가 발생했다고 가정 해 보겠습니다.

java.lang.NullPointerException

내 logcat을 확인하고 파란색 링크를 클릭하면 여기로 이동했습니다.

mTextView.setText(myString);

이제 디버그하고 싶습니다. 이 StackOverflow 질문 에 따르면 NullPointerException은 무언가가 있다고 말합니다 null.

그래서 null이 무엇인지 알아 봅시다 . 두 가지 가능성이 있습니다. 어느 쪽이 mTextViewnull의 경우, 또는 myStringnull입니다. 확인하기 위해 mTextView.setText(mString)앞에 다음 두 줄을 추가합니다.

Log.d("AppDebug","mTextView is null: " + String.valueOf(mTextView == null);
Log.d("AppDebug","myString is null: " + String.valueOf(myString== null);

이제 이전에했던 것처럼 (Verose를 오류로 변경) "오류"를 "디버그"로 변경하려고합니다. 디버깅으로 로깅하기 때문입니다. 모든 Log 메서드는 다음과 같습니다.

Log.
  d means Debug
  e means error
  w means warning
  v means verbose
  i means information
  wtf means "What a terrible failure". This is similar to Log.e

그래서 Log.d우리는를 사용했기 때문에 Debug를 확인하고 있습니다. 이것이 우리가 디버그하도록 변경 한 이유입니다.

알림 Log.d에는 첫 번째 매개 변수가 있습니다. 여기서는 "AppDebug"입니다. logcat의 오른쪽 상단에있는 "No Filters"드롭 다운 메뉴를 클릭하십시오. "Edit Filter Configuration"을 선택하고 필터에 이름을 지정한 다음 "Log Tag"에 "App Debug"를 입력합니다. "확인"을 클릭하십시오. 이제 logcat에 두 줄이 표시됩니다.

yourPackageNameAndApp: mTextView is null: true
yourPackageNameAndApp: myString is null: false

이제 우리는 mTextView가 null임을 압니다.

나는 내 코드를 관찰하고 이제 무언가를 발견했습니다.

나는 private TextView mTextView내 수업의 최상위에 선언했습니다. 그러나 나는 그것을 정의하지 않습니다.

기본적으로 내 onCreate ()에서 이것을하는 것을 잊었습니다.

mTextView = (TextView) findViewById(R.id.textview_id_in_xml);

그래서 그것이 mTextViewnull 인 이유입니다. 제 앱이 무엇인지 말하는 것을 잊었 기 때문입니다. 그래서 그 줄을 추가하고 내 앱을 실행하면 앱이 충돌하지 않습니다.



이 팝업은 코드에서 앱 실행을 중지하는 치명적인 예외가 발생한 경우에만 표시됩니다. 그것은 예외가 될 수 NullPointerException, OutOfMemoryException

확인하는 가장 좋은 방법은 스택 추적을 읽고 앱의 원인을 확인하는 빠른 방법 인 Android 스튜디오에서 앱을 아직 개발중인 경우 Logcat을 사용 하는 것입니다.

앱이 이미 라이브 상태이면 logcat을 사용할 수 없습니다 . 따라서 Crashlytics발생하는 모든 예외에 대한 버그 보고서를 제공하도록 구현할 수 있습니다 .


Logcat메시지를 확인 하고 Manifest파일을 확인하십시오 . Activity,사용자 권한을 정의하는 것과 같은 누락 된 것이 있어야합니다 .


다음 도구 중 하나를 사용할 수 있습니다.

  1. adb logcat

  2. adb logcat> logs.txt (편집기를 사용하여 오류를 열고 검색 할 수 있습니다.)

  3. eclipse logcat (eclipse에 표시되지 않으면 Windows-> Show View-> Others-> Android-> LogCat으로 이동)

  4. Android Debug Monitor 또는 Android Device Monitor (명령 모니터 입력 또는 UI를 통해 열기)

여기에 이미지 설명 입력

  1. 안드로이드 스튜디오

Android Debug Monitor 를 사용 하는 것이 좋습니다. 너무 많은 로그가 있고 adb logcat 필터를 통해 모두 어려울 때 Eclipse가 중단되기 때문입니다.


당신은 확인해야 Stack trace

그렇게하는 방법?

IDE에서 Windows 양식 LOGCAT 확인

logcat 창이 보이지 않으면이 경로로 이동하여 엽니 다.

window->show view->others->Android->Logcat

Google-Api를 사용하는 경우이 경로로 이동

adb logcat> logcat.txt


아래 showToast () 메서드에서 컨텍스트 또는 응용 프로그램 컨텍스트에 대한 다른 매개 변수를 전달해야하므로 시도해 볼 수 있습니다.

  public void showToast(String error, Context applicationContext){
        LayoutInflater inflater = getLayoutInflater();
        View view = inflater.inflate(R.layout.custom_toast, (ViewGroup)      
        findViewById(R.id.toast_root));
        TextView text = (TextView) findViewById(R.id.toast_error);
        text.setText(error);
        Toast toast = new Toast(applicationContext);
        toast.setGravity(Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(view);
        toast.show();
}

강제 종료 (앱 작동이 중지 될 때)를 만날 때에 대한 기본적인 Logcat 분석을 공유하겠습니다.

문서

Basic tool from Android to collect/analyse logs is the logcat.

HERE is the Android's page about logcat

If you use android Studio, you can also check this LINK.

Capturing

Basically, you can MANUALLY capture logcat with following command (or just check AndroidMonitor window in AndroidStudio):

adb logcat

There's a lot of parameters you can add to command which helps you to filter and display the message that you want... This is personal... I always use the command below to get the message timestamp:

adb logcat -v time

You can redirect the output to a file and analyze it in a Text Editor.

Analyzing

If you app is Crashing, you'll get something like:

07-09 08:29:13.474 21144-21144/com.example.khan.abc D/AndroidRuntime: Shutting down VM
07-09 08:29:13.475 21144-21144/com.example.khan.abc E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.khan.abc, PID: 21144
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference
     at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)
     at android.view.View.performClick(View.java:4848)
     at android.view.View$PerformClick.run(View.java:20262)
     at android.os.Handler.handleCallback(Handler.java:815)
     at android.os.Handler.dispatchMessage(Handler.java:104)
     at android.os.Looper.loop(Looper.java:194)
     at android.app.ActivityThread.main(ActivityThread.java:5631)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-09 08:29:15.195 21144-21144/com.example.khan.abc I/Process: Sending signal. PID: 21144 SIG: 9

This part of the log shows you a lot of information:

  • When the issue happened: 07-09 08:29:13.475

It is important to check when the issue happened... You may find several errors in a log... you must be sure that you are checking the proper messages :)

  • Which app crashed: com.example.khan.abc

This way, you know which app crashed (to be sure that you are checking the logs about your message)

  • Which ERROR: java.lang.NullPointerException

A NULL Pointer Exception error

  • Detailed info about the error: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.onBackPressed()' on a null object reference

You tried to call method onBackPressed() from a FragmentActivity object. However, that object was null when you did it.

  • Stack Trace: Stack Trace shows you the method invocation order... Sometimes, the error happens in the calling method (and not in the called method).

    at com.example.khan.abc.AudioFragment$1.onClick(AudioFragment.java:125)

Error happened in file com.example.khan.abc.AudioFragment.java, inside onClick() method at line: 125 (stacktrace shows the line that error happened)

It was called by:

at android.view.View.performClick(View.java:4848)

Which was called by:

at android.view.View$PerformClick.run(View.java:20262)

which was called by:

at android.os.Handler.handleCallback(Handler.java:815)

etc....

Overview

This was just an overview... Not all logs are simple etc... It is just to share the idea and provide a entry-level information to you...

I hope I could help you someway... Regards


Use the LogCat and try to find what is causing the app to crash.

To see Logcat if you use Android Studio then Press ALT + 6 or

if you use Eclipse then Window -> Open Perspective -> Other - LogCat

Go to the LogCat, from the drop down menu select error. This will contain all the required information to help you debug. If that doesn't help, post the LogCat as an edit to your question and somebody will help you out.


If your app for some reason crashes without good stacktrace. Try debug it from first line, and go line by line until crash. Then you will have answer, which line is causing you trouble. Proably you could then wrapp it into try catch block and print error output.


You can also get this error message on its own, without any stack trace or any further error message.

In this case you need to make sure your Android manifest is configured correctly (including any manifest merging happening from a library and any activity that would come from a library), and pay particular attention to the first activity displayed in your application in your manifest files.


Crash during development

Try my favourite tool logview to get the logs and analyze them during development.
Make sure to mark ./logview and ./lib/logview.jar as executable when running in Linux.

If you don't like it, there're a lot of alternative desktop log viewers for Android.

Crash in the wild

Integrate a real-time crash reporting tool such as Firebase Crashlytics in order to get stacktraces of unhandled exceptions which occurred on users' devices.

Read How to Release a Buggy App (And Live to Tell the Tale) to know more about handling bugs in the field.


People make mistakes, and so coding as well.

When ever any error happened, always check with the logcat with the text in red color however u can find out the real problem in blue color text with underline in those red color text.

Make sure if u create a new activity, always declare the activity in the AndroidManifest file.

If adding Permission, declare it in the AndroidMainifest file as well.


Logcat - To check the logs in the development phase of Android Studio

Initially clear the Logcat and let the app crash again so you can get only crashed log detail. You have to check the Stack trace

While, Unfortunately, MyApp has stopped. There are many reasons for it. You can check same in logs. For this, you can use the Log.e("TAG","Message");

Common error during app crash like:

  1. Coding mistake(Wrong use of keywords).
  2. Mismatch property name.
  3. Unsupported plugin(maybe).
  4. Mismatch version(maybe).
  5. Activity missing in AndroidManifest file.
  6. Permission missing in AndroidManifest file.
  7. Most common NullPointerException.
  8. Declared but not defined.

To resolve app crash error:

  • Keep in mind above points and go through it.
  • With the error, you will get the file name also in blue colour (click on them and jump to code from error is occurring).

First, you need to check where and why your app has been crashed (Unfortunately, MyApp has stopped.). With the help of LOG, you can figure it out what went wrong.

After that, you find which point your app has stopped fix that from your point.


터미널에 흥미로운 로그가없는 경우 (또는 앱과 직접 관련이없는 경우) 네이티브 라이브러리로 인한 문제 일 수 있습니다. 이 경우 터미널에서 "삭제 표시"파일을 확인해야합니다.

tombstone 파일의 기본 위치는 모든 장치에 따라 다르지만이 경우 다음과 같은 로그가 표시됩니다. Tombstone written to: /data/tombstones/tombstone_06

자세한 내용은 https://source.android.com/devices/tech/debug 에서 확인 하세요 .

참고 URL : https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this

반응형