不幸的是,MyApp停止了。我该如何解决?

发布于 2025-01-18 20:04:39 字数 388 浏览 1 评论 0 原文

我正在开发一个应用程序,每次运行它时,我都会收到以下消息:

不幸的是,MyApp 已停止。

我能做什么来解决这个问题?


关于这个问题 - 显然是受到 什么是堆栈跟踪,如何使用它来调试我的应用程序错误?,有很多问题表明他们的应用程序已崩溃,但没有任何进一步的详细信息。这个问题旨在指导新手 Android 程序员如何尝试自己解决问题,或者提出正确的问题。

I am developing an application, and everytime I run it, I get the message:

Unfortunately, MyApp has stopped.

What can I do to solve this?


About this question - obviously inspired by What is a stack trace, and how can I use it to debug my application errors?, there are lots of questions stating that their application has crashed, without any further detail. This question aims to instruct novice Android programmers on how to try and fix their problems themselves, or ask the right questions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(23

第几種人 2025-01-25 20:04:40

首先,您需要检查应用程序崩溃的位置和原因(不幸的是,MyApp 已停止。)。LOG的帮助下,您可以弄清楚发生了什么错误的。

之后,您会发现您的应用程序已停止从您的点修复该点。

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.

执妄 2025-01-25 20:04:40

另外,在终端中运行此命令可以帮助找到问题:

gradlew build > log.txt 2>details.txt

然后您应该转到 gradlew 文件位置读取上述两个日志文件。

Also running this command in terminal can help find the problem:

gradlew build > log.txt 2>details.txt

then you should go to gradlew file location in read two above log files.

旧伤慢歌 2025-01-25 20:04:40

我会建议这样的东西。

  1. 检查您的手机是否具有足够好的空间,该应用程序可以运行-----先验/

  2. 在应用程序崩溃时检查LogCat。它将显示应用程序崩溃的确切行。

  3. 检查您是否在主线程上使用了由于ANR而使用大量内存的东西。

I'll Suggest something like this.

  1. Check if your phone has good enough space that the app can run----prior/

  2. Check the logcat when the app crashes. It will show the exact line where the app crashed.

  3. Check if you are using something on the main thread that uses a lot of memory due to ANR.

狼亦尘 2025-01-25 20:04:40

检查您的 logcat 消息。另外,请参阅您的 castest file 对于诸如定义 >活动,用户许可等。

如果使用 Android Studio ,请参见LogCat,然后按 alt+6 < /em>
或者,

如果您使用 Eclipse ,则
窗口 - &gt;开放透视 - &gt;其他 - logcat

现在,从下拉菜单中选择错误。

另外 ,您可以使用 ADB工具获取 logcat文件以分析问题。

adb logcat > logcat.txt

现在,打开 logcat.txt 文件,然后搜索您的应用程序名称。应该有有关为什么失败的信息,行号,班级名称等。

Check your Logcat message. Also, see your Manifest file for missing elements like defining the Activity, User permission, etc.

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

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

Now, from the drop-down menu select error.

Alternatively, you can use ADB tool to get the Logcat file to analyze the issue.

adb logcat > logcat.txt

Now open the logcat.txt file and search for your application name. There should be information on why it failed, the line number, Class name, etc.

柠檬色的秋千 2025-01-25 20:04:40

如果您的应用程序崩溃了没有任何错误,而您没有使用资产管理器,而是加载了类似的纹理:

Texture texture = new Texture("myImage.png"); //dont to this all the time

那就是问题所在。我发生了这种情况。您应始终使用资产管理器来避免内存超负荷。

If your app crashed without any errors, and you didn't use an asset manager but loaded the textures like:

Texture texture = new Texture("myImage.png"); //dont to this all the time

then that's the problem. I had that happen to me. You should always use an asset manager to avoid a memory overload.

如梦初醒的夏天 2025-01-25 20:04:39

这个答案描述了检索堆栈跟踪的过程。已经有堆栈跟踪了吗?阅读“什么是堆栈跟踪,如何使用它来调试我的应用程序错误?"

问题

您的应用程序因未捕获的 RuntimeException 而退出被扔了。
其中最常见的是 NullPointerException< /代码>

怎么解决呢?

每次 Android 应用程序崩溃(或任何 Java 应用程序崩溃)时,堆栈跟踪都会写入控制台(在本例中为 logcat)。该堆栈跟踪包含解决您的问题的重要信息。

Android Studio

在 Android Studio 中查找堆栈跟踪

在窗口底部栏中,单击 Logcat 按钮。或者,您可以按 alt+6。确保在设备面板中选择您的模拟器或设备。接下来,尝试查找堆栈跟踪,它以红色显示。 logcat 中可能记录了很多内容,因此您可能需要滚动一下。找到堆栈跟踪的一个简单方法是清除 logcat(使用右侧的回收站),然后让应用程序再次崩溃。

我找到了堆栈跟踪,现在怎么办?

耶!您的问题已经解决了一半。
您只需要通过分析堆栈跟踪来找出到底是什么导致您的应用程序崩溃。

阅读“什么是堆栈跟踪,如何使用它来调试我的应用程序错误?

我仍然无法解决我的问题!

如果您找到异常以及发生该异常的行,但仍然无法弄清楚如何修复它,请随时在 StackOverflow 上提问。

尝试尽可能简洁:发布堆栈跟踪和相关代码(例如,直到引发异常的行为止的几行)。

This answer describes the process of retrieving the stack trace. Already have the stack trace? Read up on stack traces in "What is a stack trace, and how can I use it to debug my application errors?"

The Problem

Your application quit because an uncaught RuntimeException was thrown.
The most common of these is the NullPointerException.

How to solve it?

Every time an Android application crashes (or any Java application for that matter), a Stack trace is written to the console (in this case, logcat). This stack trace contains vital information for solving your problem.

Android Studio

Finding the stack trace in Android Studio

In the bottom bar of the window, click on the Logcat button. Alternatively, you can press alt+6. Make sure your emulator or device is selected in the Devices panel. Next, try to find the stack trace, which is shown in red. There may be a lot of stuff logged into logcat, so you may need to scroll a bit. An easy way to find the stack trace is to clear the logcat (using the recycle bin on the right), and let the app crash again.

I have found the stack trace, now what?

Yay! You're halfway to solving your problem.
You only need to find out what exactly made your application crash, by analyzing the stack trace.

Read up on stack traces in "What is a stack trace, and how can I use it to debug my application errors?"

I still can't solve my problem!

If you've found your Exception and the line where it occurred, and still cannot figure out how to fix it, don't hesitate to ask a question on StackOverflow.

Try to be as concise as possible: post the stack trace, and the relevant code (e.g. a few lines up to the line which threw the Exception).

奈何桥上唱咆哮 2025-01-25 20:04:39

您可以使用Google的ADB工具获取Logcat文件 来分析问题。

adb logcat > logcat.txt

打开 logcat.txt 文件并搜索您的应用程序名称。应该有关于失败原因、行号、类名等的信息。

You can use Google's ADB tool to get Logcat file to analyze the issue.

adb logcat > logcat.txt

open logcat.txt file and search for your application name. There should be information on why it failed, the line number, Class name, etc.

眉黛浅 2025-01-25 20:04:39

首先,您检查了您的应用程序崩溃的要点(不幸的是,MyApp已停止。)。为此,您可以使用 log.e(“ tag”,“ message”); ,使用此行,您可以在logcat中查看应用程序log。

之后,您发现您的应用程序停止了这一点,很容易在您身边解决。

First, you check which point your app has crashed (Unfortunately, MyApp has stopped.). For this, you can use Log.e("TAG", "Message");, using this line you can see your app log in logcat.

After that, you find which point your app has stopped it's very easy to solve at your side.

乜一 2025-01-25 20:04:39

只需检查日志猫中的错误即可。

您可以从Eclipse中获得日志猫选项:

window-&gt;显示view-&gt; android-&gt; logcat

log cat包含错误。

其他明智的方法,您还可以通过在调试模式下执行应用程序来检查错误。
首先通过这样做设置断点:

右键单击项目 - &gt; debug as-&gt; android应用程序

Just check the error in log cat.

You get the log cat option from in eclipse:

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

Log cat contains error.

Other wise you can also check the error by executing an application in debug mode.
Firstly set breakpoint after that by doing:

right click on project->debug as->Android application

浅浅淡淡 2025-01-25 20:04:39

注意:此答案使用的是 Android Studio 2.2.2

注意 2: 我认为您的设备已成功连接。


当应用程序崩溃时,您要做的第一件事就是查看 LogCat,在 Android Studio 的底部有一个带有菜单列表的工具栏:

image

单击“Android Monitor”(我在^)

现在,您将得到如下内容:

image

立即将“Verbose”更改为“Error”它只会显示您记录的错误。现在不用担心所有这些错误(如果您遇到了它们)。

image

好的。现在,执行您为使应用程序崩溃所做的操作。应用程序崩溃后,转到 logcat。您应该找到一个新的崩溃日志,其中包含大量 at:xxx: 和 Caused by: TrumpIsPresidentException 例如。转到 logcat 中的 Caused by: 语句。

image

Caused By:旁边,应该有发生的异常。就我而言,它是一个 RuntimeException 并且在它下面应该有一行包含一个蓝色链接,例如:

image

<强>如果那样的话Caused by: 下方某处没有带有蓝色文本的行,然后查找另一个具有该内容的 Caused by:

点击蓝色链接。它应该带您到问题发生的地方。就我而言,这是由于这一行:

throw new RuntimeException();

所以,现在我知道它为什么崩溃了。这是因为我自己抛出异常。 这是一个明显的错误


但是,假设我遇到了另一个错误:

java.lang.NullPointerException

我检查了 logcat,单击了它给我的蓝色链接,然后它把我带到了这里:

mTextView.setText(myString);

所以,现在我想调试。根据 这个 StackOverflow 问题,一个 NullPointerException表示某些内容为null

那么,让我们找出什么是 null。有两种可能性。 mTextView 为 null,或者 myString 为 null。为了找出答案,在 mTextView.setText(mString) 行之前,我添加了这两行:

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

现在,就像我们之前所做的那样(我们将 Verose 更改为 Error),我们要将“Error”更改为“调试”。因为我们是通过调试来记录的。以下是所有 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,因此我们正在调试中进行检查。这就是为什么我们将其更改为调试。

请注意 Log.d 有第一个参数,在我们的例子中为“AppDebug”。单击 logcat 右上角的“无过滤器”下拉菜单。选择“编辑过滤器配置”,为过滤器命名,然后在“日志标签”中输入“应用程序调试”。单击“确定”。现在,您应该在 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);

