onCreate()中的空指针异常 [英] null pointer exception in onCreate()

查看:137
本文介绍了onCreate()中的空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面提到的代码中我得到空指针异常。需要做什么?

In the below mentioned code I am getting null pointer exception. What need to be done?

private static final String PREFERENCES = "PREFERENCES";
private static final String URL = "url";
private String lastUrl;
private EditText urlText;
private TextView textView;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    urlText = (EditText) findViewById(R.id.address);
    textView = (TextView) findViewById(R.id.pagetext);

    loadPreferences();
    urlText.setText(lastUrl);
}

推荐答案

需要做什么?



调试。简单的调试。



http://developer.android .com / tools / debugging / index.html [ ^ ]



你可以在异常上设置一个断点,这会导致代码在它发生的行中停止。
What need to be done?

Debugging. Simple Debugging.

http://developer.android.com/tools/debugging/index.html[^]

You can set a break point on the exception, that would cause the code to stop in the line that it happens.


这篇关于onCreate()中的空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