w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
why is this method always returning false even when no error
the false at the end of cancel_subscription causes an implicit return. Basically, in Ruby, if no return statement is present a method will return whatever the final statement evaluates to. In this case it is equivalent to return false. You could try adding a return true in an appropriate place like this, since you want to return true any time a delete was successful. def cancel_subscription(customer_id) unless customer_id.nil? customer = Stripe::Customer.retrieve(customer_id) unless customer.nil? or customer.respond_to?('deleted') if customer.subscription.status == 'active' customer.cancel_subscription user.remove_role :pro if user.practices.size > 1 user.practices.delete(user.prac

Categories : Ruby On Rails

Method Chaining and the new Keyword returning error in PHP 5.4.x
The error actually said it just perfeclly: loadHtml returned a Bool (true/false). Check the manual for the return value. Error: Catchable fatal error: Argument 1 passed to DOMXPath::__construct() must be an instance of DOMDocument, boolean given Code: $xpath = new DomXPath((new DomDocument())->loadHtml($html)); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // Argument 1, that returned a bool.

Categories : PHP

Method is returning int type, but I keep getting "this method must return a result of type int" error
What happens if control doesn't enter second level if? if (grid[i - 2][j] != 0) There is no return statement, isn't it? You need to have a return statement for all possible paths. How do I fix this? One possible way: Add return statement for first level if too. Example if (i - 1 >= 1){ if (grid[i - 2][j] != 0){ return xyTo1D(i - 1, j); } return -1; //OR whatever int you would like to return }

Categories : Java

JQuery ajax method returning error during POST on Chrome
You mention the second POST never gets sent to the server, how are you verifying this? It sounds more like a race condition where the second request is being sent before the server is ready for it (e.g. it is still doing something that was started by the first request).

Categories : Javascript

JavaScript object returning static method and himself as method
function foo() { return "foo"; } foo.bar = function() { return "bar"; }; Or, if you prefer: var foo = function() { return "foo"; }; foo.bar = function() { return "bar"; } JS functions are a type of object so you can assign properties/methods to them the same as for any other object.

Categories : Javascript

Method specification when returning class from a method in Java
It seems that you're supposed to return a new instance of VectorADT whose vector is the sum array you've computed. It's simply return new VectorADT(sum); This is a common operation in vector math. The sum of two vectors is a third vector whose components are the sum of the two corresponding components from the addend vectors.

Categories : Java

Sorting arrays in method and returning to main method
Code sponsored by Arrays.toString() and Arrays.sort(): public class ArraySort { public static void main(String args[]) { int t[] = {3, 5, 2}; // your reading part is fine, so I will skip it sortArrayWithoutCheating(t); System.out.println(Arrays.toString(t)); } public static void sortArrayWithoutCheating(int[] t) { // simplest O(n^2) sort for (int i = 0; i < t.length; i++) { for (int j = 0; j < i; j++) { if (t[i] < t[j]) { // swap t[i] and t[j] int temp = t[i]; t[i] = t[j]; t[j] = temp; } } } } public static void sortArray(int[] t)

Categories : Java

Returning from input() method, in while loop within same method
You are recursively calling input(). If you say 'y' a few times then 'n' it will have to walk back down the stack for each call to input(). You will have to press 'n' or 'N' for each time it has input was called. Getting rid of some of the handy waving ifs might help...

Categories : C#

Method Returning Zero in C#
The problem is that you're performing integer division in this line: ((bodyFatPercentage / 100) * bodyWeight); Because (bodyFatPercentage / 100) is less than 1, it is automatically truncated to 0, and so the whole function returns 0. You could instead use: (int)((bodyFatPercentage / 100.0) * bodyWeight); Alternatives include (int)Math.Round((bodyFatPercentage / 100.0) * bodyWeight); bodyFatPercentage * bodyWeight / 100 or simply returning a floating point value. Personally, I'd return a floating point value. As a general rule of thumb, don't give away precision until you need to display it (and if you want a less precise display). Otherwise, you can get compounding rounding errors, which is, essentially, what happened here.

Categories : C#

While returning a DataContract from a WCF function, I'm getting this error: "An error occurred while receiving the HTTP response"
That's a pretty generic exception in WCF so you'll need to enable WCF tracing to get more detailed info. Just guessing but look at this MSDN forum thread where the list contained complex objects that exceeded the default internal object limits in WCF. Once you enable WCF tracing, you should have a better idea of what's going on.

Categories : C#

mvc 4 model, method always returning 0?
So I believe what we are all saying in the comments is all you need is this: public double BMI { get { return Weight / (Height * Height); } } @ataravati is also correct about the DisplayName attribute being unnecessary since it is the same as the property name. You should also change the type to double since the result should be a floating point value. I would also make sure that your Weight and Height properties are doubles as well so you don't get zeros from integer division.

Categories : C#

Method Returning Type Ignored
No, it's returning a long. It's just that you're performing the arithmetic in 32-bit integer arithmetic first. Look at how you're doing the arithmetic: int total = x * n; You're not even storing the result as a long, so I don't see how you could expect it to retain a full long value. You need total to be a long - and you've got to make one of the operands a long in order to make the multiplication occur in 64-bit. To force the multiplication to occur in 64-bit arithmetic, you should cast one of the operands: long total = x * (long) n; Alternatively, just get rid of the total variable completely - I would suggest performing argument validation before using the parameters anyway: public long power(int x, int n) { if (x < 0 && n < 0) { // Use exceptio

Categories : Java

Why is my method returning in the middle?
You have a method there. Split the parts that make up your firstGoodFix boolean into separate booleans, then re-operate into firstGoodFix to see if that method is coming back with something that couldn't possible be less than (or bigger than or equal) 30 (like a NAN or an error, God knows :)

Categories : Java

Returning a nested class from a method
MyClass1Internal is private and thus should never be able to be accessed outside of MyClass1, but method will return an instance of it outside this class (as it's public), thus breaking its defining scope. I bet if you defined method as private it would fix this error. You could also make the nested class not be private. One more thing, if you wanted other code be able to work with that class but not be able to instantiate it, then just make the constructor private and the class public like so: class MyClass1 { class MyClass1Internal private[MyClass1](a: Int, b: Int, c: String, d: String) def method1 = { // doing something new MyClass1Internal(1, 2, "3", "4") } }

Categories : Scala

returning a value from a method with a alert dialog box
U can use simple interface here public interface DialogClickListener { public void onClicked(boolean validAccessCode) } public void requestAccessCode(Activity mActivity, final DialogClickListener listener) throws Exception { private EditText mPasswordView; mPasswordView = new EditText(mActivity); mPasswordView.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); mPasswordView.setTransformationMethod(new PasswordTransformationMethod()); AlertDialog.Builder alert = new AlertDialog.Builder(mActivity); alert.setTitle("Enter access code"); alert.setView(mPasswordView); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String pw = mPasswordView.getText().toString(); if (listener != null) {

Categories : Android

returning multiple Mat from an OpenCV method
You might be confused by how OpenCV uses typedefs to hide reference types. I would lookup how typedefs like InputArray are defined, you'll see they have an & in them to make them reference types. cv::Mat is not a typedef so you need to declare it as a reference in the function's argument list. void TestMethod(Mat& a, Mat& b) { a = imread("img1.jpg"); b = imread("img2.jpg"); return; } The way you have it written now, a and b are copies of the Mat variables you passed when you called the function. You are just overwriting copies that are deallocating when the function returns.

Categories : Opencv

get method of hashmap is not returning null
var jm: java.util.Map[String, Int] = new java.util.HashMap[String, Int]; Here in the Map interface you are using key as String the value is Int. So Int default value is the 0. var counter : Integer = jm.get(ls) So here counter can hold only 0 value because in the counter variable value come not Key. jm.get(ls);

Categories : Scala

equals method not returning expected o/p
You need to override equals in your Test1 class to get the desired behavior. Otherwise, the class will inherit equals from Object, which only determines if the two references refer to the same object. Here, you have different instances, so false is the result. Quoting from the linked javadocs: The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true). Typically you test if the other object is of the same class, then you compare the individual field(s) for equality.

Categories : Java

Model method returning everything in rails
I think this should work. If I actually understand what you are asking for. def my_twitter_followers if JSON.parse(contact_hash)["social_profiles"] JSON.parse(contact_hash)["social_profiles"].each do |profile| if profile["type"] == "twitter" return profile["followers"] unless profile["followers"].blank? end end end return 0 end In this case, if there is a twitter profile. It will return the twitter followers, unless the there are no followers. In which case it will return 0 (zero)

Categories : Ruby On Rails

Javascript method is not returning a variable
You need to return through the scope of the instance this: this.getGoal = function(){ return this.goal; } this.getCurrent = function(){ return this.current; } this.getPercent = function(){ return this.percent; } goal and current are returned because of closure with the constructor parameters. But if they are changed after the constructor runs then they would return wrong values. This is apparent with the percent variable.

Categories : Javascript

codeigniter get() method returning 1 result only
Try like function getAll() { $q = $this->db->get('test'); if ($q->num_rows() > 0) { foreach ($q->result() as $row) { $data['records'][] = $row; //Here you need to give an array } return $data; } } You are assigning all values to an variable so it is holding only one row data.You need to keep an array to catch all the data rows and pass the array to the controller and then to the view while we give as $data[] it will treat $data as an array and it will assign variables like $data[0],[1],[2]...like that....if we give $data only then it will treat as variable and it only take one variable or value at once.

Categories : Codeigniter

MVC AttributeRouting With GET - Returning 405 - Method Not Allowed
You would need to decorate the Search action with one more attribute called System.Web.Http.HttpGetAttribute. For the reason behind this, you can take a look at my answer in the below post: 405 when using AttributeRouting.PUTAttribute unless I also include HttpPutAttribute

Categories : Asp Net Mvc

Returning HTTP 403 in a WebAPI method
You might have a problem with your routing configuration. Below is a working sample. Put it in your controller and see if it works. If it doesn't check your routing with a diagnostic tool (i.e. Cobisi Routing Assistant) public string GetSomeString(int id) { // This method is not allowed! return this.Request.CreateErrorResponse(HttpStatusCode.Forbidden, "This method is not allowed!"); }

Categories : Asp Net

C# Method returning array issue
You have 2 mismatches on that line: stats[x, y, z] = inputstats(stats[x, y, z]); double[] inputstats(double[] methodstats) { } The expression stats[x, y, z] is a single double, not an array. So when you fix the argument error you will get one for the assignment of the return value. This line would compile: stats[x, y, z] = Math.Sin(stats[x, y, z]); because the function is declared as double Sin(double a) Your input method collects an array of doubles, that is not possible with your current array form. You would have to use a jagged array (array-of-array-of-array: double[][][] stats = ... // extra code to create the arrays inputstats(stats[x][y]); void inputstats(double[] methodstats) { } But you might as well bite the bullet and write a proper class for your data: class Play

Categories : C#

find_by_* method is not returning the object
First off, unless this is a simple exercise in Rails authentication, you should use Devise or AuthLogic at this stage. Second, are you sure that params[:email] contains the email you are looking for? From your params, it looks to me like you want to use params[:session][:email]. Third, you should move this down into the model. For example: class SecurityUser < ActiveRecord::Base def self.authenticate(params) user = where(email: params[:email]).first (user && user.password == params[:password]) ? user : false end end And in the controller: @user = SecurityUser.authenticate params[:session] session[:user_id] = user.id if @user Note above that the password is not hashed - you should not save a plain text password - but that's not what this is about. Also note t

Categories : Ruby On Rails

WebAPI in VS 2010, method not returning JSON
I just found out what was wrong. When creating my controller I didn't choose "Empty API controller" option (facepalm). After I have changed my controller to derive from ApiController class everything was working properly.

Categories : C#

BOOL method not returning YES inside of block
I am not sure what you are asking, so here is a guess: you wish your block to return a value to checkIfGameAlreadyExistsAgainst. When a block in constructed it usually makes a copy of any value referenced from its environment. If you wish your block to modify a variable in its environment you must mark that variable with __block. In your code this would look something like: __block BOOL blockStatus = YES; [currentUserIsUser1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { ... blockStatus = NO; } ]; if (!blockStatus) { ... } Important: The name of the method you are calling, findObjectsInBackgroundWithBlock, suggests that the block may not be called synchronously, which means the call may return before the block is executed. If this is the case you n

Categories : IOS

C# - connection leaking returning from class method
SqlConnection is a disposable class, and you should dispose of it when you're done. In short, have your class itself implement IDisposable (follow the example there. It's pretty textbook).

Categories : C#

returning the location string store in the method
The description method is declared in the NSObject protocol and implemented by any class that conforms to that protocol. It is described as follows: This method is used to create a textual representation of an object, for example in a formatted string But it's default implementation is to return the class name and memory address of the object in question, hence why you are seeing Tile: 0x10010ac90 in the console. You need to override description in your Tile class and return a string that is formatted as you desire, such as: -(NSString *)description { return [NSString stringWithFormat:@"Tile Location: %d x %d", row, column]; } Side Note You can simplify the implementation of description in the Player class by removing the unnecessary variable: -(NSString *) description

Categories : Objective C

Method without parameters returning List in Web services
You can get a JSON from your List and send the array of bytes of the JSON's file. And in the calling method you get that array of bytes, create a temp file (if it's necessary), get the List from the JSON's file. I do this is my application between Android and Java, and it's working fast than send the Object, because I zip the file too. []s William Bertan

Categories : Java

Ruby Rspec returning nil after validation in the method
The method place will return whatever you make it return, either with an explicit return, or from the last statement evaluated in the method. Currently the return value is whatever @report.log(x_coordinate, y_coordinate, direction) returns. Which is probably always nil (which in turn happens to match be_false, but not match be_true). There is nothing I can see wrong with the spec. The test failures are real, the code under test has a bug. Probably you should just put the log message as the first statement in the place method, like this: def place(x_coordinate, y_coordinate, direction = :north) @report.log(x_coordinate, y_coordinate, direction) x_coordinate.between?(@board.left_limit, @board.right_limit) && y_coordinate.between?(@board.bottom_limit, @board.top_limi

Categories : Ruby

How to make chaining method but returning more than 3 value at the same time
$ doesn't return an array, it returns a jQuery object, which is an array-like object. I.e. some of its properties have numeric names and it has a length property. Example: var obj = { 0: element1, 1: element2, find: function() { // some logic return this; // return a reference to itself for chaining }, length: 2 }; Now, a jQuery method doesn't return this, it returns a new jQuery object which exposes the same interface (obviously) and hence allows chaining. If you want to implement chaining yourself, you have to do the same: Either return this or a new instance of your object and initialize it with the data the current object has. Example: function Constr(data) { this.data = data || {}; } Contr.prototype.chain = function() { // do stuff

Categories : Javascript

WCF method is returning empty message element
Maybe it will work if you declare this as a "bare" service: [SoapDocumentService(Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Bare)] Otherwise implement a custom message inspector (and if it dows not work then a custom message encoder) to change the message.

Categories : Asp Net

method returning dynamic type in java
Simply, declare the method as generic, declare its return type, and its class: public <T> T foo(Class<T> clazz, Object... args) { return null; } Obviously the parameters are different that what one would need. You can instantiate a new T with: clazz.newInstance(); for a nullary constructor. For a constructor with arguments(in this example String s and Object o): return x.getConstructor(String.class, Object.class).newInstance("s", new Object()); In fact, thanks to your varargs you can iterate through the array and get all necessary class objects for the constructor lookup. You can then safely do: String s = foo(String.class, "a", "b"); If you want to constrain T to be a subclass of HttpRequest use: public <T extends HttpRequest> T foo(Class<T> cla

Categories : Java

WCF ServiceContract's method returning Task and timeout
Since the method is lengthy I thought I could make the operation async Hold on, slow down - you are mixing up asynchrony with network operation timeout. Lets consider asynchrony first: 1. Using async/await to asynchronously call a WCF service from client async/await on client side helps us to write asynchronous program so that the application remains responsive - in case of say WPF/WinForm we don't want to freeze the UI by calling a WCF service synchronously on the UI thread. Instead we can call it asynchronously using async/await. The magic here is that this is complete client side functionality - meaning the service need not be asynchronous or need not return a Task - all you have to to is while creating the service reference(proxy) you have to tell Visual Studio to generate Tas

Categories : Wcf

Returning null in a method whose signature says return int?
int is a primitive, null is not a value that it can take on. You could change the method return type to return java.lang.Integer and then you can return null, and existing code that returns int will get autoboxed. Nulls are assigned only to reference types, it means the reference doesn't point to anything. Primitives are not reference types, they are values, so they are never set to null. Using the object wrapper java.lang.Integer as the return value means you are passing back an Object and the object reference can be null.

Categories : Java

iOS initializing and returning a new object in a helper method
getTheDictionary returns an autoreleased object, which means that the object is valid in the calling method, but not owned by the caller. Therefore the calling method must not release or autorelease that object. It will be released when the current autorelease pool ends, e.g. when program control returns to the main event loop.

Categories : IOS

Populate method not returning documents - Mongoose
You're using Status in AccountSchema before it's defined. However, you should actually be using StatusSchema (the schema) instead of Status (the model) in the definition of AccountSchema anyway. Try this instead: var AccountSchema=new mongoose.Schema({ email:{type:String,unique:true}, password:{type:String}, name:{ first:{type:String}, last:{type:String}, full:{type:String} }, contacts:[Contact], status:[StatusSchema] });

Categories : Node Js

JFileChooser not returning the file name to main method
Just create a new class variable called File selectedFile. You'r using your FileChooser in an ActionListener and is instatiated in this Listener, so you can't get a filename from there, you have to save the selected file into the class variable called selectedFile. EDIT: You can handle it via a Abstract Action: public class FileChooserAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser; int result = fc.showDialog(...); if(result == JFileChooser.APPROVE_OPTION) { System.out.println(fc.getSelectedFile().getAbsolutePath()); } } } And then add a new Action (setAction() method of the button) to the button: setAction(new FileChooserAction());

Categories : Java

ClassCastException while returning redirect url from post method
The reason it gives a ClassCastException is that the Sitebricks API will at some point see the @Service -annotation in your class and act accordingly. It will take the returned object (in your case a java.lang.String) and try and cast it to a com.google.sitebricks.headless.Reply In order to achieve what you want, you should instead return the following: return Reply.saying().redirect("/servlet"); That is how you do a redirect using the Reply API.

Categories : Web Services



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.