Not able to detect the line number in logcat Android Studio
Asked Answered
M

2

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)
Marquardt answered 26/12, 2016 at 9:44 Comment(12)
you can post a pictureGavan
hey @Charuka I have added the logcat.Marquardt
check my answerGavan
please note when you edit a question post it under EDIT part and your question is about a specific occurrence but you ask it like you have it every time when you have an error and i have given the reason for that specific scenarioGavan
I am editing the question because I think I have written in the wrong way. I want to ask something else and I am pointing to the different question.Marquardt
still do you have your issue?Gavan
I didn't get the answer so need to format the android studio. Now no problem. Still wondering why this problem occurred? @CharukaMarquardt
Now again the same issue starts@CharukaMarquardt
whatabout your naming conventions ? do you use dependancies for button effectsGavan
i do not get you @Charuka naming conventions?Marquardt
when you name a package/class name there is a stranded,and also rules not even class names simply if you use caps to name an image in drawble it's a problem case. same thing was with your previous class nameGavan
I have double check there is no resource with the first character capital and also the class name/package naming also follow the google guidelines. The previous class means i think you are talking about Reminders$13 class name. But in actual it is Reminders.java that I don't know why android studio has shown like that.Marquardt
G
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

Gavan answered 26/12, 2016 at 10:20 Comment(5)
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...Marquardt
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"Gavan
@Ankur Khandelwal you have not mentioned that "I know where is the error" either in your questionGavan
sorry. for the misunderstanding. Now I have written in the question @CharukaMarquardt
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.Marquardt
L
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

Lyonnaise answered 26/12, 2016 at 9:47 Comment(4)
its more clear if you add your answer as a comment :PGavan
I have added the logcat.. @kalpitMarquardt
I can see in your logcat there is line ` at user.com.hlthee.Reminders$13.onClick(Unknown Source)` where $13 is line number i suppose. check what are you pasing in onClick it should be view class or its subclassLyonnaise
$13 is not the line no.Marquardt

© 2022 - 2024 — McMap. All rights reserved.