我在 Android 中使用二维码扫描器,我想要拆分值,但我无法将结果从 ScanActivity 发送到 Main_Activity,导致程序崩溃,我在下面有错误
(引起:java.lang.NullPointerException:尝试在 com.exampledemo.parsaniahardik.scanbarcodeqrdemonuts 的空对象引用上调用虚拟方法“java.lang.String android.os.BaseBundle.getString(java.lang.String)”。 MainActivity.onCreate(MainActivity.java:26))
有人可以帮我吗?
*** MainActivity Code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn);
Bundle my_split = getIntent().getExtras();
String st = my_split.getString("tvresult1");
String totale = st;
String [] parte = totale.split("-");
part1 = parte[0];
part2 = parte[1];
part3 = parte[2];
part4 = parte[3];
part5 = parte[4];
part6 = parte[5];
MainActivity.Name.setText(""+part1);
MainActivity.TNumber.setText(""+part2);
MainActivity.date.setText(""+part3);
MainActivity.numberOf.setText(""+part4);
MainActivity.sum.setText(""+part5);
MainActivity.amount.setText(""+part6);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ScanActivity.class);
startActivity(intent);
}
});
牛魔王的故事
largeQ
相关分类