Android - Receiving Error Message from Different Activity After Clicking Submit Button

3250 views java
1

I have a process which is a sequence of 6 screens (the user makes selections on the first 5 and the 6th is the summary and “Submit” button) and when I test this screen sequence everything works perfectly unless… unless I visit my “UpcomingDate” activity prior to starting this sequence.

If I visit the “UpcomingDate” activity from the Main Activity and then immediately return to the Main Activity by pressing the BACK button in the “UpcomingDate” Activity. Then I start the sequence of screens mentioned before. When I get the summary page and click the “Submit” button (which calls the saveDataInputs() function) I am getting an error message which says it is coming from the “UpcomingDate” activity which was visited 6 Activities ago. Its like something in the “saveDataInputs()” function is trying to call the “UpcomingDate” activity to start. Am I missing something in the activity life cycle?

This is the sequence of events of which I am getting my error: Main Activity -> UpcomingDate Activity -> Main Activity -> Sequence Activity 1 -> Sequence Activity 2 -> Sequence Activity 3 -> Sequence Activity 4 -> Sequence Activity 5 -> Sequence Summary Activity -> Click submit button -> get error

2018-11-05 20:00:54.544 17388-17388/com.example.jacob.datenight E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jacob.datenight, PID: 17388
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
    at com.example.jacob.datenight.UpcomingDateActivity$1.onDataChange(UpcomingDateActivity.java:78)
    at com.google.firebase.database.obfuscated.zzap.zza(com.google.firebase:firebase-database@@16.0.3:75)
    at com.google.firebase.database.obfuscated.zzca.zza(com.google.firebase:firebase-database@@16.0.3:63)
    at com.google.firebase.database.obfuscated.zzcd$1.run(com.google.firebase:firebase-database@@16.0.3:55)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

The error occurs after I click the Submit button on the Summary activity which stops the app and therefore doesn’t load all of the data to the database. So of course, the error message is a NullPointerException because in the UpComingDate activity I am pulling data from a firebase database but not all of the expected data is there. So that is not the issue. I really need to figure out why it is going to the UpcomingDates activity when I have an Intent sending it to the MainActivity.

This is the code in my Upcoming Date Activity:

