Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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
Android 我尝试在文本视图中使用_Android - Fatal编程技术网

Android 我尝试在文本视图中使用

Android 我尝试在文本视图中使用,android,Android,我尝试在文本视图中使用,但出现了此错误 错误是 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bus/com.example.bus.Bus_maker}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.bus.Buss.setLicense_Number(java

我尝试在文本视图中使用,但出现了此错误 错误是

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bus/com.example.bus.Bus_maker}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.bus.Buss.setLicense_Number(java.lang.String)' on a null object reference
这就是功能

public boolean check_Bus(Buss My_Bus) {
    int num_ok = 0;
    String Error_string="the error is:/n";
    if (!check_Bus_License(My_Bus)){
        num_ok += 1;
        if(Error_nu1) Error_string+="license number most be 7 numbers\n";
        else Error_string+="license number most be 8 numbers\n";
    }
    if (!check_Bus_Date(My_Bus)){
        num_ok+=1;
        Error_string+="license start date most be before end date\n";
    }
    if (num_ok==0)
        return true;
    else {
        Error_View = findViewById(R.id.Error_View);
        Error_View.setText(Error_string);
        return false;
   }
}


如果我没有上传错误,请告诉我在哪里可以找到错误

您在尝试调用此方法时遇到了RuntimeException(NullPointerException):
setLicense\u Number(java.lang.String)
因此,问题可能在于这种方法

检查是否有任何语句(与此方法相关)返回null。

My_Bus是否有值?是否可以上载更多代码?从您发布的错误消息来看,您的java代码似乎无法引用视图层次结构中的文本视图。如果您在引用TextView对象的地方共享代码,我们可能会为您提供更详细的答案。是的,My_Bus有一个值我仍在尝试找出如何提问错误
尝试调用虚拟方法'void com.example.Bus.Buss.setLicense_Number(java.lang.String)'在空对象引用上
表示您正在对
Buss
对象调用
setLicense\u Number()
,该对象为
null
。您给出的代码是不相关的,因为它没有显示方法调用以及前面的
Buss
对象发生了什么。您需要在某个地方对该对象进行
Buss bus=new Buss()
样式的实例化。(Java对变量使用小写名称,尽管代码也会使用错误的格式。)谢谢,我尝试在我的主_总线(my_总线)中pot一些东西,它可以工作,但为什么我不能就这样离开它:静态总线主_总线和在代码中pot数据?它的工作原理是:静态总线主总线=新总线(“0”,开始、结束、公里、燃油);