Итак, я пытаюсь создать программу, которая отслеживает GPS-координаты, а затем отображает их в реальном времени в виде списка на боковой панели моего основного экрана. Макет выглядит следующим образом:
_______
|{} |LV|
| | |
| | |
| | |
|___|__|
{}= кнопка
LV = вертикальная прокрутка списка
В процессе создания я создаю:
public void onCreate(Bundle bundleIn) {
super.onCreate(bundleIn);
setContentView(R.layout.main);
retrieveLocationButton = (Button)findViewById(R.id.retrieve_location_button);
bottomList = (ListView)findViewById(R.id.myListView);
AllLocals.add("1");
bottomList.setAdapter(new ArrayAdapter<String>(this.getApplicationContext(), R.id.simple_text, AllLocals));
//viewCollectedData = (Button)findViewById(R.id.view_lat_lon_data);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//setListAdapter(new ArrayAdapter<Location>(this,android.R.layout.simple_list_item_1,AllLocals));
Файл XML выглядит следующим образом:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button android:layout_height="wrap_content"
android:text="Get Local"
android:id="@+id/retrieve_location_button"
android:layout_width="wrap_content">
</Button>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:id="@+id/simple_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</LinearLayout>
программа не работает, и я не уверен, что здесь неправильный файл журнала:
09-07 15:37:20.301: ERROR/AndroidRuntime(294): FATAL EXCEPTION:
main
09-07 15:37:20.301: ERROR/AndroidRuntime(294): java.lang.RuntimeException:
Unable to start activity ComponentInfo{geolocation.test/geolocation.test.GeoLocationActivity}: java.lang.NullPointerException
09-07 15:37:20.301: ERROR/AndroidRuntime(294):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-07 15:37:20.301:
ERROR/AndroidRuntime(294):
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-07 15:37:20.301:
ERROR/AndroidRuntime(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at android.os.Looper.loop(Looper.java:123)
09-07 15:37:20.301:
ERROR/AndroidRuntime(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invoke(Method.java:521)
09-07 15:37:20.301:
ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): at dalvik.system.NativeStart.main(Native Method)
09-07 15:37:20.301: ERROR/AndroidRuntime(294):
Caused by: java.lang.NullPointerException
09-07 15:37:20.301: ERROR/AndroidRuntime(294):
at geolocation.test.GeoLocationActivity.onCreate(GeoLocationActivity.java:47)
09-07 15:37:20.301:
ERROR/AndroidRuntime(294):
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-07 15:37:20.301:
ERROR/AndroidRuntime(294):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-07 15:37:20.301: ERROR/AndroidRuntime(294): ... 11 more
Иногда в следующей строке есть нулевое исключение:
bottomList.setAdapter(new ArrayAdapter<String>(this.getApplicationContext(), R.id.simple_text, AllLocals));
У меня нетПонять почему.Помощь очень ценится.