저는 안드로이드가 처음이고 HTTP를 통해 localhost에서 데이터를 제공하고 XML로 파싱하여 android에 목록으로 표시하는 프로그램을 가지고 있습니다.하지만 할 수 없습니다. 새 페이지 (목록을 표시하는 페이지)로 전환하십시오. 내 프로그램에는 java.lang.NullPointerException
예외가 있으며 어디에서 null.please를 제공하는지 알 수 없으며 무엇을해야하는지 알려줍니다.액티비티를 시작할 수 없습니다. ComponentInfo Java.lang.nullExeption
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sara.patientapplication/com.example.sara.patientapplication.ViewAllPatientActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.sara.patientapplication.ViewAllPatientActivity.onCreate(ViewAllPatientActivity.java:45)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)at android.app.ActivityThread.access$600(ActivityThread.java:130)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:4745)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:511)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)at dalvik.system.NativeStart.main(Native Method)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)at android.app.ActivityThread.access$600(ActivityThread.java:130)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:4745)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:511)at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
: 이 오류 메시지입니다
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".mainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show All Patients"
android:id="@+id/ShowAllPatients"
android:layout_marginTop="25dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New Patient"
android:id="@+id/AddNewP"
android:layout_below="@+id/ShowAllPatients"
android:layout_marginTop="10dp"/>
</RelativeLayout>
이것은 Activity.there가 버튼입니다 주요 내가 그것을 누를 때 나는 목록에 있지만에서 이동 예상 시간 예외가 발생합니다.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Button ShowAllPatient=(Button)findViewById(R.id.ShowAllPatients);
Button AddNewPatient=(Button)findViewById(R.id.AddNewP);
ShowAllPatient.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),ViewAllPatientActivity.class);
startActivity(i);
}
});
}
이 내 목록 레이아웃 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"></ListView>
</LinearLayout>
이 내 목록 활동 :
public class ViewAllPatientActivity extends ListActivity {
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser=new XMLParser();
static final String URL="http://localhost/AllPatient.php";
static final String Patient_ID="PatientId";
static final String First_Name="PatientFirstName";
static final String Last_Name="PatientLastName";
//static final String Blood_Type="BloodType";
//static final String Phone_Number="phoneNumber";
//static final String Practitioner_ID="practitionerId";
//static final String Email="Email";
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.all_patient);
// String xml=parser.GetXml(URL);
Document doc=parser.DomElement("http://localhost/AllPatient.php");
NodeList nl = doc.getElementsByTagName(Patient_ID);
for (int i=0;i<nl.getLength();i++){
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put(Patient_ID,parser.GetValue(e , Patient_ID));
map.put(First_Name,parser.GetValue(e,First_Name));
map.put(Last_Name,parser.GetValue(e,Last_Name));
// map.put(Blood_Type,parser.GetValue(e,Blood_Type));
// map.put(Phone_Number,parser.GetValue(e,Phone_Number));
// map.put(Email,parser.GetValue(e,Email));
// map.put(Practitioner_ID,parser.GetValue(e,Practitioner_ID));
menuItems.add(map);
}
ListAdapter adapter=new SimpleAdapter(this,menuItems,R.layout.list_item,
new String[]{Patient_ID,First_Name,Last_Name},new int[]{R.id.pid,R.id.fName,R.id.lName});
setListAdapter(adapter);
ListView lv=getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String Patient_id = ((TextView) view.findViewById(R.id.pid)).getText().toString();
String First_name = ((TextView) view.findViewById(R.id.fName)).getText().toString();
String Last_name = ((TextView) view.findViewById(R.id.lName)).getText().toString();
Intent in = new Intent(getApplicationContext(), SingleListPatient.class);
in.putExtra(Patient_ID, Patient_id);
in.putExtra(First_Name, First_name);
in.putExtra(Last_Name, Last_name);
startActivity(in);
}
});
}
또한 내가 하나의리스트 항목에 대한 몇 가지 레이아웃이 있습니다
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"><TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" /><TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" /></LinearLayout>
을
및
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textStyle="bold"
android:padding="10dp"
android:id="@+id/firstN"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textStyle="bold"
android:padding="10dp"
android:id="@+id/lastN"
android:layout_toRightOf="@+id/firstN"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:text="Patient ID: "
android:id="@+id/paId"
android:layout_below="@+id/firstN"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:id="@+id/patientid"
android:layout_toRightOf="@+id/paId"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:text="Blood Type: "
android:id="@+id/bt"
android:layout_below="@+id/paId"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:id="@+id/btype"
android:layout_toRightOf="@+id/bt"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:text="Phone Number: "
android:id="@+id/pn"
android:layout_below="@+id/bt"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:id="@+id/pnum"
android:layout_toRightOf="@+id/pn"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:text="Email: "
android:id="@+id/em"
android:layout_below="@+id/pn"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textStyle="bold"
android:padding="10dp"
android:id="@+id/mail"
android:layout_toRightOf="@+id/em"/>
</RelativeLayout>
도와주세요. 덕분에 .
무엇의 라인 (45)? –
이 줄의 onCreate (ViewAllPatientActivity.java:45)는 무엇입니까? .................... –
저는 의사가 null 인 것을 확인 했습니까? –