2014-03-19 16 views
0

我想將值設置爲String array,但它不成功。無法將值存儲到字符串android

我不知道確切的問題是什麼。

public String[] history = null; 
    public String record; 
    public int counter = 0;` 

    public void createString (String record){  
     history[counter] = record; 
     counter++; 
    } 

這裏是定義變量。

我做了什麼錯誤,以及如何解決它?

03-19 17:15:35.870: W/dalvikvm(4937): threadid=1: thread exiting with uncaught exception (group=0x40c20450) 


03-19 17:15:35.890: E/AndroidRuntime(4937): FATAL EXCEPTION: main 

03-19 17:15:35.890: E/AndroidRuntime(4937): java.lang.NullPointerException 

03-19 17:15:35.890: E/AndroidRuntime(4937):  at com.airportapplication.app.Buses.createString(Buses.java:147) 

03-19 17:15:35.890: E/AndroidRuntime(4937):  at com.airportapplication.app.Buses$1.onClick(Buses.java:101) 
+0

被它給任何錯誤? – Nand

+2

請提供更多詳情。 – user370305

+0

顯示你的日誌貓.. – pavanmvn

回答

0

需要初始化您的數組 這樣的:

String[] history = new String[lengthOfArray]; 

,如果你不知道數組長度使用此:

List<String> history = new ArrayList<String>(); 
history.add(record);