Android Studio bug

H help

Status: 06/13/2018

Especially for those who do not use an Android smartphone or tablet in everyday life, here is some basic information on operation. Note that there may be variations depending on the manufacturer (e.g. with Samsung). In addition, the operation will change fundamentally in 2018 (the three buttons will be replaced by one).

H.1.1 Navigation buttons

When you switch on and unlock an Android device, the appears Home screen. There are often several screens available that can be changed by swiping sideways.

No matter which screen you are on, there are always at the bottom three navigation buttons to see (sometimes you have to "pull it up" first, sometimes the button in the middle is a "real" button):

The Back button always goes "one step back" within an app, as you know from Internet browsers such as Chrome or Firefox.

The Home button always goes back to the above view. When you are in an app, the app takes a back seat.

The Recent applications button opens a view of all currently open apps:

You can "swipe" through the apps with your finger if there are many apps. You can also see a at the top right Cross to close the respective app.

H.1.2 App Drawer

In contrast to Apple devices, not all apps are necessarily located on one side of the device's screen. If you can't find an app, you can find one Overview of all appsinstalled on the device (also App drawer or App depot called):

Again, you can move up and down by swiping.

You can also use the Google search bar Search for the app using the name of the app (input field with a capital G).

H.2.1 Run window

When you start your project it can be that easy nothing happens. Your emulator or smartphone doesn't move and you don't know what's going on.

Then open the pane runwhich you can find in the lower bar:

You may then see one error messagewhich unfortunately comes across as relatively detailed and complex. Look in the text for a file name that sounds familiar (marked in blue here). There you can see in which Java class and even in which line the error occurred. You can even just click on the file name, then Android Studio jumps directly to the incorrect line.

The nature of your error (exception) is also displayed (marked in red here). A common mistake is that NullPointerException: then you applied the dot notation to a variable that should actually contain an object (e.g. to call a method), although there was no object in it (but zero).

H.2.2 Log

"Logging" simply refers to the systematic reporting of messages, similar to what you may have done in Processing or Java. The (static) methods of the class that are predefined in Android are used to output any messages (strings) on a special "log console".

For example, one method is simple (for "info"):

The first string can be used to roughly indicate which app or which area of ​​the app is involved. The second string is then the message. For example, you can use to test whether your button reacts:

When you start your project, you have to open the "Logcat" window (bar at the bottom). Additionally, be sure to look for "info" messages filter (Drop-down menu). Then you will only see the info messages:

There are different "levels" when logging. info is such a level. That was indicated by the fact that the method was called:

There are other levels below and above.

  • Verbose
  • Debug
  • info
  • Warning
  • Error
  • Assert

For each level you have its own method, e.g. for "Error" or for "Warn":

If you filter by a level you will see all log messages of the level and those of all levels below. For example under "Info" you will also see the messages: Warn, Error, Assert. Important (more basic) messages are located further down in the level hierarchy. You obviously don't want to ignore hard errors (level "Error").

The idea here is that you decide in your expenses how vital the expense is and choose a level accordingly (i.e. method or for example). Messages that you "just" incorporate when searching for errors (debugging) should be located on the "Info" or "Debug" levels.

H.2.3 Determine the name of the app

By default, your app is named as you named the project. This is often not such a sonorous name as "LayoutTest2" or something similar. However, this name appears in the top bar of your app, so you may want to adjust it.

To do this, open the String resourcelocated in the folder. When you open the file you will see:

Just change the string, e.g. like this or similar:

H.2.4 Rename project

You should always be very careful when renaming directories, variables, etc. If you want to rename an entire project, you can actually do the following:

  1. Close project
  2. Rename the project directory
  3. Open project with Android Studio
  4. Call up the Rebuild Project (see section "Tips in the event of errors")

If you want the name that is displayed in the bar at the top of the app: You can do this in /res/values/strings.xml determine. There is e.g.

Just change the text and it will change in the bar too.

Rebuild Project

The following trick works in many situations, e.g.

  • You open an existing project, but you cannot start it - even after waiting for a while - the corresponding button is grayed out
  • You are working on your layout and the display (or the preview) does not show what you have changed
  • You have a bug that mentions the term "gradle"

In such situations, try to "rebuild" the project using the menu option Build> Rebuild Project:

The project is then recompiled, old files are deleted and the problems mentioned are often solved.

Problems with the emulator

When Android Studio claims it cannot find the emulator, it often helps to exit the emulator first. Then introduce again run in Android Studio and start the emulator again.

Stubborn error messages in Android Studio

If Android Studio shows errors even though the code is correct and you already have Rebuild Project tried then you can still use the menu option File> Invalidate Caches / Restart try out.

Error APK

If the following error message appears, try again to start the project.

If that doesn't help, restart the emulator by exiting the emulator and restarting the project.

Prof. Dr. Michael Kipp
Augsburg University of Applied Sciences
At the university 1
86161 Augsburg
Room J3.18
Tel: +49 821 5586 3509