public class UpcomingDateActivity extends AppCompatActivity {

private DatabaseReference mDatabaseRef;
private FirebaseDatabase mFirebaseDatabase;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private String userId;
private String userEmail;
public String userToken;
private RecyclerView UpcomingDateRecyclerViewAdapter;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
ArrayList<UserDateNightSubmission> dnSubmissionValuesArray = new ArrayList<>();
RecyclerView recyclerView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upcoming_date);

    UpcomingDateRecyclerViewAdapter = (RecyclerView) findViewById(R.id.upcoming_date_recycler_view);
    mAuth = FirebaseAuth.getInstance();
    mFirebaseDatabase = FirebaseDatabase.getInstance();
    final FirebaseUser USER = mAuth.getCurrentUser();

    if (USER != null){
        userId = USER.getUid();
        userEmail = USER.getEmail();
        userToken = USER.getIdToken(true).toString();
    }


    mDatabaseRef = mFirebaseDatabase.getReference("date_night_submissions/" + userId);
    Query query = mDatabaseRef.orderByChild("name");
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //Clean up and organize the snapshot data which contains the notification's timestamp and other fields.
            dnSubmissionValuesArray.clear();

            if(dataSnapshot.getChildrenCount() > 0){

                for (DataSnapshot locSnapshot: dataSnapshot.getChildren()) {

                    UserDateNightSubmission dateNightSubmission = new UserDateNightSubmission(locSnapshot.getKey(), locSnapshot.child("email_address").getValue().toString(),
                            locSnapshot.child("screen_sequence").getValue().toString(), locSnapshot.child("selected_activities").getValue().toStr

answered question

I added an "answer" to post the code in my Summary activity

1 Answer

3

I exceeded the character limit on the original question so her is the code in my Summary Activity:

public class SummaryLetsGoActivity extends AppCompatActivity implements com.example.jacob.datenight.MasterDrawerFragment.Callbacks {

private static final String TAG_MASTER_FRAGMENT = "TAG_MASTER_FRAGMENT";
private static final String TAG_DETAIL_FRAGMENT = "TAG_DETAIL_FRAGMENT";

private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;

public String selectedDrivingOrUber;
public String selectedStartTime;
public String selectedEndTime;
public String selectedTimeHours;
public String selectedBudget;
public String budgetForYelp;
public String selectedPartySize;
public String selectedMood;
public String selectedActivities;
public String selectedDate;

public TextView drivingTextView;
public TextView budgetTextView;
public TextView startTimeTextView;
public TextView endTimeTextView;
public TextView totalHoursTextView;
public TextView partySizeTextView;
public TextView moodTextView;
public TextView activitiesTextView;
public TextView dateTextView;
public Button summaryNextBtn;
int randomInt1;
int randomInt2;

private UserProfile profile;
String userFirstName;
String userLastName;
String userPhoneNbr;
String userCommPref;

private DatabaseReference submissionsDatabaseRef;
private DatabaseReference profileDatabaseRef;
private FirebaseDatabase mFirebaseDatabase;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private String userId;
private String userEmail;
public String deviceRegistrationToken;
private ArrayList<YelpBusiness> yelpBusinessesArray = new ArrayList<>();
private ArrayList<YelpBusiness> yelpBusinessesArray2 = new ArrayList<>();
String apiKey;
String userLatitude;
String userLongitude;
FusedLocationProviderClient mFusedLocationClient;

String activitiesTerm = "";
String[][] selectedActivityXref = new String[7][2];
int numOfActivities = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_summary_lets_go);

    // Start Navigation bar and list
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    FirebaseApp.initializeApp(this);
    deviceRegistrationToken = FirebaseInstanceId.getInstance().getToken();
    apiKey = getString(R.string.yelp_api_key);

    mAuth = FirebaseAuth.getInstance();
    mFirebaseDatabase = FirebaseDatabase.getInstance();

    final FirebaseUser USER = mAuth.getCurrentUser();

    if (USER != null) {
        userId = USER.getUid();
        userEmail = USER.getEmail();
    }

    selectedDrivingOrUber = getIntent().getStringExtra("selectedDrivingOrUber");
    selectedStartTime = getIntent().getStringExtra("selectedStartTime"); // This is used to bring the data from the previous activity into the summary
    selectedEndTime = getIntent().getStringExtra("selectedEndTime");
    selectedTimeHours = getIntent().getStringExtra("selectedTimeHours");
    selectedBudget = getIntent().getStringExtra("selectedBudget");

    if (selectedBudget.equals("Free")) {
        budgetForYelp = "1";
    } else if (selectedBudget.equals("Average")) {
        budgetForYelp = "2";
    } else if (selectedBudget.contains("Special")) {
        budgetForYelp = "2, 3";
    } else if (selectedBudget.contains("Splurge")) {
        budgetForYelp = "3, 4";
    }

    selectedPartySize = getIntent().getStringExtra("selectedPartySize");
    selectedMood = getIntent().getStringExtra("selectedMood");
    selectedActivities = getIntent().getStringExtra("selectedActivities");
    selectedDate = getIntent().getStringExtra("selectedDate");

    if (savedInstanceState != null) {
        selectedDrivingOrUber = savedInstanceState.get("selectedDrivingOrUber").toString();
        selectedStartTime = savedInstanceState.get("selectedStartTime").toString();
        selectedEndTime = savedInstanceState.get("selectedEndTime").toString();
        selectedTimeHours = savedInstanceState.get("selectedTimeHours").toString();
        selectedBudget = savedInstanceState.get("selectedBudget").toString();

        if (selectedBudget.equals("Free")) {
            budgetForYelp = "1";
        } else if (selectedBudget.equals("Average")) {
            budgetForYelp = "2";
        } else if (selectedBudget.contains("Special")) {
            budgetForYelp = "2, 3";
        } else if (selectedBudget.contains("Splurge")) {
            budgetForYelp = "3, 4";
        }

        selectedPartySize = savedInstanceState.get("selectedPartySize").toString();
        selectedMood = savedInstanceState.get("selectedMood").toString();
        selectedActivities = savedInstanceState.get("selectedActivities").toString();
        selectedDate = savedInstanceState.get("selectedDate").toString();
    }


    drivingTextView = (TextView) findViewById(R.id.summaryDrivingTextView);
    budgetTextView = (TextView) findViewById(R.id.summaryBudgetTextView);
    startTimeTextView = (TextView) findViewById(R.id.summaryStartTimeTextView);
    endTimeTextView = (TextView) findViewById(R.id.summaryEndTimeTextView);
    totalHoursTextView = (TextView) findViewById(R.id.summaryTotalHoursTextView);
    partySizeTextView = (TextView) findViewById(R.id.summaryPartySizeTextView);
    moodTextView = (TextView) findViewById(R.id.summaryMoodTextView);
    activitiesTextView = (TextView) findViewById(R.id.summaryActivitiesTextView);
    dateTextView = (TextView) findViewById(R.id.summaryDateTextView);
    summaryNextBtn = (Button) findViewById(R.id.summaryNextBtn);

    selectedActivityXref[0][0] = "Dinner";
    selectedActivityXref[0][1] = "Food";
    selectedActivityXref[1][0] = "Movie";
    selectedActivityXref[1][1] = "Movie";
    selectedActivityXref[2][0] = "Drinks";
    selectedActivityXref[2][1] = "Bars";
    selectedActivityXref[3][0] = "Dance";
    selectedActivityXref[3][1] = "Dance Clubs";
    selectedActivityXref[4][0] = "Walk";
    selectedActivityXref[4][1] = "Walking Trails";
    selectedActivityXref[5][0] = "Workout";
    selectedActivityXref[5][1] = "Gyms";
    selectedActivityXref[6][0] = "Coffee";
    selectedActivityXref[6][1] = "Coffee & Tea";

    //Retreiving Yelp data
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

        mFusedLocationClient.getLastLocation()
                .addOnSuccessListener(this, new OnSuccessListener<Location>() {
                    @Override
                    public void onSuccess(Location location) {
                        // Got last known location. In some rare situations this can be null.
                        if (location != null) {
                            // Logic to handle location object
                            userLatitude = Double.toString(location.getLatitude());
                            userLongitude = Double.toString(location.getLongitude());

                            numOfActivities = 1;
                            fetchYelpForOneActivity();

                            drivingTextView.setText(selectedDrivingOrUber);
                            budgetTextView.setText(selectedBudget);
                            startTimeTextView.setText(selectedStartTime);
                            endTimeTextView.setText(selectedEndTime);
                            totalHoursTextView.setText(selectedTimeHours);
                            partySizeTextView.setText(selectedPartySize);
                            moodTextView.setText(selectedMood);
                            activitiesTextView.setText(selectedActivities);
                            dateTextView.setText(selectedDate);
                            summaryNextBtn.setVisibility(View.VISIBLE);


                        }
                    }
                });
//return;
    } 


    if (drawerLayout != null) {
        // setup drawer view
        NavigationView navigationView = (NavigationView) findViewById(R.id.master_fragment_container);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                return true;
            }
        });

        // setup menu icon
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        for (int i = 0; i < toolbar.getChildCount(); i++) {
            if (toolbar.getChildAt(i) instanceof ImageButton) {
                toolbar.getChildAt(i).setScaleX(1.5f);
                toolbar.getChildAt(i).setScaleY(1.5f);
            }
        }


        // insert detail fragment into detail container
        com.example.jacob.datenight.DetailDrawerFragment detailFragment = com.example.jacob.datenight.DetailDrawerFragment.newInstance();
        android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .add(R.id.detail_fragment_container, detailFragment, TAG_DETAIL_FRAGMENT)
                .commit();

        // insert master fragment into master container (i.e. nav view)
        com.example.jacob.datenight.MasterDrawerFragment masterFragment = com.example.jacob.datenight.MasterDrawerFragment.newInstance();
        fragmentManager.beginTransaction()
                .add(R.id.master_fragment_container, masterFragment, TAG_MASTER_FRAGMENT)
                .commit();

        setupDrawer();
    }
    // End onCreate Navigation bar and list

    summaryNextBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (saveDataInputs()) {
                //Removed code here during testing
                Intent i = new Intent(SummaryLetsGoActivity.this, MainActivity.class);
                startActivity(i);
            }

        }
    });


    submissionsDatabaseRef = mFirebaseDatabase.getReference("date_night_submissions/" + userId);
    profileDatabaseRef = mFirebaseDatabase.getReference("user_profile/" + userId);
    ValueEventListener databaseListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            profile = new UserProfile(Objects.requireNonNull(dataSnapshot.child("address").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("city").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("country").getValue()).toString(),
                    Objects.requireNonNull(dataSnapshot.child("date_of_birth").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("device_registration_token").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("email_address").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("fname").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("lname").getValue()).toString(),
                    Objects.requireNonNull(dataSnapshot.child("gender").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("phone_nbr").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("photo_url").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("state").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("user_name").getValue()).toString(),
                    Objects.requireNonNull(dataSnapshot.child("zip_cd").getValue()).toString(), Objects.requireNonNull(dataSnapshot.child("communication_preference").getValue()).toString());

            userFirstName = profile.getfName();
            userLastName = profile.getlName();
            userPhoneNbr = profile.getPhoneNbr();
            userCommPref = profile.getCommunicationPref();

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            // Getting Post failed, log a message
        }
    };
    profileDatabaseRef.addValueEventListener(databaseListener);


}

