-2

i try to use in Text View and i get this error the error is

 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

the is function

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;
   }

}

if i didnt upload the error pleas tell me where i can find the error

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
z games
  • 9
  • 4
  • does `My_Bus` have a value? – Ottxr Dec 22 '20 at 10:13
  • Can you please upload more code? From the error message you have posted, it looks like your java code can't refer the text view in the View Hierarchy. Maybe if you share the code where you are referring TextView object, we could provide you with a more detailed answer. – Sanskar Jethi Dec 22 '20 at 10:19
  • yes My_Bus have a value – z games Dec 22 '20 at 10:25
  • i stil try to figure out how to ask questions – z games Dec 22 '20 at 10:26
  • The error `Attempt to invoke virtual method 'void com.example.bus.Buss.setLicense_Number(java.lang.String)' on a null object reference` means that you are calling `setLicense_Number()` on a `Buss` object that's `null`. The code you gave is irrelevant as it doesn't show that method call and what happens to that `Buss` object before it. You'll need a `Buss bus = new Buss()` style instantiation of that object somewhere. (And Java uses lowercase names for variables though the code will work with wrong formatting too.) – Markus Kauppinen Dec 23 '20 at 13:06
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Markus Kauppinen Dec 23 '20 at 13:11
  • yes thanks. i fix it – z games Dec 24 '20 at 07:40

1 Answers1

-1

You got a RuntimeException (NullPointerException) while trying to call this method: setLicense_Number(java.lang.String) So, the problem may be in this method.
Check if there any statement (related to this method) returning null.

  • thanks i try to pot something in my Main_Bus(My_Bus) and it work but why i cant just leave it like this: static Buss Main_Bus and in the code to pot data? it worke whith this: static Buss Main_Bus=new Buss("0",Start_Day,End_Day,Kilometer,Fuel); – z games Dec 22 '20 at 14:04