gpt4 book ai didi

java - 保存数据和传输到另一个 Activity 时出现问题(使用 FireBase)

转载 作者:行者123 更新时间:2023-12-02 00:56:32 25 4
gpt4 key购买 nike

我在尝试通过两个 EditText 保存数据输入(来自用户)并将其传输到另一个应显示为 ViewText 的 Activity 时遇到问题。

来自 Activity/数据输入的代码

public class DatosBasicos extends AppCompatActivity {

EditText presion;
EditText ritmo;
Button atriaje;
String valorritmo;
String valorpresion;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_datos_basicos);

atriaje = (Button) findViewById(R.id.triaj);
presion = (EditText) findViewById(R.id.presion);
ritmo = (EditText) findViewById(R.id.ritmo);
atriaje.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

valorritmo = ritmo.getText().toString();
valorpresion = presion.getText().toString();
Intent i = new Intent(DatosBasicos.this, Triaje.class);
i.putExtra("PRESION",valorpresion);
i.putExtra("RITMO",valorritmo);
startActivity(i);
finish();
}
});

}
}

来自 Activity/数据输出的代码

public class Triaje extends AppCompatActivity {

TextView rit, pres;
String ritS, presS;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_triaje);

rit = (TextView) findViewById(R.id.ritmoval);
pres = (TextView) findViewById(R.id.presionval);

ritS = getIntent().getExtras().getString("PRESION");
presS = getIntent().getExtras().getString("RITMO");

rit.setText(ritS);
pres.setText(presS);
}
}

错误日志

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aplicaciontriaje, PID: 2569
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aplicaciontriaje/com.example.aplicaciontriaje.Triaje}: java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.TextView
at com.example.aplicaciontriaje.Triaje.onCreate(Triaje.java:19)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Disconnected from the target VM, address: 'localhost:8619', transport: 'socket'

应用程序应该做什么我希望将数据输入到我的 Triaje Activity 中并显示在两个相应的 ViewText 中。我收到以下错误:“应用程序不断停止”

最佳答案

可以调试系统吗?然后你就清楚地明白它在哪里给你带来了错误!然后准确说出在哪一行出错!

关于java - 保存数据和传输到另一个 Activity 时出现问题(使用 FireBase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57813716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com