java.lang.NumberFormatException: unable to parse '' as integer one more time
        Posted  
        
            by 
                Quzziy
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Quzziy
        
        
        
        Published on 2014-08-25T03:58:44Z
        Indexed on 
            2014/08/25
            4:20 UTC
        
        
        Read the original article
        Hit count: 227
        
I will take two numbers from user, but this number from EditText must be converted to int. I think it should be working, but I still have problem with compilation code in Android Studio.
CatLog show error in line with:
int wiek = Integer.parseInt(wiekEditText.getText().toString());
Below is my full Android code:
public class MyActivity extends ActionBarActivity {
    int Wynik; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        int Tmax, RT;
        EditText wiekEditText = (EditText) findViewById(R.id.inWiek);
        EditText tspoczEditText = (EditText) findViewById(R.id.inTspocz);
        int wiek = Integer.parseInt(wiekEditText.getText().toString());
        int tspocz = Integer.parseInt(tspoczEditText.getText().toString());
        Tmax = 220 - wiek;
        RT = Tmax - tspocz;
        Wynik = 70*RT/100 + tspocz;
        final EditText tempWiekEdit = wiekEditText;
        TabHost tabHost = (TabHost) findViewById(R.id.tabHost);   //Do TabHost'a z layoutu
        tabHost.setup();                         
        TabHost.TabSpec tabSpec = tabHost.newTabSpec("Calc");
        tabSpec.setContent(R.id.Calc);
        tabSpec.setIndicator("Calc");
        tabHost.addTab(tabSpec);
        tabSpec = tabHost.newTabSpec("Hints");                    
        tabSpec.setContent(R.id.Hints);
        tabSpec.setIndicator("Hints");
        tabHost.addTab(tabSpec);
        final Button Btn = (Button) findViewById(R.id.Btn);      
        Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),"blablabla"+ "Wynik",Toast.LENGTH_SHORT).show();
            }
        });
        wiekEditText.addTextChangedListener(new TextWatcher() {      
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Btn.setEnabled(!(tempWiekEdit.getText().toString().trim().isEmpty()));
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // 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();
        if (id == R.id.action_settings) {
            return true;
        }
       return super.onOptionsItemSelected(item);
    }
}
© Stack Overflow or respective owner