6

Android Studio 2.2.3

Android Studio is not able to detect the line number in logcat. Is there any way to solve this? It show Unknown Source in place of line no.

LOGCAT is added just the shake of pointing what is the issue. Not to point why NULL POINT EXCEPTION occuring...

Please ignore the error( I know why it is occurring ). I have added the logout to show what is problem.

Android studio is showing Unknown Source instead of error line number.

Logcat:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: user.com.hlthee, PID: 1107
                  java.lang.NullPointerException
                      at user.com.hlthee.Reminders$13.onClick(**Unknown Source**)
                      at android.support.v7.app.AlertController$ButtonHandler.handleMessage(Unknown Source)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:136)
                      at android.app.ActivityThread.main(ActivityThread.java:5001)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:515)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                      at dalvik.system.NativeStart.main(Native Method)
Charuක
  • 12,953
  • 5
  • 50
  • 88
Ankur Khandelwal
  • 1,042
  • 3
  • 19
  • 40

2 Answers2

4

If it is your class(Not a library) you are missing a view in your XML connected to the class. It says as NullPointerException - onClick(**Unknown Source)** meaning in your class you probably used onclick funtion for that view but the view is not in the XML. Find where you added onClicks in your class and see which one is not present in your connected XML

Edit :

This Unknown Source can occur if you do not have a proper naming conventions for your package name and package tag in your manifest like below

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="string"
          android:sharedUserId="string"
          android:sharedUserLabel="string resource" 
          android:versionCode="integer"
          android:versionName="string"
          android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
    . . .
</manifest> 

So you can double check your activity tag as well and follow naming conventions. You might have a name something like this ..Reminders$13

enter image description here

A full Java-language-style package name for the Android application. The name should be unique. The name may contain uppercase or lowercase letters ('A' through 'Z'), numbers, and underscores ('_'). However, individual package name parts may only start with letters. To avoid conflicts with other developers, you should use Internet domain ownership as the basis for your package names (in reverse). For example, applications published by Google start with com.google. You should also never use the com.example namespace when publishing your applications.

From developer.android.com

Charuක
  • 12,953
  • 5
  • 50
  • 88
  • hey think you have understand my question wrongly... My question is.. I know where is the error but why don't it pointing to the line number ( or showing ) where is error... – Ankur Khandelwal Dec 26 '16 at 10:37
  • because it cannot link them,compiler ignored it maybe you have same id with another xml so compiler cannot do the job and when run-time it try to find and return the view there is none in that xml it confuses and displayed as **Unknown Source)** but as a hint it says where that can occur "user.com.hlthee.Reminders$13.onClick" – Charuක Dec 26 '16 at 10:45
  • @Ankur Khandelwal you have not mentioned that "I know where is the error" either in your question – Charuක Dec 26 '16 at 10:46
  • sorry. for the misunderstanding. Now I have written in the question @Charuka – Ankur Khandelwal Dec 26 '16 at 10:49
  • I am not asking why null point exception occurred, I am saying irrespective to the error, the android studio is not telling me in which line the error is occurring. – Ankur Khandelwal Dec 26 '16 at 10:58
2

the possibilities that you are seeing Unknown Source are because either your device connection has been lost or the application's main thread is killed, It will be more clear if you put screen shot here