Duplicate Model instantiated from InitializeComponent()

Uncategorized
Question: I'm working on a MVVM WPF application and have run into a dead end trying to solve this. %) I have a model class DeviceModel instantiated from App.xaml.cs. This model implements INotifyPropertyChanged interface. public partial class App : Application { public DeviceModel DeviceModelInstance { get; set; } public App() { DeviceModelInstance = new DeviceModel(); } } In App.xaml: Then from MainWindow.xaml I instantiate the ViewModelBase: Then I bind buttons in the UI (MainWindow.xaml) to commands in ViewModelBase, which implement ICommand interface_Command="{Binding InputPhantomCommand, Converter={StaticResource InputPhantomConverter}, Source={StaticResource ViewModelBaseApp}}" This works great! I push a button, a command in the ViewModelBase gets called and changes a property of the DeviceModelInstance (instantiated in App.xaml.cs), which in turn triggers a PropertyChanged event, which propagates to other classes listening to that event. All the ICommand…
Read More

Cordova Build Android failed exit code 1

Uncategorized
Question: I am new to ionic 2 and want to build an apk for my app to android then the error belows shows up. I am using Ubuntu 16.04 and I also had installed android studio and updated all the sdk requirements. cordova build android - failed! [ERROR] An error occurred while running cordova build android (exit code 1):ANDROID_HOME=/home/jayzdevera/Android/Sdk JAVA_HOME=/usr/lib/jvm/java-8-oracle Error: Could not find an installed version of Gradle either in Android Studio, or on your system to install the gradle wrapper. Please include gradle in your path, or install Android Studio Answer: Read more
Read More

How to use AnyClass to init an specific class instance in swift3.x

Uncategorized
Question: I have seen this question on stackoverflow Here Unfortunately, this answer is not helpful in swift3.x protocol Effect { func des() } class A: Effect { func des() { print("This is A") } required init() { } } class B: Effect { func des() { print("This is B") } required init() { } } I want to store class A & B in an array var array = [Effect.Type]() array.append(A.self) array.append(B.self) When I want to get class A & B from array, I get this result A.self // __lldb_expr_23.A.Type A.self.init().des() -> This i A array[0] // __lldb_expr_23.A.Type array[0].init().des() -> Error Error Image I know I can use this method to init Class A let a = array[0] as! A.Type a.init().des() -> This is class A But if I don't…
Read More

Javascript for loop different order

Uncategorized
Question: Can anyone tell me why I get different order everytime the code loops? I'm very new to JavScript and I know the code isn't very neat. Answer: You use a for loop to loop through the list of users in a predefined order. But inside the loop you make an asynchronous XMLHttpRequest and you give it a function that will run when you receive a response for that request. The function you have attached to the xhttp.onreadystatechange event will run when a response is received. The responses can be received in a different order everytime the script is run and that's why the different xhttp.onreadystatechange events will fire in a different order. Read more
Read More

Android how to call MainActivity method from Non Activity class

Uncategorized
Question: I am troubing on Runtime permission method in a non activity class. I want to call a public MainActivity method to a helper class. MainActivity.java method public void a(){ //some method } Now My helper class:Class B{ private Context mContext; public B(Context context){ this.mContext = context; //now I am calling Mainactivity Method MainActivity mainActivity = new MainActivity(); mainActivity.a(); } } Calling B class from CActivity onCreate(){ B b = new B(this); } But it gives me Runtime error UPDATE: My method has runtime permission method which isn't static . ex- requestPermissions(), onRequestPermissionsResult() Answer: Make that method as static so you can call without creating the class object eg public static void testing() {} now calling MainActivity.testing(); Read more
Read More

carousel timeline causing “jumps” on every slide

Uncategorized
Question: 1st problem On https://bm-translations.de/#sprachrichtungen you can see the website "jumps" a few pixel towards the top on every slide of this autosliding timeline. I thinks its caused because of the #0 which is added to every point of the timeline to make it slide. But I am not sure how to make it work without jumping? As its quite a lot code I created a pen so you can see: https://codepen.io/anon/pen/gxxWOM 2nd problem: When its autosliding for example to year 2000 and then I press manually 2016. If its then autosliding again its not going to 2017 as it should but to the next after 2000, which could be annoying for the user. How to adjust this code? //adjustment > Autoslide function timeLineAutoPlay(){ var current = 0; setInterval(function(){ current…
Read More

Google ads don’t show on my website

Uncategorized
Question: My Google advertisements aren't showing on my HTML homepage - instead there's a blank box. This is what it looks like: And this is what the code looks like: Run code snippetHide results Expand snippet Answer: The reason ads aren't being displayed is because your domain is forbidden (with error code 403). This happens because AdSense does not want to display ads on your domain, either because of something you did that violated AdSense policies or something the previous domain owner did. Policy specialists disable ad serving to a page or site when it’s found to be in violation of program policies If it was something the previous domain owner did and your implementation of the site is in compliance then you can try and request that ad serving…
Read More

customising serialization process in java

Uncategorized
Question: While doing serialization what I have discover is that during deserialization process when file is read till end using readObject() in while loop then EOFException. so I have come up with this solution , Create a class EofIndicatorClass which implements Serializable interface. During serialization Write instance of EofIndicatorClass at EOF during serialization to indicate EOF during Serialization process. During serialization ,If oin.readObject() returns instanceof EofIndicatorClass that means it's EOF, exit while loop and EOFException will not be thrown. so below is the program based on that approach now please advise is this apprach is correct or is there any other better approach exists /* * Class whose instance will be written at EOF during serialization * to indicate EOF during deSerialization process. */ class EofIndicatorClass implements Serializable{} the other…
Read More

How to make spaced text .equal() to unspaced text

Uncategorized
Question: I am working on code that takes two inputs like the following:,Air Condition, , Air Condition, This text is received from a JSON object and the commas are something that must be considered. As can be seen, one has white space at the beginning and the other doesn't. How can I compare them using the equals()? So far, I have used the following code to compare the two strings: if (oldSelected.get(i).equalsIgnoreCase(String.valueOf(fc.getText()))){ fc.setChecked(true); } However, it doesn't do what I expect it to do. How i can trim this space and get the desired results? Answer: You need to trim the white spaces first. String oldSelected = ",Air Conditioner,"; String newSelected = ", Air Conditioner, "; if(oldSelected.replaceAll("\s", "").equalsIgnoreCase(newSelected.replaceAll("\s", ""))){ // Do Something } else{ // Do Something Else } Hope…
Read More