Good day! Interested in such a question. There is a MainActivity

@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Spinner spinner = (Spinner) findViewById(R.id.bodySpiner); bodySelected = spinner.getSelectedItem().toString(); Test1 = position; Intent intent = new Intent(getBaseContext(), Engine.class); intent.putExtra("Test1", Test1); startActivity(intent); } @Override public void onNothingSelected(AdapterView<?> arg0) { } 

In Engine.class

  Intent i = getIntent(); String id = i.getStringExtra("Test1"); 

Is it possible to somehow transfer the int value of the selected position? Just based on this choice, I need to do a sorting.

  • 2
    do i.getIntExtra(Test1) or what's the problem? - Jarvis_J
  • it does not allow me to call i.getIntExtra (Test1) directly, It is only possible to getIntExtra (String name, int defaultValue), I entered all positions from 0 to max number of positions in my spiner in defaultValue, it still crashed with NPE - Nexx
  • @Nexx defaultValue will be returned from the method if no value is found by the passed key. Attach a standard error. - temq
  • @ temqjava.lang.RuntimeException: Unable to instantiate activity ComponentInfo {com.example.nexxie.diplom2 / com.example.nexxie.diplom2.Engine}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchword ActivityThreadingThreadPointerException at android.app.ActivityThread.performLaunchHeathEngineThreadPointerException 2232) at com.example.nexxie.diplom2.Engine. <Init> (Engine.java:55) - Nexx
  • and what is the variable Test1 in general? put in the intent position immediately. Everything should work with any default, see the problem elsewhere. Perhaps you are running an intent not in a UI thread? - Jarvis_J

2 answers 2

You pass int , and you try to get Stirng , use int getIntExtra(String name, int defaultValue) method int getIntExtra(String name, int defaultValue)

  • @ katsoА question, what value to enter in dtfaultValue? I chose from 0 to the end of the count of my positions and he always cursed NullPointerException It was on this line - Nexx

In general, I am a fool. I forgot that in the Engine class I used RecicleView. And output intant after implementing RecicleView. Thanks to all.!