// Start Navigation bar and list

@Override
public void onMasterItemClicked(int masterItemId) {
    com.example.jacob.datenight.DetailDrawerFragment detailFragment = (com.example.jacob.datenight.DetailDrawerFragment) getSupportFragmentManager()
            .findFragmentByTag(TAG_DETAIL_FRAGMENT);
    detailFragment.onMasterItemClicked(masterItemId);

    // Close the navigation drawer
    if (drawerLayout != null) {
        drawerLayout.closeDrawers();
    }
}

private void setupDrawer() {

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
            R.string.drawer_open, R.string.drawer_close) {


        /**
         * Called when a drawer has settled in a completely open state.
         */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //getSupportActionBar().setTitle(activityTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /**
         * Called when a drawer has settled in a completely closed state.
         */
        public void onDrawerClosed(View view) {

            super.onDrawerClosed(view);
            //getSupportActionBar().setTitle(activityTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

        }
    };

    drawerToggle.setDrawerIndicatorEnabled(true);
    //drawerLayout.setDrawerListener(drawerToggle);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (drawerToggle.onOptionsItemSelected(item)) {
        return true;
    }

    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_bar_profile_img) {
        Toast.makeText(SummaryLetsGoActivity.this, "Action clicked", Toast.LENGTH_LONG).show();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    drawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    drawerToggle.onConfigurationChanged(newConfig);
}

