2011-01-26 47 views
1

我試圖運行下面的Android應用程序,但我得到一個NullPointerException的NullPointerException在JdwpPaquet

Main.java

import android.app.ListActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class Main extends ListActivity { 
String[] listActivityNames = 
    {"Text1", "Text2", "Text3", "Text4"}; 

    /** Called when the activity is first created. */ 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

     // Use an existing ListAdapter that will map an array 
     // of strings to TextViews 

     setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listActivityNames)); 
     getListView().setTextFilterEnabled(true); 
} 

/*protected void onListItemClick(ListView l, View v, int position, long id) { 
    Intent myIntent = new Intent(); 
    myIntent.setClassName("com.utsc", "com.utsc.Announcements"); 
    startActivity(myIntent); 
}*/ 
} 

控制檯:

[2011-01-26 13:58:57 - ddms]null 
java.lang.NullPointerException 
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213) 
at com.android.ddmlib.Client.sendAndConsume(Client.java:573) 
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142) 
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) 
at com.android.ddmlib.Client.getJdwpPacket(Client.java:670) 
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) 
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) 

[2011-01-26 13:58:57 - ddms]null 
java.lang.NullPointerException 
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213) 
at com.android.ddmlib.Client.sendAndConsume(Client.java:573) 
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142) 
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) 
at com.android.ddmlib.Client.getJdwpPacket(Client.java:670) 
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) 
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) 
+0

發生了我也是,你過去了嗎? – 2011-05-08 02:34:19

回答

0

我試圖運行你的應用程序和它似乎運行良好。這裏是我的測試:

package com.stackoverflow.testlistactivity; 

import android.app.ListActivity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 


public class TestListActivity extends ListActivity { 
    String[] listActivityNames = { 
     "Text1", "Text2", "Text3", "Text4" 
    }; 

    /** Called when the activity is first created. */ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Use an existing ListAdapter that will map an array 
     // of strings to TextViews 

     setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 
       listActivityNames)); 
     getListView().setTextFilterEnabled(true); 
    } 
} 
0

的錯誤不是完全有用的,我覺得可能是在錯誤日誌更多的提示,但還是:

我覺得你getListView()不返回的對象。您可能首先要調用setListAdapter(),然後才能使用listViews做些什麼,但我不完全確定爲什麼在您的情況下不起作用。那次電話會不會有錯誤?

編輯: 這似乎與剛剛發佈的wat @ noel一致。

4

我不在乎這個問題真的很老,這是發生在我身上,我花了一段時間才弄清楚。

確保您沒有任何打開的xml文件。我關閉了所有的XML文件,這個異常消失了。

+0

令人驚歎的,謝謝 – 2014-11-13 00:08:40

相關問題