I am doing one application in android for that I need to access com.android.internal.telephony APIs. Now I am able to access those APIs but problem is wherever I call the
Presumably getConnections()
is returning null, so l
is null, so trying to call l.size()
is throwing the exception. We don't know what getConnections()
does though.
Note that this looks suspicious too:
Connection myConn = new MyConn();
myConn = myCall.getEarliestConnection();
Why are you creating an instance of MyConn
in the first line, only to throw it away again? Why not just use:
Connection myConn = myCall.getEarliestConnection();
In general, it's worth declaring local variables as late as you can, ideally when you have a useful value - so in your method, you could declare c
within the loop, assign t
a value in the declaration, declare l
at the point of assignment, etc. You should also consider using generics where possible - e.g. List
instead of just the raw List
type.
EDIT: In contrast to the accepted answer, I would suggest changing getConnections()
to always return a non-null value, returning an empty list if there are no connections. That will be easier to work with.