Reputation: 42824
I am getting nullpointer exception in line:
initialNetLocation = appLocationService.getLocation(LocationManager.NETWORK_PROVIDER);
This is not happening in case of Activity !
public class MyClass extends Fragment {
//Constructor
public MyClass () {
}
//View references
ImageView mImageView;
EditText mEditText;
double latitude,longitude;
LocationManager locationManager;
private AppLocationService appLocationService;
private Location locationPassive,initialNetLocation;
String finalLastDate,finalLastTime,finalCurDate,finalCurTime;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.findurgentcare, container,false);
mImageView=(ImageView) rootView.findViewById(R.id.iv_get_adress_from_location);
mEditText=(EditText) rootView.findViewById(R.id.et_adress_of_loc);
return rootView;
}
@Override
public void onStart() {
super.onStart();
mImageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
initialNetLocation =appLocationService.getLocation(LocationManager.NETWORK_PROVIDER);
}
}
Upvotes: 0
Views: 51
Reputation: 242
You didn't initialize appLocationService before using it, therefore you are receiving NullPointer Exception:
appLocationService = new AppLocationService(<CONTEXT>);
Upvotes: 0