//End Navigation Drawer
//End Navigation bar and list

private void fetchYelpForOneActivity() {

    for (int i = 0; i < selectedActivityXref.length; i++) {
        if (selectedActivities.equals("Surprise")) {

            int x = new Random().nextInt(selectedActivityXref.length);
            if (x > 7) {
                x -= 3;
            }

            activitiesTerm = selectedActivityXref[x][1];

        } else if (selectedActivities.equals(selectedActivityXref[i][0])) {
            activitiesTerm = selectedActivityXref[i][1];
        }
    }



    new FetchYelp(userLatitude, userLongitude, apiKey, budgetForYelp, activitiesTerm, new FetchYelp.OnFetchFinishedListener() {
        @Override
        public void onFetchFinished(ArrayList<YelpBusiness> result) {

            if (result.size() > 0) {

                yelpBusinessesArray.addAll(result);

                ProgressBar spinner = findViewById(R.id.loading_yelp_progress);
                TextView details = findViewById(R.id.loading_results_txtview);
                RelativeLayout loadingRL = findViewById(R.id.loading_relative_layout);
                spinner.setVisibility(View.GONE);
                details.setVisibility(View.GONE);
                loadingRL.setVisibility(View.GONE);
            }

        }
    }).execute();

}

public boolean saveDataInputs() {

    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int monthInt = calendar.get(Calendar.MONTH) + 1;
    int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
    int hourInt = calendar.get(Calendar.HOUR_OF_DAY);
    int minuteInt = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);

    String monthString = String.format(Locale.getDefault(), "%02d", monthInt);
    String dayString = String.format(Locale.getDefault(), "%02d", dayInt);
    String hourString = String.format(Locale.getDefault(), "%02d", hourInt);
    String minuteString = String.format(Locale.getDefault(), "%02d", minuteInt);

    String timeStamp = year + "" + monthString + "" + dayString + ":" + hourString + ":" + minuteString + ":" + second;

    submissionsDatabaseRef.child(timeStamp).child("email_address").setValue(userEmail);
    submissionsDatabaseRef.child(timeStamp).child("device_registration_token").setValue(deviceRegistrationToken);
    submissionsDatabaseRef.child(timeStamp).child("selected_driving_or_uber").setValue(selectedDrivingOrUber);
    submissionsDatabaseRef.child(timeStamp).child("selected_mood").setValue(selectedMood);
    submissionsDatabaseRef.child(timeStamp).child("selected_activities").setValue(selectedActivities);
    submissionsDatabaseRef.child(timeStamp).child("selected_budget").setValue(selectedBudget);
    submissionsDatabaseRef.child(timeStamp).child("selected_party_size").setValue(selectedPartySize);
    submissionsDatabaseRef.child(timeStamp).child("selected_date").setValue(selectedDate);
    submissionsDatabaseRef.child(timeStamp).child("selected_start_time").setValue(selectedStartTime);
    submissionsDatabaseRef.child(timeStamp).child("selected_end_time").setValue(selectedEndTime);
    submissionsDatabaseRef.child(timeStamp).child("selected_time_hours").setValue(selectedTimeHours);
    submissionsDatabaseRef.child(timeStamp).child("screen_sequence").setValue("LetsGo");
    submissionsDatabaseRef.child(timeStamp).child("submission_timestamp").setValue(timeStamp);

    if (numOfActivities == 1) {

        if (yelpBusinessesArray.size() > 0) {

            if(yelpBusinessesArray.size()==1){
                randomInt1 = 0;
                loadFirstArrayValues(timeStamp, randomInt1);
                loadBlankSecondArrayValues(timeStamp);
            } else {
                randomInt1 = new Random().nextInt(yelpBusinessesArray.size() - 1);
                if(randomInt1 <= yelpBusinessesArray.size()){
                    loadFirstArrayValues(timeStamp, randomInt1);
                    loadBlankSecondArrayValues(timeStamp);
                } else
                {
                    randomInt1 = yelpBusinessesArray.size();
                    loadFirstArrayValues(timeStamp, randomInt1);
                    loadBlankSecondArrayValues(timeStamp);
                }

            }

        } else {
            loadBlankFirstArrayValues(timeStamp);
            loadBlankSecondArrayValues(timeStamp);
        }

    }

    return true;

}


