2011-09-07 46 views
0

所以我想创建一个程序,跟踪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 

Apprently存在于下一行空例外:

bottomList.setAdapter(new ArrayAdapter<String>(this.getApplicationContext(), R.id.simple_text, AllLocals)); 

我不知道为什么。非常感谢帮助。

+0

告诉我UR清单文件 – confucius

+0

<清单的xmlns前:安卓=“http://schemas.android .com/apk/res/android“ package =”geolocation.test“
---名称匹配,我可以运行该程序,如果我删除视图列表,因此我假设问题在那里 – Aziz

+0

你有一个semi- android命名空间之后的列? xmlns:android =“schemas.android.com/apk/res/android”; ???? – confucius

回答

1

OK试试这个 bottomList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, AllLocals));并确保ü初始化AllLocalsü调用此方法

AllLocals = new ArrayList<String>();

+0

这不是我的情况问题 – Aziz

+0

好吧试试这个 bottomList.setAdapter(new ArrayAdapter (this,android.R.layout.simple_list_item_1,AllLocals )); 告诉我结果是什么,并确保在您调用此方法之前初始化AllLocals。AllLocals = new ArrayList (); – confucius

+0

是的! ^^这工作非常感谢您的时间! – Aziz

相关问题