Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
StringTokenizer上的空指针异常-Android_Android_Exception_Pointers_Null - Fatal编程技术网

StringTokenizer上的空指针异常-Android

StringTokenizer上的空指针异常-Android,android,exception,pointers,null,Android,Exception,Pointers,Null,有人能告诉我为什么在代码的这一部分中会出现空指针异常错误吗?特别是这一行----StringTokenizer wholeresp=新的StringTokenizer(modGen.response,“|”) 正如我看到的代码一样,您使用不正确的activity类初始化了modgen。您必须使用以下代码: public void run() { modGen = new ModGenClassName(); StringTokenizer wholeres

有人能告诉我为什么在代码的这一部分中会出现空指针异常错误吗?特别是这一行----StringTokenizer wholeresp=新的StringTokenizer(modGen.response,“|”)


正如我看到的代码一样,您使用不正确的activity类初始化了
modgen
。您必须使用以下代码:

public void run() {
          modGen = new ModGenClassName();
          StringTokenizer wholeresp = new StringTokenizer(modGen.response,"|");
          Intent intent = new Intent(ClaimVoucherActivity.this,ClaimVoucherDetailsActivity.class);
          intent.putExtra("customerID", customerID);
          intent.putExtra("type", type);
          intent.putExtra("name", name);
          intent.putExtra("email", email);
          intent.putExtra("voucher", voucher);
          intent.putExtra("branch", branch);
          intent.putExtra("issued", issued);
          intent.putExtra("expiration", expiration);
          intent.putExtra("status", status);
          intent.putExtra("vouchername", vouchername);
          intent.putExtra("employeeid", employeeid);
          intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
           startActivity(intent);

          }   
        });
我不知道ModGen的类名,您需要用
ModGenClassName


按照你的意图单独发送10个项目不是一个好方法,我认为你可以用最多两个类来处理所有项目,然后再发送下一个活动的对象,这是一个更好更干净的方法。

如果你有一个NPE在那一行,modGen为空如果modGen是任何类对象?你初始化了吗?你初始化了吗?我没有看到那一行,只需添加
modGen=newyourclassname()到你的方法的第一行你能发布
modgen
类吗?这是正确的。但是现在我在这一行SpineEmployee.setSelection(Integer.parseInt(employ)-1)中得到NumberFormatException错误;。在下一个活动中,我传递这些代码。雇用值是多少?检查一下,@jajaja如果有一个答案可以帮助你并解决你的问题,你必须勾选它作为帮助他人的答案。
public void run() {
          modGen = new ModGenClassName();
          StringTokenizer wholeresp = new StringTokenizer(modGen.response,"|");
          Intent intent = new Intent(ClaimVoucherActivity.this,ClaimVoucherDetailsActivity.class);
          intent.putExtra("customerID", customerID);
          intent.putExtra("type", type);
          intent.putExtra("name", name);
          intent.putExtra("email", email);
          intent.putExtra("voucher", voucher);
          intent.putExtra("branch", branch);
          intent.putExtra("issued", issued);
          intent.putExtra("expiration", expiration);
          intent.putExtra("status", status);
          intent.putExtra("vouchername", vouchername);
          intent.putExtra("employeeid", employeeid);
          intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
           startActivity(intent);

          }   
        });