这就是为什么 mTextView 为 null,因为我忘记告诉我的应用程序它是什么。所以我添加了该行,运行我的应用程序,现在应用程序不会崩溃。


Note: This answer is using Android Studio 2.2.2

Note 2: I am considering that your device is successfully connected.


The first thing you do when your application crashes is looking into the LogCat, at the bottom of Android Studio there's a toolbar with a list of menus:

image

Click on the "Android Monitor" (The one I underlined in the image above. ^)

Now, you'll get something like this:

image

Change "Verbose" to "Error" Now it will only show you logged errors. Don't worry about all these errors (if you got them) now.

image

Ok. Now, do what you did to crash your app. After your app crashes, go to your logcat. You should find a new crash log that has a lot of at:x.x.x: and Caused by: TrumpIsPresidentException for example. Go to that Caused by: statement in your logcat.

image

Next to that Caused By:, there should be the Exception that happened. In my case, it's a RuntimeException and under it there should be a line that contains a blue link such as:

image

If that Caused by: DOESN'T have a line with a blue text somewhere under it, then look for another Caused by: that does.

Click on that blue link. It should take you to where the problem occurred. In my case, it was due to this line:

throw new RuntimeException();

So, now I know why it's crashing. It's because I'm throwing the exception myself. This was an obvious error.


