Java – how to set text to an integer and get int without receiving an error
                                        
                    •
                    Java                                    
                I'm trying to get intent from integers String fetch intent works normally and displays well, but when I put integers, I get a forced close error
package kfc.project;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class productdetail extends Activity{
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.productdetail);
        //stuff to get intent
        Intent receivedIntent = getIntent();
        String productName = receivedIntent.getStringExtra("name");
        int productCalories = receivedIntent.getIntExtra("calories",0);
        Bundle extras = getIntent().getExtras();
        String name = extras.getString("name");
        if (name != null) {
            TextView text1 = (TextView) findViewById(R.id.servingsize);
            text1.setText(productName);
        }
        //int calories = extras.getInt("calories");
            TextView text1 = (TextView) findViewById(R.id.calories);
            text1.setText(productCalories);
    }
}
Solution
TextView text1 = (TextView) findViewById(R.id.calories);
TextView text1 = (TextView) findViewById(R.id.calories);
text1.setText(""+productCalories);
or
text1.setText(String.valueOf(productCalories));
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        