小编Mal*_*lik的帖子

带有 Intent 的空对象引用

所以谢谢给定的任何 awnsers :)
我的问题的解决方案是,我的线路

Intent i = getIntent();
Run Code Online (Sandbox Code Playgroud)

不在我的 onCreate() 函数中。
谢谢你,祝你有美好的一天。






我知道,这种问题在互联网上被问了很多,但我找不到任何对我有帮助的答案,所以我将把我的特例带到这里。

这是我在 MainActivity 中的函数,我在其中创建 Intent 并开始我的第二个活动:

private void showArticle(String entryUrl, String entryTitle) {
    Intent intent = new Intent(this, ArticleActivity.class);
    intent.putExtra(EXTRA_URL, entryUrl.toString());
    intent.putExtra(EXTRA_TITLE, entryTitle.toString());
    Log.d("DEBUG", intent.getStringExtra(EXTRA_URL));
    Log.d("DEBUG", intent.getStringExtra(EXTRA_TITLE));
    Log.d("DEBUG", "EXTRAS PUTTED");
    startActivity(intent);
    Log.d("DEBUG", "ACTIVITY STARTED");
}
Run Code Online (Sandbox Code Playgroud)

这是控制台输出:

01-02 15:29:21.808 7108-7108/com.example.myfirstapp D/DEBUG: http://example.com/correct-url
01-02 15:29:21.809 7108-7108/com.example.myfirstapp D/DEBUG: Yeah, we have the correct title hhere
01-02 15:29:21.809 7108-7108/com.example.myfirstapp D/DEBUG: EXTRAS PUTTED
01-02 15:29:21.809 7108-7108/com.example.myfirstapp I/Timeline: Timeline: Activity_launch_request id:com.example.myfirstapp time:1404863384
01-02 15:29:21.815 …
Run Code Online (Sandbox Code Playgroud)

java android android-intent android-activity

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-activity ×1

android-intent ×1

java ×1