本文介绍了显示java.lang.NullPointerException长baba1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我送值和字符串值作为演员从列表活动agenmin activity.But GET 显示java.lang.NullPointerException 行120

I am sending long value and String value as extras from list activity to agenmin activity.But get java.lang.NullPointerException at line 120

    long baba1 = intent1.getExtras().getLong("baba",0); //line number 120

从列表活动发送

          // long id from from listview

            Intent i = new Intent(list.this, agenmin.class);
            i.putExtra("baba", id);
            startActivity(i); 

             //int position from listview
            String c= Integer.toString(position);
            Intent i1 = new Intent(list.this, agenmin.class);
            i1.putExtra("abc", c);
            startActivity(i1); 

在接收端agenmin

At receiving side agenmin

            Intent i1 = getIntent();
        String easyPuzzle;
        easyPuzzle=i1.getStringExtra("abc");
        textView2.setText(easyPuzzle);

        Toast.makeText(getApplicationContext(), "Position " + (mess)+" ROWID " +(easyPuzzle), Toast.LENGTH_LONG).show();


           Intent intent1 = getIntent();
        long baba1 = intent1.getExtras().getLong("baba",0);
        String strLong1 = Long.toString(baba1);
        textView3.setText(strLong1);

logcat的:

      05-27 20:43:45.169: E/AndroidRuntime(593): FATAL EXCEPTION: main
      05-27 20:43:45.169: E/AndroidRuntime(593): java.lang.NullPointerException
      05-27 20:43:45.169: E/AndroidRuntime(593):    at com.indianic.demo.calendark.agenmin$1.onClick(agenmin.java:120)

我开始agenmin活动两次,多数民众赞成显示java.lang.NullPointerException 的理由行120

推荐答案

为什么你必须启动 agenmin 活动两个目的?

Why do you have two intents starting the agenmin activity?

这样,您就已经开始了 agenmin 活动两次,但只给一个额外给每个开始的。那么就不能得到第二个加时您尝试使用它的价值崩溃。

This way you're starting the agenmin activity twice, but giving only one extra to each of the starts. Then the second extra can't be obtained and it crashes when you try to use its value.

只要做到这一点:

Intent i = new Intent(list.this, agenmin.class);
i.putExtra("baba", id);
i.putExtra("abc", c);
startActivity(i);

和我建议你阅读更多关于意图,以及它们如何工作。例如。为了启动一个不同的活动,你只需要一个意图。正如你愿意,你可以把尽可能多的群众演员在里面。

And I suggest you read more about what intents are and how they work. For example here. For starting a different activity, you only need one intent. And you can put as many extras in it as you wish.

这篇关于显示java.lang.NullPointerException长baba1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 01:14