1つのアクティビティアプリからのパスによりクラッシュしました。 いくつか私を助けることができます。 私は複数の方法を試してみました。 おかげさまで、ありがとうございました。1つのアクティビティから他のアンドロイドアプリケーションへの値渡し
package com.wing.test2.test2; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; public class person extends AppCompatActivity { Button submit_person; EditText user_ida,name,gander,age; //Intent patient_data = new Intent(this, patient.class); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_person); submit_person = (Button) findViewById(R.id.submit_person); user_ida = (EditText) findViewById(R.id.userid); name = (EditText) findViewById(R.id.name); gander = (EditText) findViewById(R.id.gander); age = (EditText) findViewById(R.id.age); submit_person.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Log.v("EditText", user_ida.getText().toString()); Log.v("EditText", name.getText().toString()); Log.v("EditText", gander.getText().toString()); Log.v("EditText", age.getText().toString()); String user_id = user_ida.getText().toString(); String user_name = name.getText().toString(); String user_gander = gander.getText().toString(); String user_a = age.getText().toString(); Intent patient_data =new Intent(getApplicationContext(),patient.class); patient activity = new patient(); activity.displayInfo(user_name,user_gander,user_id,user_a); startActivity(patient_data); /*patient_data.putExtra("id",user_id); patient_data.putExtra("name", user_name); patient_data.putExtra("gander", user_gander); patient_data.putExtra("age", user_a); startActivity(patient_data); */ } }); } }
======================================= =======
他の活動
パッケージcom.wing.test2.test2。ここ
import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.widget.EditText; import android.widget.TextView; public class patient extends person { //Intent patient_data = getIntent(); person patient_data = new person(); TextView textView2,textView,textView3,textView4; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.patient); Log.v("EditText", patient_data.toString()); /* String user_id = patient_data.getStringExtra("id"); String name = patient_data.getStringExtra("name"); String gander = patient_data.getStringExtra("gander"); String user_age = patient_data.getStringExtra("age"); textView2 = (TextView) findViewById(R.id.textView2); textView = (TextView) findViewById(R.id.textView); textView3 = (EditText) findViewById(R.id.textView3); textView4 = (TextView) findViewById(R.id.textView4); textView2.setText(user_id); textView.setText(name); textView3.setText(gander); textView4.setText(user_age);*/ } public void displayInfo(String name, String gander, String user_ida, String age) { textView2 = (TextView) findViewById(R.id.textView2); textView = (TextView) findViewById(R.id.textView); textView3 = (EditText) findViewById(R.id.textView3); textView4 = (TextView) findViewById(R.id.textView4); textView2.setText((CharSequence) user_ida); textView.setText((CharSequence) name); textView3.setText((CharSequence) gander); textView4.setText((CharSequence) age); } }
エラーログ
02-10 02:35:08.651 19910-19910/com.wing.test2.test2 D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
02-10 02:35:08.721 19910-19910/com.wing.test2.test2 V/EditText: 12
02-10 02:35:08.731 19910-19910/com.wing.test2.test2 V/EditText: 12
02-10 02:35:08.731 19910-19910/com.wing.test2.test2 V/EditText: 233
02-10 02:35:08.731 19910-19910/com.wing.test2.test2 V/EditText: Wer
02-10 02:35:08.741 19910-19910/com.wing.test2.test2 D/AndroidRuntime: Shutting down VM
02-10 02:35:08.751 19910-19910/com.wing.test2.test2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wing.test2.test2, PID: 19910
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:68)
at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:190)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:172)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:512)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:184)
at com.wing.test2.test2.patient.displayInfo(patient.java:39)
at com.wing.test2.test2.person$1.onClick(person.java:47)
at android.view.View.performClick(View.java:5076)
at android.view.View$PerformClick.run(View.java:20279)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5910)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
02-10 02:35:26.458 19910-19910/com.wing.test2.test2 I/Process: Sending signal. PID: 19910 SIG: 9
エラーのスタックトレースを投稿してください。 –
なぜ 'activity'ではなく' person'を拡張していますか? – rafsanahmad007