在第一个活动中,我有一个代数运算,我需要将第一个活动的结果传递给第二个活动。我偷了我找到的所有东西,但我是一个 android 初学者,所以我找不到真正的问题。
这是第一个活动:
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Contar extends MainActivity{
public EditText et1, et2, et3;
public TextView tv1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contar);
et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
et3=(EditText)findViewById(R.id.et3);
tv1=(TextView)findViewById(R.id.tv1);
}
public void contarbesos(View view){
String meses=et1.getText().toString();
String bd=et2.getText().toString();
String dsvs=et3.getText().toString();
int nro1=Integer.parseInt(meses);
int nro2=Integer.parseInt(bd);
int nro3=Integer.parseInt(dsvs);
int sm=4;
int dsvm;
int dvm;
int dr;
int besos;
int dsv;
dr=nro1*30;
dsv=nro3*sm;
dsvm=nro1*dsv;
dvm=dr-dsvm;
besos=dvm*nro2;
Intent i = new Intent(this, Resultado.class );
i.putExtra("besos", besos);
startActivity(i);
}
}
第二个活动:
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Resultado extends Contar {
public TextView tv1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultado);
tv1=(TextView)findViewById(R.id.tv1);
Bundle bundle = getIntent().getExtras();
String intValue = bundle.getString("besos");
tv1.setText(intValue);
}
}
和 logcat 中的错误(更新):
07-13 23:40:14.084: E/AndroidRuntime(768): FATAL EXCEPTION: main
07-13 23:40:14.084: E/AndroidRuntime(768): java.lang.RuntimeException: Unable to start activity ComponentInfo{whao.whaoapps.kisscounter/whao.whaoapps.kisscounter.Resultado}: android.content.res.Resources$NotFoundException: String resource ID #0x30c
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.os.Looper.loop(Looper.java:137)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.ActivityThread.main(ActivityThread.java:5039)
07-13 23:40:14.084: E/AndroidRuntime(768): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 23:40:14.084: E/AndroidRuntime(768): at java.lang.reflect.Method.invoke(Method.java:511)
07-13 23:40:14.084: E/AndroidRuntime(768): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-13 23:40:14.084: E/AndroidRuntime(768): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-13 23:40:14.084: E/AndroidRuntime(768): at dalvik.system.NativeStart.main(Native Method)
07-13 23:40:14.084: E/AndroidRuntime(768): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x30c
07-13 23:40:14.084: E/AndroidRuntime(768): at android.content.res.Resources.getText(Resources.java:230)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.widget.TextView.setText(TextView.java:3640)
07-13 23:40:14.084: E/AndroidRuntime(768): at whao.whaoapps.kisscounter.Resultado.onCreate(Resultado.java:20)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.Activity.performCreate(Activity.java:5104)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-13 23:40:14.084: E/AndroidRuntime(768): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-13 23:40:14.084: E/AndroidRuntime(768): ... 11 more