App crashing android studio

How to Resolve App Crashes in Android Studio?

While developing applications in Android Studio we might encounter many errors while writing code in the editor. We know that there’s an error since the editor automatically detects in real-time and highlights it in red color like this

Well, in the above image we can see that the error occurs due to a closing bracket after orderLists in Line 58. We can say that because the editor detects that in real-time and warns us with red underlining at that line. Now we can write error-less code and our app should run, right? Well, NO. Because the editor only helps in detecting the syntax error in the code. Whereas we have many other kinds of errors that might cause our app not to work the way we want it to be. Runtime and Logical errors are the common ones and cannot be detected in the editor.

Now the question is – We have written 100’s and 1000’s lines of error less codes or I should syntax error free code that compiles and runs without any problem. But my app still stops working or some features don’t work the way I want it to?

In this situation, the Logcat acts as our best friend. Logcat Window is the place where various messages can be printed when an application runs. Suppose, you are running your application and the program crashes, unfortunately. Then, Logcat Window is going to help you to debug the output by collecting and viewing all the messages that your emulator throws. So, this is a very useful component for the app development because this Logcat dumps a lot of system messages and these messages are actually thrown by the emulator. In Android Studio one of the most used tools is Logcat. Logcat window in Android Studio is used to display real-time system messages and messages that are added in the Log class of the app. To open Logcat Click View > Tool Windows > Logcat (Alt + 6 or from the toolbar window).

Most Common Types of Error

  • NullPointerException – When expecting from null variables, objects, or classes.
  • IOException – Exceptions produced by failed or interrupted I/O operations.
  • OutOfMemoryError – When an object cannot be allocated more memory by its garbage collector.

Solutions to fix App Crash

1. Observe the App Crash

Suppose you have built an application with multiple activities or fragments or both then you need to observe and see which action causes the application to crash. This might sometimes help you automatically remember or recall what mistake was made and which part of the app is causing that.

2. Find the Stack Trace

It is best to look at the logcat to find the exact point of error. You can open the logcat and in the error section start reading the log error messages. Scroll to the bottom of the screen and look for the line that says Caused by. You may find the file name and line number in the logcat messages, which will lead you directly to the cause of the error. Look for elements to resolve the error.

  • File Name
  • Line Number
  • Exception Type
  • Exception Message

3. Investigation Techniques

There are times when you might not find the exact line of code or file name that’s causing the error. So you should following techniques to investigate by yourself –

  • Toast – Toast messages are used to display alerts messages and in this case, you can use them to display failure messages.
  • Logging – Logging is used to print messages in the logcat.
  • Breakpoints – It can be used to investigate values at the points where breaks are applied.

Источник

Android studio app keeps stopping & rename project

Android studio app keeps stopping & rename the project. If you are irritated why your android studio app keeps crashing, here you will get your answer. Keep reading to know more. I am working on an application and each time I try to run it, I receive the following message: Unfortunately, MyApp has stopped.

Each moment an Android application fails to function (or the entire Java application, for the matter) it is an Stack trace The console is logged to (in this instance logcat). This trace of the stack contains crucial information to resolve your problem. Click on the logcat trace to see it. You can also hit the alt + 6 . Check that your computer or other device has been chosen in the Devices panel. Then, you can try to locate the trace for the stack. There might be lots of data that is logged into logcat, therefore it may be necessary to scroll. The easiest way to find the trace of the stack is to delete your logcat (using the recycle bin to the right) and allow the application to crash.

Читайте также:  Chery tiggo 5x android multimedia

Android studio app keeps stopping

Android studio app keeps stopping & renaming projects. Does your android studio app keep crashing? You have written all the codes right. Still, you are facing this issue again and again. Well, there are many reasons for them. We will see those reasons in this article and try to resolve them.

Android studio stops working because, due to some issues, it faces an unexpected exit. This unexpected exit can be due to many reasons. Or the other reason is that your app is not able to handle the exception thrown by the program. If the code is written in native java, the exception handling is thrown are SIGSEGV.

When this kind of exception handling happens, the app gets crashed and shows a message that the app has been crashed,

