从一个活动应用程序传递崩溃。 有人能帮我吗。 我尝试了多种方法。 先谢谢你们所有人。
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 ); */ } } ); } }
============================================== < / p>
包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
答案 0 :(得分:3)
试试这个:在你的第一个活动中
patient activity = new patient();
activity.displayInfo(user_name,user_gander,user_id,user_a);
同样删除:
public class patient extends Activity {
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() );
Intent patient_data = getIntent();
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);
}
}
现在进行第二次活动:
import requests
from bs4 import BeautifulSoup
result = requests.get("https://en.wikipedia.org/wiki/List_of_Game_of_Thrones_episodes")
result
page = result.content
soup = BeautifulSoup(page, "lxml")
soup
table = soup.find("table", {"class" : "wikitable plainrowheaders wikiepisodetable"})
table
f = open('output.csv', 'w')
for row in table.findAll("th"):
cells = row.findAll("td")
if len(cells) == 7:
No_overall = cells[0].find(text = True)
No_in_season = cells[1].find(text = True)
Title = cells[2].find(text = True)
Directed_by = cells[3].find(text = True)
Written_by = cells[4].find(text = True)
Original_air_date = cells[5].find(text = True).replace(',','')
US_viewers = cells[6].find(text = True).replace('.','')
line = No_overall + "," + No_in_season + "," + Title + "," +
Directed_by +"," + Written_by + "," + Original_air_date + "," +
US_viewers + "\n"
print(line)
f.write(write_to_file)
答案 1 :(得分:2)
你需要在Manifest中声明它。 (根据错误登录图片)
您将textView定义为EditText。
textView3 =(EditText / 将其替换为TextView /)findViewById(R.id.textView3);