However, let's say I got another error:

java.lang.NullPointerException

I checked my logcat, I clicked on the blue link it gave me, and it took me here:

mTextView.setText(myString);

So, now I want to debug. According to this StackOverflow question, a NullPointerException says that something is null.

So, let's find out what is null. There are two possibilities. Either mTextView is null, or myString is null. To find out, before the mTextView.setText(mString) line, I add these two lines:

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

Now, like we did previously (We changed Verose to Error), we want to change "Error" to "Debug". Since we're logging by debugging. Here are all the Log methods:

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

So, since we used Log.d, we're checking in Debug. That's why we changed it to debug.

Notice Log.d has a first parameter,in our case "AppDebug". Click on the "No Filters" drop down menu on the top-right of the logcat. Select "Edit Filter Configuration", give a name to your filter, and in "Log Tag" put "App Debug". Click "OK". Now, you should see two lines in the logcat:

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

So now we know that mTextView is null.

I observe my code, now I notice something.

I have private TextView mTextView declared at the top of my class. But, I'm not defining it.

Basically, I forgot to do this in my onCreate():

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

So THAT'S why mTextView is null, because I forgot to tell my app what it is. So I add that line, run my app, and now the app doesn't crash.


护你周全 2025-01-25 20:04:39

此弹出窗口仅在您在代码中获得致命例外的情况下显示,从而阻止了该应用程序的执行。它可能是任何例外 nullpoInterException OutOfMemoryException 等。

检查的最佳方法是通过 logcat ,如果您仍在Android Studio中开发App,快速读取堆栈跟踪并检查应用程序原因的方法。