We are going to look into the causes of this crash, and we will resolve them.

Clean your phone cache memory

If you are testing your app on your phone, one of the reasons to crash your app is your phone cache memory. It happens when your phone’s cache memory gets filled, and you don’t clean it. So, when you start running your new app, it needs some cache memory to run, and the app could not find it. So the app gets crashed.

To resolve this problem, you need to clear your phone cache memory. To clean your cache memory, go through these steps.

Step 1. Open your phone setting.

Step 2. Go to the phone store and open it.

Step 3. On the bottom of the page, you will find the cache. Tap on it.

Step 4. When you tap it, a pop-up message will appear, click OK. Now your cache memory will get clean in a moment.

Now you can again try to run your program.

Reinstall the app

Many of the times the issue happens it that when you try to install the app from the android studio, the app did not get installed correctly. In that case, the app keeps crashing. To resolve this problem, you need to reinstall the app on your phone.

First of all, you need to uninstall the app from the phone. To uninstall the app, tap on the app for a second, click on info, a new page will appear, then click on the uninstall app. This will uninstall the app from the phone.

Now you have to again install the app on your device. To install the app, you only have to click the run button on the android studio.

This will install the app on your device.

Network issues

One of the major problems is that if your app uses the internet to fetch data and your internet is not fast enough; your app will crash. To resolve this problem, all you can do is to have a good internet connection.

Issues in code

This is also one of the biggest issues. The issues in your code will crash your app because due to issue in code, the will now be able to compile, and it will generate the run time error and the app will exit. To resolve this, you need to check your code thoroughly and make sure that there is no issue in the code.

You can also take the help of a logcat to trace your issue. We have talked about logcat in another article. You can read it here.

Issues with emulator

When you use an android emulator, then also some issues happen when your app gets crashed. It is probably the not proper installation of the emulator. All you need to fix this problem is that you have to reinstall the emulator on your system. It will fix the problem.

If you still can’t fix the problem, then you need to check where the problem. We will now see how to do it.

Reading stack trace

If you have done all the things above we mentioned and you still can’t fix the problem now you need the trace the problem. To do that, you need to take the help of the stack trace. The stack trace will help you in finding the problems which are causing the crash. You can use the stack trace tool available in the logcat window. android studio app keeps stopping

The stack trace gives two kinds of information about the crash.

  • The kind of exception happened
  • Where the exception has happened in the entire code.

These two things will help to tace the problem and resolve it.

Memory errors

When you are using the emulator on a low memory computer, it leads to the crash of the app. You can fix it by fixing the memory usage of the emulator. You can do this by going to the emulator settings page and fix all the issues. android studio app keeps stopping

You can fix how much the amount of memory can be used by the app—the amount of graphics used by the app and a lot of other things.

This is all for the android studio app keeps stopping.

Android studio rename project

Android studio app keeps stopping & rename project. There comes a time when you want to rename your project, but you can’t because the android studio does not give direct access to change the name of the project. So here we are helping you to do it. There are multiple of the process to do it. We will see most of the methods. Keep reading to know about it.

METHOD 1

Step 1. Start your project.

Step 2. Open the manifest.xml file.

Читайте также:  Андроид том за золотом много денег

Step 3. android:label=”@string/app_name” write this code. On the place of app_name write the name of the project you want.

This is the first method of how you can change the name of the project.

METHOD 2

Step 1. Open the project.

Step 2. Select the project name and click the setting button.

Step 3. Click on hide empty middle package.

Step 4. Right-click on the androidride folder. Then click on the setting button

Step 5. Click on the refactor and then on the rename.

Step 6. A warning message will pop-up. Click on rename.

Step 7. Input the name of the applicationt. I will keep it abc.

Step 8. Click refactor and then click do refactor.

Step 9. Right-click on the myapplication folder. Then click on the setting button

Step 10. Click on the refactor and then on the rename.

Step 11. A warning message will pop-up. Click on rename.

Step 12. Input the name of the application. I will keep it test.

Step 13. Click refactor and then click do refactor.

Step 14. Now you have to change application id, click on build.gradle, then on change application id.

