user1072908 user1072908 - 1 year ago 45
Android Question

how to set text an integer and get int without getting error

This is the code i used in getting the intent for integer. The String get intent works fine and displays well but when i put the integer i get a force close error. I might be doing something wrong here. This is the code:

package kfc.project;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class productdetail extends Activity{

protected void onCreate(Bundle bundle) {
// TODO Auto-generated method stub
//stuff to get intent
Intent receivedIntent = getIntent();

String productName = receivedIntent.getStringExtra("name");
int productCalories = receivedIntent.getIntExtra("calories",0);

/*Intent intent = new Intent(ProductListView.this, productdetail.class);
intent.putExtra("calories", product.getCalories());
intent.putExtra("serving size", product.getServingSize());
intent.putExtra("fat", product.getFat());
intent.putExtra("saturated fat", product.getSaturatedFat());
intent.putExtra("trans fat", product.getTransFat());
intent.putExtra("cholesterol", product.getCholesterol());
intent.putExtra("sodium", product.getSodium());
intent.putExtra("carbs", product.getCarbs());
intent.putExtra("fiber", product.getFiber());
intent.putExtra("sugar", product.getSugar());
intent.putExtra("protein", product.getProtein());
intent.putExtra("vitamina", product.getVitaminA());
intent.putExtra("vitaminc", product.getVitaminC());
intent.putExtra("calcium", product.getCalcium());
intent.putExtra("iron", product.getIron());*/
Bundle extras = getIntent().getExtras();

String name = extras.getString("name");

if (name != null) {
TextView text1 = (TextView) findViewById(;

//int calories = extras.getInt("calories");

TextView text1 = (TextView) findViewById(;

Intent intent = getIntent();
String str = intent.getStringExtra("name");*/



Answer Source
    TextView text1 = (TextView) findViewById(;

String s = String.valueOf(productCalories);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download