我是android的新手。我想将用户在MainActivity.java中的dropdown-spinner中选择的内容发送到SecondClass.java,并且我正在使用intent但是应用程序被强制关闭并且日志正在说
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hitesh.recommend/com.example.hitesh.recommend.SecondClass}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
MainActivity
Spinner dropdown = findViewById(R.id.spinner1);
String[] items = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items);
dropdown.setAdapter(adapter);
Spinner dropdown1 = findViewById(R.id.spinner2);
String[] items1 = new String[]{"9", "10", "11", "12", "1", "2", "3", "4", "5", "6", "7", "8"};
ArrayAdapter<String> adapter1 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items1);
dropdown1.setAdapter(adapter1);
String ConcatedString1 = dropdown2.getSelectedItem().toString().concat(dropdown3.getSelectedItem().toString());
Intent intent = new Intent(MainActivity.this,SecondClass.class);
intent.putExtra("username",dropdown2.getSelectedItem().toString().concat(dropdown3.getSelectedItem().toString()));
startActivity(intent);
二等
String string = getIntent().getExtras().getString("username");
TextView h2 = (TextView) findViewById(R.id.src);
h2.setText(string);
我再次处于学习阶段。我在这做错了什么? 感谢您的建议