本文介绍了Android的包不会结转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是新来这个网站也还挺新到Android编程...

Hello I am new to this site also kinda new to android programming...

我每次点击按钮进入到下一个活动,我得到一个强制关闭。我知道这个活动的作品,因为我注释掉包..任何人都知道我在做什么错了?

Every time I click the button to go to next activity I get a force close. I know the activity works because I commented out the bundles.. anyone know What I am doing wrong?

// click button on 1st activity

    Intent iCreate = new 
Intent("silver.asw.charactersheet.CREATECHARACTER");
        iCreate.putExtra("cname",item);
        startActivity(iCreate);

// on item select
item = spin.getItemAtPosition(position).toString();
// spinner is being populated by sql database


// 2nd activity
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.character);
    TextView character = (TextView)findViewById(R.id.tvViewCharacter);

    Bundle b = this.getIntent().getExtras();
    String item = b.getString("cname");
    character.setText(item);
}

另外,我没有任何警告或不能检查我的logcat的,因为我使用AIDE这是一个Android应用程序的IDE。 (之前我离开了家,同样的问题我已经测试了这个code我的电脑上。)

Also, I dont have any warnings or cant check my logcat as I am using AIDE which is an android app ide. (I have tested this code on my computer before I left home, same issue.)

推荐答案

如果您使用此code

If you used this code

    Intent iCreate = new Intent("silver.asw.charactersheet.CREATECHARACTER");
    iCreate.putExtra("cname",item);
    startActivity(iCreate);

在你的第二个活动,就可以使用这个样子。

In your second activity,you can use like this.

// 2nd activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.character);
TextView character = (TextView)findViewById(R.id.tvViewCharacter);

String item = getIntent().getExtras()..getString("cname");
character.setText(item);
}

或者另一种方式,你可以使用这样,

Or another way you can use like this,

    Intent iCreate = new Intent("silver.asw.charactersheet.CREATECHARACTER");
    Bundle b=new Bundle();
    b.putString("cname", item);
    iCreate.putExtras(bundle);
    startActivity(iCreate);

在你的第二个活动

/ 2nd activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.character);
TextView character = (TextView)findViewById(R.id.tvViewCharacter);
Bundle b = getIntent().getExtras();
String item = b.getString("cname");
character.setText(item);
}

这篇关于Android的包不会结转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:46