Step 15. Now a page opens there find application id change it to com.abc.text

Step 16. Hit the sync now option.

Now the name of your application has been renamed.

METHOD 3

In this method, we are going to use the old project name to demonstrate things.

Step 1. Right-click on the package name which is com.abc.text.

Step 2. Hit on refactor and then select move.

Step 3. Select move package “com.abc.txt,” to another package.

Step 4. Click OK.

Step 5. Now when you click OK, you will get a list of warning messages with the list of folders to move. Hit Yes.

Step 6. A new dialog box will appear for entering the name of the project. Enter the name of the project except for the last part. For example, if you want to name the project “com.abc.def” enter till “com.abc”.

Step 7. Now a new pop-up will appear asking for the folder does not exist want to create a new folder. Hit Yes.

Step 8. Hit do refactor.

Step 9. Now we will enter the last part of the name for the project. To do so, right-click on the application folder name.

Step 10. Now, you have to hit refactor and then click on the rename option.

Step 11. Again you will get some warning; click OK.

Step 12. Enter the new name, def. And click OK.

Step 13. Now again, you have to click on do refactor.

Step 14. Now if you want you can remove those old files. You can select multiple of packages at once and press the delete button.

Conclusion

Android studio app keeps stopping & rename project. We have seen how to resolve the problem related to the android studio app, not working. We tried to make easy to tackle those problems. It is not hard to resolve them. We have also seen how to rename the project. These things are quite easy to do. I hope you liked the post.

Источник

App Center Crashes (Android)

App Center Crashes will automatically generate a crash log every time your app crashes. The log is first written to the device’s storage and when the user starts the app again, the crash report will be sent to App Center. Collecting crashes works for both beta and live apps, i.e. those submitted to Google Play. Crash logs contain valuable information for you to help fix the crash.

Follow the Getting Started section if you haven’t set up the SDK in your application yet.

Generate a test crash

App Center Crashes provides you with an API to generate a test crash for easy testing of the SDK. This API can only be used in debug builds and won’t do anything in release builds.

Get more information about a previous crash

App Center Crashes has two APIs that give you more information in case your app has crashed.

Did the app receive a low memory warning in the previous session?

At any time after starting the SDK, you can check if the app received a memory warning in the previous session:

This API is asynchronous, you can read more about that in our App Center Asynchronous APIs guide.

This method must only be used after Crashes has been started, it will always return false before start.

In some cases, a device with low memory can’t send events.

Did the app crash in the previous session?

At any time after starting the SDK, you can check if the app crashed in the previous launch:

This API is asynchronous, you can read more about that in our App Center Asynchronous APIs guide.

This comes in handy in case you want to adjust the behavior or UI of your app after a crash has occurred. Some developers chose to show additional UI to apologize to their users, or want way to get in touch after a crash has occurred.

This method must only be used after Crashes has been started, it will always return false before start.

Details about the last crash

If your app crashed previously, you can get details about the last crash.

This API is asynchronous, you can read more about that in our App Center Asynchronous APIs guide.

There are numerous use cases for this API, the most common one is people who call this API and implement their custom CrashesListener.

This method must only be used after Crashes has been started, it will always return null before start.

Customize your usage of App Center Crashes

App Center Crashes provides callbacks for developers to perform additional actions before and when sending crash logs to App Center.

To handle the callbacks, either implement all methods in the CrashesListener interface, or override the AbstractCrashesListener class and pick only the ones you’re interested in.

Use your own CrashesListener

Create your own CrashesListener and assign it like this:

Читайте также:  Удалить данные с карты памяти андроид

In case you’re only interested in customizing some of the callbacks, use the AbstractCrashesListener instead:

Set the listener before calling AppCenter.start() , since App Center starts processing crashes immediately after the start.

Should the crash be processed?

Implement this callback if you want to decide if a particular crash needs to be processed or not. For example, there could be a system level crash that you’d want to ignore and that you don’t want to send to App Center.

If user privacy is important to you, you might want to get user confirmation before sending a crash report to App Center. The SDK exposes a callback that tells App Center Crashes to await user confirmation before sending any crash reports.

