initialization - Why does not this work - Android - onCreate() -


The following code does not work, and throws a runtime uppress because of NullPointerException

  public Increase the activity activity of the category list filter (linear type type = new linearlayout (this); Override public zeros on @Create (bundle saved instanestate) {super.Nocrat (savedinstenstate); ScrollView sv = new ScrollView (this) ; This.setContentView (sv); //this.typeSelector = New linerlayout (this); this.typeSelector.setOrientation (L InearLayout.VERTICAL); sv.addView (this.typeSelector);}  

When I went to the initialization of the creator () inside the this.typeSelection Great work.

  @Override Public Zero OnCreate (bundled savedinstenstate) {... this.TypeSelector = new linear line (this); ...}  

Why is the empty indicator error? As the inline announcement in the first part of the code is called as Constructor, and then the Oktit () has access to the object, right?

for linear layout you must pass in an Android lifecycle The object and the Java object is not there when the field is declared and started directly, then it will be started using the Java default constructor. However, when you receive the onCreate lifecycle method, only one reference will be received, which is too much, and later part of the Android, is not Java so that's when you call the LinearLayout constructor This is called , then Android is expecting a reference reference, which you call only after calling.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -