android上的空指针

android上的空指针,android,android-intent,nullpointerexception,Android,Android Intent,Nullpointerexception,我的意图是得到NullPointerException。我是从两个不同的活动中来参加同一个活动的。我的代码是: if(getIntent().getStringExtra("action").equals("yes"){ // NULLPOINTER HERE //Some code } else if(getIntent().getStringExtra("action").equals("completed"){ // Some code } 当我在putExtra中

我的意图是得到
NullPointerException
。我是从两个不同的活动中来参加同一个活动的。我的代码是:

if(getIntent().getStringExtra("action").equals("yes"){   // NULLPOINTER HERE

 //Some code

 }
 else if(getIntent().getStringExtra("action").equals("completed"){

 // Some code

 }
当我在putExtra中发送“已完成”时,它会显示错误;当我发送“是”时,它工作正常

试试看-

if(getIntent().getStringExtra("action")!=null)
{
if(getIntent().getStringExtra("action").equals("yes")){  

 //Some code

 }
 else if(getIntent().getStringExtra("action").equals("completed")){

 // Some code

 }
}
试着这样,

将此添加到Oncreate中

String yourvalue;

@Override
    protected void onCreate(Bundle savedInstanceState) 
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.new);

    Bundle extras = getIntent().getExtras();
     yourvalue = extras.getString("STRINGVALUE");

  }
//随处使用

  if(yourvalue.equals(""))
        {
        //your value is empty
        }
        else
        {
        if(yourvalue.equals("yes"))
        {  

         //Some code

         }
         else if(yourvalue.equals("completed"))
        {

         }

        }
检查您的putextra数据是否发送到下一个目的地

Intent intent = new Intent(getActivity(),newAct.class);                 
    intent.putExtra("STRINGVALUE", value);
     startActivity(intent);

检查
getIntent().getStringExtra(“操作”)=null
检查是否在这两个位置使用额外变量作为“操作”。缺少右括号。