-1
  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_driver_edmm);
    mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    locationSwitch = findViewById(R.id.workingSwitch);
    locationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isOnline) {
            if (isOnline) {
                startLocationUpdates();
                displayLocation();
                Snackbar.make(mapFragment.getView(), "You Are Online", Snackbar.LENGTH_SHORT).show();
            } else {
                stopLocationUpdates();

                mMap.clear();
                handler.removeCallbacks(drawPathRunnable);
                Snackbar.make(mapFragment.getView(), "You Are OffLine", Snackbar.LENGTH_LONG).show();
            }
        }
    });
    polyLineList = new ArrayList<>();
   places = (PlaceAutocompleteFragment)getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment) ;
    places.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            if (locationSwitch.isChecked()){
                destination = place.getAddress().toString();
                destination = destination.replace(" ","+");
                getDirection();
            }else {
                Toast.makeText(DriverEdm.this, "Please press the ONLINE_SWITCH", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onError(Status status) {
            Toast.makeText(DriverEdm.this, "error "+status.toString(), Toast.LENGTH_SHORT).show();
        }
    });


    drivers = FirebaseDatabase.getInstance().getReference("Drivers");
    geoFire = new GeoFire(drivers);
    setUpLocation();
    mService = Common.getGoogleAPI();
}

`

--------- beginning of crash

2019-02-13 21:35:52.118 9765-9765/E/AndroidRuntime: FATAL EXCEPTION: main Process: PID: 9765 java.lang.RuntimeException: Unable to start activity : java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.location.places.ui.PlaceAutocompleteFragment.setOnPlaceSelectedListener(com.google.android.gms.location.places.ui.PlaceSelectionListener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main(ActivityThread.java:6251) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.location.places.ui.PlaceAutocompleteFragment.setOnPlaceSelectedListener(com.google.android.gms.location.places.ui.PlaceSelectionListener)' on a null object reference at uber.DriverEdm.onCreate(DriverEdm.java:180) at android.app.Activity.performCreate(Activity.java:6673) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)  at android.app.ActivityThread.-wrap12(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)  at android.os.Handler.dispatchMessage(Handler.java:110)  at android.os.Looper.loop(Looper.java:203)  at android.app.ActivityThread.main(ActivityThread.java:6251)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) `

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<fragment
    android:id="@+id/place_autocomplete_fragment"
    android:name="com.google.android.gms.location.places.ui.PlaceAutocomplete"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_margin="0dp"
    android:layout_weight="5"
    app:layout_constraintBottom_toTopOf="@+id/map"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_above="@+id/pannel"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginBottom="8dp"
    android:layout_weight="5"
    app:layout_constraintBottom_toTopOf="@+id/pannel"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/place_autocomplete_fragment" />

<LinearLayout
    android:id="@+id/pannel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="8dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/map">

    <Switch
        android:id="@+id/workingSwitch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10sp"
        android:text="Working" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/settings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_weight="1"
            android:text="Find User" />
    </LinearLayout>

</LinearLayout>

Kmaangaty
  • 83
  • 1
  • 12
  • 1
    Hello and welcome! StackOverflow is a place where people can ask questions, display what they have tried, and receive answers (hopefully). Can you please be sure to format the code and add what you have done so far to address the problem? –  Feb 13 '19 at 19:47
  • @OneLunchMan iam sorry retype it – Kmaangaty Feb 13 '19 at 19:52

1 Answers1

0

As i can see the NullPointerException is in PlaceAutocompleteFragment and not in a EditText...

U can try with this changes, let me know if its works for u:

Replace

<fragment
    android:id="@+id/place_autocomplete_fragment"
    android:name="com.google.android.gms.location.places.ui.PlaceAutocomplete"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_margin="0dp"
    android:layout_weight="5"
    app:layout_constraintBottom_toTopOf="@+id/map"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

With:

<fragment
    android:id="@+id/place_autocomplete_fragment"
    android:name="com.google.android.gms.location.places.ui.SupportPlaceAutocompleteFragment"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_margin="0dp"
    android:layout_weight="5"
    app:layout_constraintBottom_toTopOf="@+id/map"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

And in activity:

SupportPlaceAutocompleteFragment places = (SupportPlaceAutocompleteFragment)
            getChildFragmentManager()
                    .findFragmentById(R.id.place_autocomplete_fragment);