如果您的应用程序已经存在,则无法使用 logcat 。因此,为此,您可以实现 crashlytics 为您提供任何发生任何例外的错误报告。

This popup shows only when you get a fatal exception in your code which stops the execution of the app. It could be any exception NullPointerException, OutOfMemoryException etc.

Best way to check is through Logcat if you are still developing the app in Android studio which is quick way to read stack trace and check the cause of the app.

If your app is already live, then you can not use logcat. So, for that you can implement Crashlytics to provide you bug reports of any exception that occurs.

只为守护你 2025-01-25 20:04:39

检查您的 logcat 消息,然后查看您的清单文件。应该缺少某些内容,例如定义活动,用户权限,等等。

Check your Logcat message and see your Manifest file. There should be something missing like defining the Activity,User permission`, etc.

别理我 2025-01-25 20:04:39

您可以使用这些工具:

  1. adb logcat

  2. adb logcat&gt; logs.txt(您可以使用编辑器打开并搜索错误。)

  3. eclipse logcat(如果在Eclipse中不可见,请转到Windows-&gt; show view-&gt; ersother-&gt; android-&gt; logcat)

  4. Android Debug Monitor或Android设备监视器(键入命令 Monitor 或通过UI打开)

“在此处输入图像说明”

  1. Android Studio

建议使用 Android调试显示器,这很好。因为当日志过多时,Eclipse会悬挂,并且通过ADB LogCat过滤器以及所有困难。

You can use any of these tools:

  1. adb logcat

  2. adb logcat > logs.txt (you can use editors to open and search errors.)

  3. eclipse logcat (If not visible in eclipse, Go to Windows->Show View->Others->Android->LogCat)

  4. Android Debug Monitor or Android Device Monitor(type command monitor or open through UI)

enter image description here

  1. Android Studio

I suggest to use Android Debug Monitor, it is good. Because eclipse hangs when too many logs are there, and through adb logcat filter and all difficult.

一个人的旅程 2025-01-25 20:04:39

您必须检查 IDE 上的堆栈跟踪

如何执行此操作?

检查 Windows 窗体 LOGCAT

如果您看不到 logcat 窗口,请转到此路径并打开它

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

(如果您这样 做)正在使用 Google-Api 转到此路径

adb logcat > logcat.txt

You have to check the Stack trace

How to do that?

on Your IDE Check the windows form LOGCAT

If you cant see the logcat windows go to this path and open it

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

if you are using Google-Api go to this path

adb logcat > logcat.txt

醉南桥 2025-01-25 20:04:39

在下面的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();
}

In below showToast() method you have to pass another parameter for context or application context by doing so you can try it.

  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();
}
地狱即天堂 2025-01-25 20:04:39

让我分享一下当您遇到强制关闭(当应用程序停止工作时)时的基本 Logcat 分析。

DOCS

Android 中收集/分析日志的基本工具是 logcat。

这里是关于 logcat 的 Android 页面

如果您使用 android Studio,您还可以检查此LINK

捕获

基本上,您可以使用以下命令手动捕获 logcat(或者仅检查 AndroidStudio 中的 AndroidMonitor 窗口):

adb logcat

您可以在命令中添加很多参数,以帮助您过滤和显示以下消息:你想要...这是个人的...我总是使用下面的命令来获取消息时间戳:

adb logcat -v time

您可以将输出重定向到文件并在文本编辑器中分析它。

分析

如果您的应用崩溃,您会得到类似以下内容:

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

日志的这一部分向您显示大量信息:

  • 问题发生时:07-09 08:29:13.475< /code>

检查问题何时发生非常重要...您可能会在日志中发现多个错误...您必须确保检查正确的消息:)

  • 哪个应用程序崩溃了: com.example.khan.abc

这样,您就知道哪个应用程序崩溃了(以确保您正在检查有关消息的日志)

  • 哪个错误:java.lang.NullPointerException

空指针异常错误

  • 有关错误的详细信息:尝试在空对象引用上调用虚拟方法 'void android.support.v4.app.FragmentActivity.onBackPressed()'

您尝试从 FragmentActivity 对象调用方法 onBackPressed()。但是,当您执行此操作时,该对象为 null

  • 堆栈跟踪:堆栈跟踪向您显示方法调用顺序...有时,错误发生在调用方法中(而不是发生在被调用方法中)。

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

文件 com.example.khan.abc.AudioFragment.javaonClick() 发生错误 方法位于行: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)

等等...

概述

这只是一个概述...并非所有日志都很简单,但错误给出了具体问题,详细显示了所有问题...这只是分享想法并提供给你的入门级信息...

我希望我能以某种方式帮助你...
问候

Let me share a basic Logcat analysis for when you meet a Force Close (when the app stops working).

DOCS

The basic tool from Android to collect/analyze 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 the following command (or just check AndroidMonitor window in AndroidStudio):

adb logcat

There's a lot of parameters you can add to the 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 but the error gives specific problem and verbose shows up all problem ... It is just to share the idea and provide entry-level information to you...

I hope I could help you someway...
Regards

无风消散 2025-01-25 20:04:39

使用 LogCat 并尝试查找导致应用程序崩溃的原因。

要查看 Logcat(如果您使用 Android Studio),请按 ALT + 6
或者

如果您使用 Eclipse 那么
窗口->开放视角->其他 - LogCat

转到 LogCat,从下拉菜单中选择错误。这将包含帮助您调试所需的所有信息。如果这没有帮助,请将 LogCat 作为对您的问题的编辑发布,有人会帮助您。

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.

幸福还没到 2025-01-25 20:04:39

如果您的应用程序出于某种原因而没有良好的StackTrace崩溃。尝试从第一行进行调试,然后按行行直至崩溃。然后,您将得到答案,哪一行会给您带来麻烦。然后,您可以将其包装到尝试捕获块并打印错误输出中。

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.

心碎无痕… 2025-01-25 20:04:39

您还可以自己收到此错误消息,而无需任何堆栈跟踪或任何其他错误消息。

在这种情况下,您需要确保正确配置了Android清单(包括从库中发生的任何明显合并以及将来自库的任何活动),并特别注意您的清单文件中应用程序中显示的第一个活动。

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.

柒七 2025-01-25 20:04:39

人们会犯错误,编码也会犯错误。

发生任何错误时,请始终使用红色文本的 logcat 进行检查,但是您可以在红色文本中找到带下划线的蓝色文本中的真正问题 。

确保如果您创建新的 activity,请始终在 AndroidManifest 文件中声明该 activity

如果添加权限,也要在 AndroidMainifest 文件中声明它。

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.

噩梦成真你也成魔 2025-01-25 20:04:39

logcat - 检查Android Studio的开发阶段的日志

最初清除了LogCat,然后再次让应用程序崩溃,以便您只能获得崩溃的日志详细信息。您必须检查堆栈跟踪

不幸的是,MyApp停止了。有很多原因。您可以在日志中检查相同。为此,您可以使用log.e(“标签”,“消息”);

应用程序崩溃期间的常见错误如下:

  1. 编码错误(错误使用关键字)。
  2. 不匹配的属性名称。
  3. 不受支持的插件(也许)。
  4. 不匹配版本(也许)。
  5. AndroidManifest文件中缺少活动。
  6. AndroidManifest文件中缺少许可。
  7. 最常见的NullPoInterException。
  8. 声明但未定义。

解决应用程序崩溃错误:

  • 请记住高于点并仔细阅读。
  • 有了错误,您也将以蓝色获得文件名(单击它们,并从错误中跳到代码)。

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).
听不够的曲调 2025-01-25 20:04:39

开发期间崩溃

尝试我最喜欢的工具 logview 来获取日志并分析它们在开发过程中。
在 Linux 中运行时,请确保将 ./logview./lib/logview.jar 标记为可执行文件。

如果您不喜欢它,还有很多替代的Android 桌面日志查看器

野外崩溃

集成实时崩溃报告工具,例如 Firebase Crashlytics,以便获取用户设备上发生的未处理异常的堆栈跟踪。

阅读如何发布一个有问题的应用程序(并现场讲述故事)以了解有关现场处理错误的更多信息。

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.

诠释孤独 2025-01-25 20:04:39

如果您的终端中没有任何有趣的日志(或者它们与您的应用程序不直接相关),则您的问题可能是由于本机库造成的。在这种情况下,您应该检查终端中的“tombstone”文件。

逻辑删除文件的默认位置取决于每个设备,但如果是这种情况,您将收到一条日志,告诉您:逻辑删除文件已写入:/data/tombstones/tombstone_06

有关详细信息,请查看https://source.android.com/devices/tech/debug

If you don't have any kind of interesting log in your terminal (or they are not directly related to your app), maybe your problem is due to a native library. In that case, you should check for the "tombstone" files within your terminal.

The default location for the tombstone files depends on every device, but if that's the case, you will have a log telling: Tombstone written to: /data/tombstones/tombstone_06

For more information, check on https://source.android.com/devices/tech/debug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文