随机NullPointerException。追踪中没有线索

时间:2013-04-17 08:04:28

标签: android

我已经在一个项目上工作了一段时间,整夜工作,项目一直在工作,我设法摆脱的任何小错误。

它处于工作状态,我去了生物休息区并回到了这里!!

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)

在我休息之前,我可能已经改变了一些东西,但这并没有给我一些关于我应该在哪里寻找指针异常的线索....

任何人都可以了解问题可能源于何处吗?

提前致谢...

EDIT !!!

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));
}

随着新闻活动的推出,应用程序很快就崩溃了......

 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();

    }

我不完全确定会导致崩溃的原因......

1 个答案:

答案 0 :(得分:0)

正如评论中提到的,如果在适配器的getView()方法中返回null,则会出现此问题。如果它是null,请确保创建一个新的convertView实例。