If you chose to do so, you’re responsible for obtaining the user’s confirmation, e.g. through a dialog prompt with one of the following options: Always Send, Send, and Don’t send. Based on the input, you’ll tell App Center Crashes what to do and the crash will then be handled accordingly.

The SDK doesn’t display a dialog for this, the app must provide its own UI to ask for user consent.

The following callback shows how to tell the SDK to wait for user confirmation before sending crashes:

If you return true , your app must obtain (using your own code) the user’s permission and message the SDK with the result using the following API:

As an example you can refer to our custom dialog example.

Get information about the sending status for a crash log

At times, you want to know the status of your app crash. A common use case is that you might want to show UI that tells the users that your app is submitting a crash report, or, in case your app is crashing quickly after the launch, you want to adjust the behavior of the app to make sure the crash logs can be submitted. App Center Crashes has three different callbacks that you can use in your app to be notified of what’s going on:

The following callback will be invoked before the SDK sends a crash log

In case we have network issues or an outage on the endpoint, and you restart the app, onBeforeSending is triggered again after process restart.

The following callback will be invoked after the SDK sent a crash log successfully

The following callback will be invoked if the SDK failed to send a crash log

Receiving onSendingFailed means a non-recoverable error such as a 4xx code occurred. For example, 401 means the appSecret is wrong.

This callback isn’t triggered if it’s a network issue. In this case, the SDK keeps retrying (and also pauses retries while the network connection is down).

Add attachments to a crash report

You can add binary and text attachments to a crash report. The SDK will send them along with the crash so that you can see them in App Center portal. The following callback will be invoked right before sending the stored crash from previous application launches. It won’t be invoked when the crash happens. Be sure the attachment file isn’t named minidump.dmp as that name is reserved for minidump files. Here’s an example of how to attach text and an image to a crash:

The size limit is currently 7 MB. Attempting to send a larger attachment will trigger an error.

Enable or disable App Center Crashes at runtime

You can enable and disable App Center Crashes at runtime. If you disable it, the SDK won’t do any crash reporting for the app.

To enable App Center Crashes again, use the same API but pass true as a parameter.

The state is persisted in the device’s storage across application launches.

This API is asynchronous, you can read more about that in our App Center Asynchronous APIs guide.

This method must only be used after Crashes has been started.

Check if App Center Crashes is enabled

You can also check if App Center Crashes is enabled or not:

This API is asynchronous, you can read more about that in our App Center Asynchronous APIs guide.

This method must only be used after Crashes has been started, it will always return false before start.

Handled Errors

App Center also allows you to track errors by using handled exceptions. To do so, use the trackError method:

An app can optionally attach properties to a handled error report to provide further context. Pass the properties as a map of key/value pairs (strings only) as shown in the example below.

You can also optionally add binary and text attachments to a handled error report. Pass the attachments as an Iterable as shown in the example below.

Reporting NDK crashes

Reporting crashes

To receive proper crash reports in App Center, first make sure you have the App Center Crashes SDK set up by following the instructions listed above.

Building the breakpad library

Next, include and compile Google Breakpad by following the instructions listed in the official Google Breakpad for Android README.

The App Center SDK doesn’t bundle Google Breakpad by default.

Attaching the exception handler

Once you have Google Breakpad included, attach the NDK Crash Handler after AppCenter.start :

The method setupNativeCrashesListener is a native method that you must implement in C/C++:

Where dumpCallback is used for troubleshooting:

Once these methods are properly set up, the app sends the minidump to App Center automatically upon restart. To troubleshoot, you can use verbose logs ( AppCenter.setLogLevel(Log.VERBOSE) before AppCenter.start ) to check if minidumps are sent after the app is restarted.

App Center uses the reserved name minidump.dmp for minidump attachments. Make sure to give your attachment a different name unless it’s a minidump file so we can handle it properly.

There’s a known bug in breakpad which makes it impossible to capture crashes on x86 emulators.

Symbolication

See the Diagnostics documentation for more information regarding the processing of crashes.

Источник

Оцените статью