2013-04-17 50 views
0

我一直在做一段時間的項目,在整個夜晚工作,而且這個項目一直在努力工作,任何我能夠擺脫的小錯誤。隨機NullPointerException。無跡可尋

這是在工作狀態,我去了一個生物休息,並回到這個!

04-17 08:42:53.017: E/AndroidRuntime(4779): FATAL EXCEPTION: main 
04-17 08:42:53.017: E/AndroidRuntime(4779): java.lang.NullPointerException 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.AbsListView.obtainView(AbsListView.java:2163) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.ListView.makeAndAddView(ListView.java:1831) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.ListView.fillDown(ListView.java:674) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.ListView.fillFromTop(ListView.java:735) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.ListView.layoutChildren(ListView.java:1638) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.AbsListView.onLayout(AbsListView.java:1996) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.View.layout(View.java:14008) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewGroup.layout(ViewGroup.java:4373) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.GridLayout.onLayout(GridLayout.java:1138) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.View.layout(View.java:14008) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewGroup.layout(ViewGroup.java:4373) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.View.layout(View.java:14008) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewGroup.layout(ViewGroup.java:4373) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.View.layout(View.java:14008) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewGroup.layout(ViewGroup.java:4373) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.View.layout(View.java:14008) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewGroup.layout(ViewGroup.java:4373) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.View.layout(View.java:14008) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewGroup.layout(ViewGroup.java:4373) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.Choreographer.doCallbacks(Choreographer.java:562) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.Choreographer.doFrame(Choreographer.java:532) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.os.Handler.handleCallback(Handler.java:725) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.os.Handler.dispatchMessage(Handler.java:92) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.os.Looper.loop(Looper.java:137) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at android.app.ActivityThread.main(ActivityThread.java:5234) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at java.lang.reflect.Method.invoke(Method.java:525) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) 
04-17 08:42:53.017: E/AndroidRuntime(4779):  at dalvik.system.NativeStart.main(Native Method) 

我可能已經改變的東西之前,我有我的突破,但這沒有給我太多的線索,我應該找指針異常的....

任何人都可以擺脫從這個問題可以看出問題的其他部分嗎?

在此先感謝...

編輯!

public class MenuActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    WindowManager windowManager = getWindowManager(); 
    Display display = windowManager.getDefaultDisplay(); 
    if (display.getWidth() > display.getHeight()) { 
     setContentView(R.layout.land_activity_menu); 
    } else { 
     setContentView(R.layout.activity_menu); 
    } 
} 


public void aboutClick(View view) { 
    startActivity(new Intent(this, AboutActivity.class)); 
} 

public void newsClick(View view) { 
    startActivity(new Intent(this, NewsActivity.class)); 
} 

public void coursesClick(View view) { 
    startActivity(new Intent(this, CoursesActivity.class)); 
} 

public void loginClick(View view) { 
    startActivity(new Intent(this, LoginActivity.class)); 
} 

然後應用程序崩潰,一旦newsactivity推出...

public class NewsActivity extends Activity implements OnItemClickListener { 

// globals... need to change these? 
private ListView listview; 
private List<RowItems> rowItems; 
final int itemCount = 15; 
String newsItemTitles[] = new String[itemCount]; 
String newsItemDates[] = new String[itemCount]; 
String newsItemDesc[] = new String[itemCount]; 
String newsItemHREFS[] = new String[itemCount]; 
String newsItemPicHREFS[] = new String[itemCount]; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_news); 

    ActionBar actionBar = getActionBar(); 
    actionBar.setDisplayHomeAsUpEnabled(true); 

    // Start Async for News 
    getNewsTask(); 

} 

private void getNewsTask() { 
    new getNews().execute(); 
} 

private class getNews extends AsyncTask<Void, Void, Void> { 
    private ProgressDialog pd; 
    boolean service; 
    CustomAdapter adapter; 

    @Override 
    protected void onPreExecute() { 
     pd = new ProgressDialog(NewsActivity.this); 
     pd.setTitle("Loading News..."); 
     pd.setMessage("Loading " + itemCount + " News Items"); 
     pd.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", 
       new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 
         pd.dismiss(); 
         startActivity(new Intent(NewsActivity.this, 
           MenuActivity.class)); 
        } 
       }); 
     pd.show(); 

    } 

我不是完全肯定什麼會導致這裏的崩潰......

+2

嘗試:http://stackoverflow.com/a/3944534/1651233 – BobTheBuilder

+2

好像有什麼錯誤的getView實現適配器...你是從getView返回null? – Selvin

+0

我認爲你應該發佈你的代碼來幫助 –

回答

0

正如在評論中提到,如果您在適配器的getView()方法中返回null,則會出現此問題。確保你創建一個新的convertView實例,如果它爲null。

+0

你不應該把其他人的評論作爲你自己的答案。 –

+0

如果他們沒有提供答案而永遠不會呢?沒有什麼可以接受的原始海報。 –