private void loadFirstArrayValues(String timeStamp, int array1randomInt){

    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_name").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessName());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_rating").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessRating());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_term").setValue(yelpBusinessesArray.get(array1randomInt).getYelpBusinessTermValue());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_address1").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessAddress1());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_address2").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessAddress2());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_zipCd").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessZipCode());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_city").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessCity());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_state").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessState());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_country").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessCountry());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_cross_streets").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessCrossStreets());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_avg_price").setValue(yelpBusinessesArray.get(array1randomInt).getAvgPrice());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_open_time").setValue("NULL");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_close_time").setValue("NULL");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_latitude").setValue(yelpBusinessesArray.get(array1randomInt).getBusinesslatitude());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_longitude").setValue(yelpBusinessesArray.get(array1randomInt).getBusinesslongitude());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_distance").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessDistance());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_review_count").setValue(yelpBusinessesArray.get(array1randomInt).getReviewCount());
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_is_closed").setValue(yelpBusinessesArray.get(array1randomInt).getIsClosed());

    if (yelpBusinessesArray.get(array1randomInt).getBusinessCrossStreets() != null) {
        submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_cross_streets").setValue(yelpBusinessesArray.get(array1randomInt).getBusinessCrossStreets());
    } else {
        submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_cross_streets").setValue("NULL");
    }

}

private void loadBlankFirstArrayValues(String timeStamp){

    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_name").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_rating").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_term").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_address1").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_address2").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_zipCd").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_city").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_state").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_country").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_cross_streets").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_avg_price").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_open_time").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_close_time").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_latitude").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_longitude").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_distance").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_review_count").setValue(0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_is_closed").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location1_cross_streets").setValue("No Results");

}

private void loadBlankSecondArrayValues(String timeStamp){

    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_name").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_rating").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_term").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_address1").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_address2").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_zipCd").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_city").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_state").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_country").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_cross_streets").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_avg_price").setValue("No Results");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_open_time").setValue("NULL");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_close_time").setValue("NULL");
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_latitude").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_longitude").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_distance").setValue(0.0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_review_count").setValue(0);
    submissionsDatabaseRef.child(timeStamp).child("chosen_activity_location2_is_closed").setValue("No Results");

}
}

posted this

Have an answer?

JD

Please login first before posting an answer.