May 6, 2013 Replies: 21 Starting from v2.70, Basic4android includes a warning engine. The purpose of the warning engine is to find potential programming mistakes as soon as possible. The warning engine runs whenever you compile the project, when clicking on Project -> Test Compilation or when you save the project. The compile time warnings appear above the logs and in the code itself: Clicking on the warning will take you to the relevant code. Ignoring warnings You, as the developer, can choose to ignore any warning. Adding an "ignore" comment will remove all the warnings for that specific line: Code: Sub UnusedSub(a As Int) 'ignore You can also disable warning from a specific type in the module by adding the #IgnoreWarning attribute. For example to disable warnings #10 and #12: Code: #IgnoreWarnings: 10, 12 Runtime warnings Some of the warnings are only checked at runtime. These warnings will appear in the regular logs. Runtime warnings are only checked in Debug mode. List of warnings 1: Unreachable code detected. 2: Not all code paths return a value. 3: Return type (in Sub signature) should be set explicitly. 4: Return value is missing. Default value will be used instead. 5: Variable declaration type is missing. String type will be used. 6: The following value misses screen units ('dip' or %x / %y): {1}. 7: Object converted to String. This is probably a programming mistake. 8: Undeclared variable '{1}'. 9: Unused variable '{1}'. 10: Variable '{1}' is never assigned any value. 11: Variable '{1}' was not initialized. 12: Sub '{1}' is not used. 13: Variable '{1}' should be declared in Sub Process_Globals. 14: File '{1}' in Files folder was not added to the Files tab.\nYou should either delete it or add it to the project.\nYou can choose Tools - Clean unused files. 15: File '{1}' is not used. 16: Layout file '{1}' is not used. Are you missing a call to Activity.LoadLayout? 17: File '{1}' is missing from the Files tab. 18: TextSize value should not be scaled as it is scaled internally. 19: Empty Catch block. You should at least add Log(LastException.Message). 20: View '{1}' was added with the designer. You should not initialize it. 21: Cannot access view's dimension before it is added to its parent. 22: Types do not match. 23: Modal dialogs are not allowed in Sub Activity_Pause. It will be ignored. 24: Accessing fields from other modules in Sub Process_Globals can be dangerous as the initialization order is not deterministic. 25: Sub '{1}' not found. 'Runtime warnings 1001: Panel.LoadLayout should only be called after the panel was added to its parent. 1002: The same object was added to the list. You should call Dim again to create a new object. 1003: Object was already initialized. 1004: FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. Click to expand... Click to expand...
Starting from v2.70, Basic4android includes a warning engine. The purpose of the warning engine is to find potential programming mistakes as soon as possible. The warning engine runs whenever you compile the project, when clicking on Project -> Test Compilation or when you save the project. The compile time warnings appear above the logs and in the code itself: Clicking on the warning will take you to the relevant code. Ignoring warnings You, as the developer, can choose to ignore any warning. Adding an "ignore" comment will remove all the warnings for that specific line: Code: Sub UnusedSub(a As Int) 'ignore You can also disable warning from a specific type in the module by adding the #IgnoreWarning attribute. For example to disable warnings #10 and #12: Code: #IgnoreWarnings: 10, 12 Runtime warnings Some of the warnings are only checked at runtime. These warnings will appear in the regular logs. Runtime warnings are only checked in Debug mode. List of warnings 1: Unreachable code detected. 2: Not all code paths return a value. 3: Return type (in Sub signature) should be set explicitly. 4: Return value is missing. Default value will be used instead. 5: Variable declaration type is missing. String type will be used. 6: The following value misses screen units ('dip' or %x / %y): {1}. 7: Object converted to String. This is probably a programming mistake. 8: Undeclared variable '{1}'. 9: Unused variable '{1}'. 10: Variable '{1}' is never assigned any value. 11: Variable '{1}' was not initialized. 12: Sub '{1}' is not used. 13: Variable '{1}' should be declared in Sub Process_Globals. 14: File '{1}' in Files folder was not added to the Files tab.\nYou should either delete it or add it to the project.\nYou can choose Tools - Clean unused files. 15: File '{1}' is not used. 16: Layout file '{1}' is not used. Are you missing a call to Activity.LoadLayout? 17: File '{1}' is missing from the Files tab. 18: TextSize value should not be scaled as it is scaled internally. 19: Empty Catch block. You should at least add Log(LastException.Message). 20: View '{1}' was added with the designer. You should not initialize it. 21: Cannot access view's dimension before it is added to its parent. 22: Types do not match. 23: Modal dialogs are not allowed in Sub Activity_Pause. It will be ignored. 24: Accessing fields from other modules in Sub Process_Globals can be dangerous as the initialization order is not deterministic. 25: Sub '{1}' not found. 'Runtime warnings 1001: Panel.LoadLayout should only be called after the panel was added to its parent. 1002: The same object was added to the list. You should call Dim again to create a new object. 1003: Object was already initialized. 1004: FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. Click to expand...
Reviewnow Active Member Licensed User Longtime User May 7, 2013 #2 10: Variable '{1}' is never assigned any value. Erel, I did find some false positives with this error where variable actually does have an assigned value.. So happy to see this new addition Do you have a specific forum where to place bugs for this beta? Thanks again
10: Variable '{1}' is never assigned any value. Erel, I did find some false positives with this error where variable actually does have an assigned value.. So happy to see this new addition Do you have a specific forum where to place bugs for this beta? Thanks again
corwin42 Expert Licensed User Longtime User May 7, 2013 #3 If the variable gets only assigned values but is never used anywhere it is useless. Edit: Sorry I thought you are talking about "Unused variable '{1}'.". Are you sure that there is a value assigned to the variable before it is used the first time?
If the variable gets only assigned values but is never used anywhere it is useless. Edit: Sorry I thought you are talking about "Unused variable '{1}'.". Are you sure that there is a value assigned to the variable before it is used the first time?
Erel B4X founder Staff member Licensed User Longtime User May 7, 2013 #4 Do you have a specific forum where to place bugs for this beta? Click to expand... Please post bugs in the "bugs & wishlist" forum. You can add [beta] in the thread title.
Do you have a specific forum where to place bugs for this beta? Click to expand... Please post bugs in the "bugs & wishlist" forum. You can add [beta] in the thread title.
Dave O Well-Known Member Licensed User Longtime User May 23, 2013 #5 Love the warnings, but would like to see one change: For undeclared variables, I think it would be good to add an option to make this an error rather than just a warning. For those of us who *always* declare our variables, it's sometimes hard to spot bugs because the default B4A behaviour is to allow undeclared variables. I don't check the warnings on each compile (mostly because I have lots of warnings and they get lost in the shuffle), so it takes me a while to realise there's a rogue variable running around. If there was an option for stricter declarations (e.g. "Don't allow undeclared variables"), that would (rightly) stop me in my tracks and give me a bit more confidence in my code. Hope this helps!
Love the warnings, but would like to see one change: For undeclared variables, I think it would be good to add an option to make this an error rather than just a warning. For those of us who *always* declare our variables, it's sometimes hard to spot bugs because the default B4A behaviour is to allow undeclared variables. I don't check the warnings on each compile (mostly because I have lots of warnings and they get lost in the shuffle), so it takes me a while to realise there's a rogue variable running around. If there was an option for stricter declarations (e.g. "Don't allow undeclared variables"), that would (rightly) stop me in my tracks and give me a bit more confidence in my code. Hope this helps!
Erel B4X founder Staff member Licensed User Longtime User May 23, 2013 #6 Why do you have lots of warnings? This is the problem...
Dave O Well-Known Member Licensed User Longtime User May 24, 2013 #7 Good question. Two reasons: I am using some third-party classes that generate a lot of warnings. Is there an easy way to say "ignore warnings for this entire file"? I have a lot of icon files that are either: Included in the file list, but referenced by building the name programmatically Not added to the file list, but used in the code. Should I be adding all referenced files to the file list (in the designer)? Does this make a functional difference, or is it just a matter of keeping everything in good order? (The app seems to work either way.) Thanks!
Good question. Two reasons: I am using some third-party classes that generate a lot of warnings. Is there an easy way to say "ignore warnings for this entire file"? I have a lot of icon files that are either: Included in the file list, but referenced by building the name programmatically Not added to the file list, but used in the code. Should I be adding all referenced files to the file list (in the designer)? Does this make a functional difference, or is it just a matter of keeping everything in good order? (The app seems to work either way.) Thanks!
Erel B4X founder Staff member Licensed User Longtime User May 24, 2013 #8 You can use the #IgnoreWarnings attribute in these classes to remove the warnings. Included in the file list, but referenced by building the name programmatically Click to expand... You should add the IgnoreWarnings attribute with attribute number 15. Not added to the file list, but used in the code. Click to expand... Just add the files to the Files tab.
You can use the #IgnoreWarnings attribute in these classes to remove the warnings. Included in the file list, but referenced by building the name programmatically Click to expand... You should add the IgnoreWarnings attribute with attribute number 15. Not added to the file list, but used in the code. Click to expand... Just add the files to the Files tab.
Erel B4X founder Staff member Licensed User Longtime User Oct 14, 2013 #9 You can add this line to your modules: #IgnoreWarnings: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Though it is better to understand why there are warnings and fix them...
You can add this line to your modules: #IgnoreWarnings: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Though it is better to understand why there are warnings and fix them...
Erel B4X founder Staff member Licensed User Longtime User Oct 20, 2013 #10 Warning #2 means that the compiler found that there is at least one code path that doesn't return a value. For example: Code: Sub S1 (b As Boolean) As Int If b then Return 3 End If End If There are cases where the compiler may not be correct. For example if you know that b is always True in the above code. The compiler doesn't have this information. In that case you should add a 'ignore comment to the sub.
Warning #2 means that the compiler found that there is at least one code path that doesn't return a value. For example: Code: Sub S1 (b As Boolean) As Int If b then Return 3 End If End If There are cases where the compiler may not be correct. For example if you know that b is always True in the above code. The compiler doesn't have this information. In that case you should add a 'ignore comment to the sub.
A Anawratha Member Licensed User Longtime User Feb 14, 2015 #11 Good Morning, I'm now using B4A Version 4.30 and get two new compiler warnings: 1.: 'Add android:targetSdkVersion="14" to the manifest editor. (warning #26)' => If I add 'SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")' to the manifest, the compiler gives an error that 'Theme.Holo' cannot be found. What's wrong? 2.: 'Add SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") to the manifest editor. (warning #28)' => What line will I have to write into the manifest editor (android:targetSdkVersion="14" does not work, other constructions also failed)? I can't find a description for this warnings.Thank's for your answers... Last edited: Feb 14, 2015
Good Morning, I'm now using B4A Version 4.30 and get two new compiler warnings: 1.: 'Add android:targetSdkVersion="14" to the manifest editor. (warning #26)' => If I add 'SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")' to the manifest, the compiler gives an error that 'Theme.Holo' cannot be found. What's wrong? 2.: 'Add SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") to the manifest editor. (warning #28)' => What line will I have to write into the manifest editor (android:targetSdkVersion="14" does not work, other constructions also failed)? I can't find a description for this warnings.Thank's for your answers...
lemonisdead Well-Known Member Licensed User Longtime User Feb 14, 2015 #12 Anawratha said: Good Morning, Click to expand... Hello, When you create a new project, the default Manifest contains : Code: AddManifestText( <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
Anawratha said: Good Morning, Click to expand... Hello, When you create a new project, the default Manifest contains : Code: AddManifestText( <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
A Anawratha Member Licensed User Longtime User Feb 15, 2015 #13 lemonisdead said: Hello, When you create a new project, the default Manifest contains : Code: AddManifestText( <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") Click to expand... Thank's for your advice! The problem with the targetSdkVersion 14 is solved now (...but I still do not really now what it means for my app...). The theme-problem remains. When I fill in the line and start 'compile and run' I get the following error: ... Generating R file. Error AndroidManifest.xml:21: error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/Theme.Holo'). ... When I delete the line 'SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")' everything works fine. Any solution for this problem? Btw: my default manifest did not contain the mentioned lines. Here is my default manifest (before I changesd anything!): Code: AddManifestText( <uses-sdk android:minSdkVersion="4"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$")
lemonisdead said: Hello, When you create a new project, the default Manifest contains : Code: AddManifestText( <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") SetApplicationAttribute(android:theme, "@android:style/Theme.Holo") Click to expand... Thank's for your advice! The problem with the targetSdkVersion 14 is solved now (...but I still do not really now what it means for my app...). The theme-problem remains. When I fill in the line and start 'compile and run' I get the following error: ... Generating R file. Error AndroidManifest.xml:21: error: Error: No resource found that matches the given name (at 'theme' with value '@android:style/Theme.Holo'). ... When I delete the line 'SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")' everything works fine. Any solution for this problem? Btw: my default manifest did not contain the mentioned lines. Here is my default manifest (before I changesd anything!): Code: AddManifestText( <uses-sdk android:minSdkVersion="4"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$")
Erel B4X founder Staff member Licensed User Longtime User Feb 15, 2015 #14 Anawratha said: Any solution for this problem? Click to expand... Yes, install the latest version of Android SDK and set the IDE to use it (android.jar under Tools - Configure Paths).
Anawratha said: Any solution for this problem? Click to expand... Yes, install the latest version of Android SDK and set the IDE to use it (android.jar under Tools - Configure Paths).
palmaf Member Licensed User Longtime User Feb 15, 2015 #15 I used the IIF function as described in the forum, but now compile i from this alert : Return type (Sub signature) should be set explicitly. How to correct ? Thanks
I used the IIF function as described in the forum, but now compile i from this alert : Return type (Sub signature) should be set explicitly. How to correct ? Thanks
A Anawratha Member Licensed User Longtime User Feb 16, 2015 #16 Erel said: Yes, install the latest version of Android SDK and set the IDE to use it (android.jar under Tools - Configure Paths). Click to expand... Thank you, Erel!!
Erel said: Yes, install the latest version of Android SDK and set the IDE to use it (android.jar under Tools - Configure Paths). Click to expand... Thank you, Erel!!
Erel B4X founder Staff member Licensed User Longtime User Feb 16, 2015 #17 palmaf said: I used the IIF function as described in the forum, but now compile i from this alert : Return type (Sub signature) should be set explicitly. How to correct ? Thanks Click to expand... Please start a new thread for this and post the sub code.
palmaf said: I used the IIF function as described in the forum, but now compile i from this alert : Return type (Sub signature) should be set explicitly. How to correct ? Thanks Click to expand... Please start a new thread for this and post the sub code.
Dave O Well-Known Member Licensed User Longtime User Aug 23, 2015 #18 The warnings are a great feature (especially when I forget "dip" units). I just noticed that the current app I'm working on doesn't use some of the libraries that are ticked (because I derived it from a more complex app). Would it be possible to add a warning for libraries that are ticked but not used?
The warnings are a great feature (especially when I forget "dip" units). I just noticed that the current app I'm working on doesn't use some of the libraries that are ticked (because I derived it from a more complex app). Would it be possible to add a warning for libraries that are ticked but not used?
DonManfred Expert Licensed User Longtime User Aug 24, 2015 #19 You should create a thread in the Wishlist forum as this is 1. an old Thread 2. not the right place to place wishes PS: Good idea btw
You should create a thread in the Wishlist forum as this is 1. an old Thread 2. not the right place to place wishes PS: Good idea btw
Dave O Well-Known Member Licensed User Longtime User Aug 24, 2015 #20 DonManfred said: You should create a thread in the Wishlist forum as this is 1. an old Thread 2. not the right place to place wishes PS: Good idea btw Click to expand... Good point - I'll repost in the wish list.
DonManfred said: You should create a thread in the Wishlist forum as this is 1. an old Thread 2. not the right place to place wishes PS: Good idea btw Click to expand... Good point - I'll repost in the wish list.