i have a spinner with two values and a button to go to the next activity if selected the first the second activity will contain an image and text if the second is selected the second activity will contain another image and text but when i press the button to go to the second activity it always crashes
public class MainActivity extends AppCompatActivity {
Spinner companies;
Button infoButton;
Button linkButton;
ArrayList<String> alCompanies;
ImageView cLogo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
companies = findViewById(R.id.main_sp_companies);
infoButton = findViewById(R.id.main_btn_info);
linkButton = findViewById(R.id.main_btn_link);
alCompanies = new ArrayList<>();
alCompanies.add("Google");
alCompanies.add("Microsoft");
ArrayAdapter<String> arrayAdapterCompanies = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_spinner_item, alCompanies);
arrayAdapterCompanies.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
companies.setAdapter(arrayAdapterCompanies);
infoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (companies.getSelectedItem().equals("Google")) {
Intent intent = new Intent(MainActivity.this, ActivityOne.class);
cLogo.setImageResource(R.drawable.googlelogo);
cLogo.setContentDescription(companies.getSelectedItem().toString());
startActivity(intent);
}
else {
companies.getSelectedItem();
Intent intent = new Intent (MainActivity.this,ActivityOne.class);
cLogo.setImageResource(R.drawable.micrsoftlogo);
cLogo.setContentDescription(companies.getSelectedItem().toString());
startActivity(intent);
}
}
});
this the mian
public class ActivityOne extends AppCompatActivity {
public static final String EXTRA_INFO = "info";
//Spinner companies = findViewById(R.id.main_sp_companies);
ImageView cLogo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
Intent intent = getIntent();
/* if (companies.getSelectedItem().equals("Google")) {
cLogo.setImageResource(R.drawable.googlelogo);
cLogo.setContentDescription(companies.getSelectedItem().toString());
}
else {
companies.getSelectedItem();
cLogo.setImageResource(R.drawable.micrsoftlogo);
cLogo.setContentDescription(companies.getSelectedItem().toString());
}*/
}
}
this is the first activity
i want the user chose from the spinner and depends on their choice will be the second activity if Google was chosen the logo and the description will be the one about google but Microsoft will be about the Microsoft