Search Results

Search found 12457 results on 499 pages for 'variable assignment'.

Page 19/499 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • Semicolon in object variable name

    - by milkfilk
    There's a common LDAP attribute called userCertificate;binary. It actually has a semi-colon in the attribute name. In ruby, I turn an LDAP entry into a OpenStruct object called 'struct'. struct.class = OpenStruct But of course ruby thinks it's an end-of-line character. ? struct.userCertificate;binary NameError: undefined local variable or method `binary' for main:Object from (irb):52 from :0 IRB knows that the local variable is there, because it gives me struct.userCertificate;binary from the tab auto-completion. I can also see the class variable when calling struct.methods on it. struct.methods = ... "send", "methods", "userCertificate;binary=", "hash", ... It's definitely there, I can see the contents if I print the whole variable to_s(). But how can I access the local variable when it has a semicolon in it? I have workarounds for this but I thought it was an interesting problem to post.

    Read the article

  • Objective-C NSString Assignment Problem

    - by golfromeo
    In my Cocoa application, in the header file, I declare a NSString ivar: NSString *gSdkPath; Then, in awakeFromNib, I assign it to a value: gSdkPath = @"hello"; Later, it's value is changed in the code: gSdkPath = [NSString stringWithString:[folderNames objectAtIndex:0]]; (the object returned from objectAtIndex is an NSString) However, after this point, in another method when I try to NSLog() (or do anything with) the gSdkPath variable, the app crashes. I'm sure this has something to do with memory management, but I'm beginning with Cocoa and not sure exactly how this all works. Thanks for any help in advance.

    Read the article

  • Get variable name as string in Perl

    - by Jose Cuervo
    Hi, I am trying to get a text representation of a variable's name. For instance, this would be the function I am looking for: $abc = '123'; $var_name = &get_var_name($abc); #returns '$abc' I want this because I am trying to write a debug function that recursively outputs the contents of a passed variable, I want it to output the variable's name before hand so if I call this debug function 100 times in succession there will be no confusion as to which variable I am looking at in the output. I have heard of Data::Dumper and am not a fan. If someone can tell me how to if it's possible get a string of a variable's name, that would be great. Thanks!

    Read the article

  • assignment not working in a dll exported C++ class

    - by Jim Jones
    Using VS 2008 Have a C++ class in which I'm calling functions from a 3rd party dll. The definition in the header file is as follows: namespace OITImageExport { class ImageExport { private: SCCERR seResult; /* Error code returned. */ VTHDOC hDoc; /* Input doc handle returned by DAOpenDocument(). */ VTHEXPORT hExport; /* Handle to the export returned by EXOpenExport(). */ VTDWORD dwFIFlags; /* Used in setting the SCCOPT_FIFLAGS option. */ VTCHAR szError[256]; /* Error string buffer. */ VTDWORD dwOutputId; /* Output Format. */ VTDWORD dwSpecType; public: ImageExport(const char* outputId, const char* specType); void ProcessDocument(const char* inputPath, const char* outputPath); ~ImageExport(); }; } In the constructor I initialize two of the class fields having values which come from enumerations in the 3rd party dll: ImageExport::ImageExport(const char* outputId, const char* specType) { if(outputId == "jpeg") { dwOutputId = FI_JPEGFIF; } if(specType == "ansi") { dwSpecType = IOTYPE_ANSIPATH; } seResult = DAInit(); if (seResult != SCCERR_OK) { DAGetErrorString(seResult, szError, sizeof(szError)); fprintf(stderr, "DAInit() failed: %s (0x%04X)\n", szError, seResult); exit(seResult); } } When I use this class inside of a console app, with a main method in another file (all in the same namespace), instantiating the class object and calling the methods, it works like a champ. So, now that I know the basic code works, I open a dll project using the class header and code file. Course I have to add the dll macro, namely: #ifdef IMAGEDLL_EXPORTS #define DLL __declspec(dllexport) #else #define DLL __declspec(dllimport) #endif and changed the class definition to "class DLL ImageExport". Compiled nicely to a dll and .lib file (No errors, No warnings). Now to test this dll I open another console project using the same main method as before and linking to the (dll) lib file. Had problems, which when tracked down were the result of the two fields not being set; both had values of 0. Went back to the first console app and printed out the values: dwOutputId was 1535 (#define FI_JPEGFIF 1535) and dwSpecType was 2 (#define IOTYPE_ANSIPATH 2). Now if I was assigning these values outside of the class, I can see how the visibility could be different, but why is the assignment in the dll not working? Is it something about having a class in the dll?

    Read the article

  • Retrieve a static variable using its name dynamically using reflection

    - by user2538438
    How to retrieve a static variable using its name dynamically using Java reflection? If I have class containing some variables: public class myClass { string [][] cfg1= {{"01"},{"02"},{"81"},{"82"}}; string [][]cfg2= {{"c01"},{"c02"},{"c81"},{"c82"}}; string [][] cfg3= {{"d01"},{"d02"},{"d81"}{"d82"}}; int cfg11 = 5; int cfg22 = 10; int cfg33 = 15; } And in another class I want variable name is input from user: class test { Scanner in = new Scanner(System.in); String userInput = in.nextLine(); // get variable from class myClass that has the same name as userInput System.out.println("variable name " + // correct variable from class) } Using reflection. Any help please?

    Read the article

  • Prevent Erroneous Property Assignment

    - by Gordon
    Porting android applications to iphone applications always gives me the following pattern that I accidentally create: - (void) myFunc:(id)prop { self.property = property; } Which instead should be: - (void) myFunc:(id)prop { self.property = prop; } This always causes my program to quietly break because property gets reset to its existing value rather than being set to the new value, 'prop'. I cannot name the parameter 'prop' to 'property' since the compile complains that the parameter masks the instance variables visibility. Is there a good way to avoid this situation? There are no compiler warnings. Is there a way to make xcode prevent this? I cannot see very many situations where you would set a property to the value of its underlying instance variable (maybe to trigger a KVO binding?), but I don't see myself doing that in majority of cases. I understand the above code is synthetic and should be done with @synthesize, but I am just using it as a simplified example to illustrate my point.

    Read the article

  • Media Information for Constant and Variable bit rate of Video files

    - by cpx
    What is this Maximum bit rate for a .mp4 format file whose bit rate mode is Constant? Media information displayed for MP4 (Using MediaInfo Tool) ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : [email protected] Format settings, CABAC : No Format settings, ReFrames : 1 frame Codec ID : avc1 Codec ID/Info : Advanced Video Coding Bit rate mode : Constant Bit rate : 1 500 Kbps Maximum bit rate : 3 961 Kbps Display aspect ratio : 4:3 Frame rate mode : Constant Frame rate : 29.970 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.163 In this case where the bit rate mode is set to Variable, is the Bit rate field where the value is displayed as 309 is its average bit rate? Media information displayed for M4V (Using MediaInfo Tool) ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : [email protected] Format settings, CABAC : No Format settings, ReFrames : 1 frame Codec ID : avc1 Codec ID/Info : Advanced Video Coding Bit rate mode : Variable Bit rate : 309 Kbps Display aspect ratio : 16:9 Frame rate mode : Variable Frame rate : 23.976 fps Minimum frame rate : 23.810 fps Maximum frame rate : 24.390 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.229 Writing library : x264 core 120

    Read the article

  • What is the EGG environment variable?

    - by Randall
    A user on our (openSuSE) linux systems attempted to run sudo, and triggered an alert. He has the environment variable EGG set - EGG=UH211åH1ÒH»ÿ/bin/shHÁSH211çH1ÀPWH211æ°;^O^Ej^A_j<X^O^EÉÃÿ This looks unusual to say the least. Is EGG a legitimate environment variable? (I've found some references to PYTHON_EGG_CACHE - could be related? But that environment variable isn't set for this user). If it's legit, then I imagine this group has the best chance of recognizing it. Or, given the embedded /bin/sh in the string above, does anyone recognize this as an exploit fingerprint? It wouldn't be the first time we had a cracked account (sigh).

    Read the article

  • HOSTNAME environment variable on Linux

    - by infogrind
    On my Linux box (Gentoo Linux 2.6.31 to be specific) I have noticed that the HOSTNAME environment variable is available in my shell, but not in scripts. For example, $ echo $HOSTNAME returns xxxxxxxx.com, but $ ruby -e 'puts ENV["HOSTNAME"]' returns nil On the other hand, the USER environment variable, for instance, is available both in the shell and in scripts. I have noticed that USER appears in the list of environment variables that appears when I type export i.e., declare -x USER="infogrind" but HOSTNAME doesn't. I suspect the issue has something to do with that. My questions: 1) how can I make HOSTNAME available in scripts, and 2) for my better understanding, where is this variable initially set, and why is it not "exported"?

    Read the article

  • Puppet - pass variable with a file create command

    - by Tim Brigham
    I need a way to pass a given variable - lets say thearch - to several different files within a given class. I need to be able to state the contents of this variable for each file individually. I have tried the following: file { "xxx": thearch => "i386", path => "/xxx/yyyy", owner => root, group => root, mode => 644, content => template("module/test.erb"), } This doesn't pass this variable so I can use it with a <%=thearch% statement within the erb file as I expect. What am I doing wrong here?

    Read the article

  • Linked Lists in Java - Help with assignment

    - by doron2010
    I have been trying to solve this assignment all day, please help me. I'm completely lost. Representation of a string in linked lists In every intersection in the list there will be 3 fields : The letter itself. The number of times it appears consecutively. A pointer to the next intersection in the list. The following class CharNode represents a intersection in the list : public class CharNode { private char _data; private int _value; private charNode _next; public CharNode (char c, int val, charNode n) { _data = c; _value = val; _next = n; } public charNode getNext() { return _next; } public void setNext (charNode node) { _next = node; } public int getValue() { return _value; } public void setValue (int v) { value = v; } public char getData() { return _data; } public void setData (char c) { _data = c; } } The class StringList represents the whole list : public class StringList { private charNode _head; public StringList() { _head = null; } public StringList (CharNode node) { _head = node; } } Add methods to the class StringList according to the details : (Pay attention, these are methods from the class String and we want to fulfill them by the representation of a string by a list as explained above) public char charAt (int i) - returns the char in the place i in the string. Assume that the value of i is in the right range. public StringList concat (String str) - returns a string that consists of the string that it is operated on and in its end the string "str" is concatenated. public int indexOf (int ch) - returns the index in the string it is operated on of the first appeareance of the char "ch". If the char "ch" doesn't appear in the string, returns -1. If the value of fromIndex isn't in the range, returns -1. public int indexOf (int ch, int fromIndex) - returns the index in the string it is operated on of the first appeareance of the char "ch", as the search begins in the index "fromIndex". If the char "ch" doesn't appear in the string, returns -1. public boolean equals (String str) - returns true if the string that it is operated on is equal to the string str. Otherwise returns false. This method must be written in recursion, without using loops at all. public int compareTo (String str) - compares between the string that the method is operated on to the string "str" that is in the parameter. The method returns 0 if the strings are equal. If the string in the object is smaller lexicographic from the string "str" in the paramater, a negative number will be returned. And if the string in the object is bigger lexicographic from the string "str", a positive number will be returned. public StringList substring (int i) - returns the list of the substring that starts in the place i in the string on which it operates. Meaning, the sub-string from the place i until the end of the string. Assume the value of i is in the right range. public StringList substring (int i, int j) - returns the list of the substring that begins in the place i and ends in the place j (not included) in the string it operates on. Assume the values of i, j are in the right range. public int length() - will return the length of the string on which it operates. Pay attention to all the possible error cases. Write what is the time complexity and space complexity of every method that you wrote. Make sure the methods you wrote are effective. It is NOT allowed to use ready classes of Java. It is NOT allowed to move to string and use string operations.

    Read the article

  • Basic C question, concerning memory allocation and value assignment

    - by VHristov
    Hi there, I have recently started working on my master thesis in C that I haven't used in quite a long time. Being used to Java, I'm now facing all kinds of problems all the time. I hope someone can help me with the following one, since I've been struggling with it for the past two days. So I have a really basic model of a database: tables, tuples, attributes and I'm trying to load some data into this structure. Following are the definitions: typedef struct attribute { int type; char * name; void * value; } attribute; typedef struct tuple { int tuple_id; int attribute_count; attribute * attributes; } tuple; typedef struct table { char * name; int row_count; tuple * tuples; } table; Data is coming from a file with inserts (generated for the Wisconsin benchmark), which I'm parsing. I have only integer or string values. A sample row would look like: insert into table values (9205, 541, 1, 1, 5, 5, 5, 5, 0, 1, 9205, 10, 11, 'HHHHHHH', 'HHHHHHH', 'HHHHHHH'); I've "managed" to load and parse the data and also to assign it. However, the assignment bit is buggy, since all values point to the same memory location, i.e. all rows look identical after I've loaded the data. Here is what I do: char value[10]; // assuming no value is longer than 10 chars int i, j, k; table * data = (table*) malloc(sizeof(data)); data->name = "table"; data->row_count = number_of_lines; data->tuples = (tuple*) malloc(number_of_lines*sizeof(tuple)); tuple* current_tuple; for(i=0; i<number_of_lines; i++) { current_tuple = &data->tuples[i]; current_tuple->tuple_id = i; current_tuple->attribute_count = 16; // static in our system current_tuple->attributes = (attribute*) malloc(16*sizeof(attribute)); for(k = 0; k < 16; k++) { current_tuple->attributes[k].name = attribute_names[k]; // for int values: current_tuple->attributes[k].type = DB_ATT_TYPE_INT; // write data into value-field int v = atoi(value); current_tuple->attributes[k].value = &v; // for string values: current_tuple->attributes[k].type = DB_ATT_TYPE_STRING; current_tuple->attributes[k].value = value; } // ... } While I am perfectly aware, why this is not working, I can't figure out how to get it working. I've tried following things, none of which worked: memcpy(current_tuple->attributes[k].value, &v, sizeof(int)); This results in a bad access error. Same for the following code (since I'm not quite sure which one would be the correct usage): memcpy(current_tuple->attributes[k].value, &v, 1); Not even sure if memcpy is what I need here... Also I've tried allocating memory, by doing something like: current_tuple->attributes[k].value = (int *) malloc(sizeof(int)); only to get "malloc: * error for object 0x100108e98: incorrect checksum for freed object - object was probably modified after being freed." As far as I understand this error, memory has already been allocated for this object, but I don't see where this happened. Doesn't the malloc(sizeof(attribute)) only allocate the memory needed to store an integer and two pointers (i.e. not the memory those pointers point to)? Any help would be greatly appreciated! Regards, Vassil

    Read the article

  • c# scope/typing/assignment question

    - by Shannow
    Hi there another quick question. I would like to create a variable object so that depending on the value of something, it gets cast as needed. e.g. var rule; switch (seqRuleObj.RuleType) { case SeqRuleObj.type.Pre : rule = new preConditionRuleType(); rule = (preConditionRuleType)seqRuleObj.Rule; break; case SeqRuleObj.type.Post : rule = new postConditionRuleType(); rule = (postConditionRuleType)seqRuleObj.Rule; break; case SeqRuleObj.type.Exit : rule = new exitConditionRuleType(); rule = (exitConditionRuleType)seqRuleObj.Rule; break; default : break; } String result; foreach (sequencingRuleTypeRuleConditionsRuleCondition cond in rule.ruleConditions.ruleCondition) { ....../ blah } so basically this will not work. c# will not allow me to create an new object in every case as the name is aleady defined. i can just paste the foreach loop into each case but that to me is such a waste, as the objects are exactly the same in all but name.

    Read the article

  • Ruby on Rails: How to use a local variable in a collection_select

    - by mmacaulay
    I have a partial view which I'm passing a local variable into: <%= render :partial => "products/product_row", :locals => { :product => product } %> These are rows in a table, and I want to have a <select> in each row for product categories: <%= collection_select(:product, :category_id, @current_user.categories, :id, :name, options = {:prompt => "-- Select a category --"}, html_options = { :id => "", :class => "product_category" }) %> (Note: the id = "" is there because collection_select tries to give all these select elements the same id.) The problem is that I want to have product.category be selected by default and this doesn't work unless I have an instance variable @product. I can't do this in the controller because this is a collection of products. One way I was able to get around this was to have this line just before the collection_select: <% @product = product %> But this seems very hacky and would be a problem if I ever wanted to have an actual instance variable @product in the controller. I guess one workaround would be to name this instance variable something more specific like @product_select_tmp in hopes of not interfering with anything that might be declared in the controller. This still seems very hacky though, and I'd prefer a cleaner solution. Surely there must be a way to have collection_select use a local variable instead of an instance variable. Note that I've tried a few different ways of calling collection_select with no success: <%= collection_select(product, ... <%= collection_select('product', ... etc. Any help greatly appreciated!

    Read the article

  • numpy array assignment problem

    - by Sujan
    Hi All: I have a strange problem in Python 2.6.5 with Numpy. I assign a numpy array, then equate a new variable to it. When I perform any operation to the new array, the original's values also change. Why is that? Please see the example below. Kindly enlighten me, as I'm fairly new to Python, and programming in general. -Sujan >>> import numpy as np >>> a = np.array([[1,2],[3,4]]) >>> b = a >>> b array([[1, 2], [3, 4]]) >>> c = a >>> c array([[1, 2], [3, 4]]) >>> c[:,1] = c[:,1] + 5 >>> c array([[1, 7], [3, 9]]) >>> b array([[1, 7], [3, 9]]) >>> a array([[1, 7], [3, 9]])

    Read the article

  • Create Session Variable from different datasources?

    - by Szafranamn
    Currently I am developing a dynamic website using Dreamweaver cs5 with ColdFusion 9 and using Access to create my databases along with QuickBooks and QODBC to create database. I have established a login session variable stemming from the login page. This session variable is being drawn from one Datasource "Access" Table "Logininfo" Field "FullName" but I wanted to create another session variable either at this point or further into the member's page to use in a query sequence. This session variable would stem from another Datasoucre "QBs" Table "Invoice" Field "CustomerRefFullName" which is generated through Quickbooks and QODBC. I am not sure if this is possible but if it is how do I do it. I want to do this so I can query the Invoice database to upload the customer's Invoices unique to them onto their page. So it would have to be related to their login credentials. If there is another better route to take I would greatly appreciate the advice. Below is the login code if there is additional information needed let me know. This is my current thinking/plan to do what I wish to intend hence the need to create the session variable: I have another Datasource "QBs" with a Table "Invoice" when I create another webpage for the customer to see their invoice I need to create a recordset that accesses that Table. In order to do so I think the best way would some home convert the session.FullName (which came from Access Datasource, Logininfor Table) into a session.CustomerRefFullName (which would have to come from (Datasource: QBs Table: Invoice Field: CustomerRefFullName) that way I could set the query WHERE CustomerRefFullName and have each logged in user see their specific Invoices. So is there a way to turn the session variable off one datasource/table into a different sessionvariable off a new datasource/table even if it is unique just to that page??? <cfif IsDefined("FORM.username")> SELECT FullName, Username,Password,AccessLevels FROM Logininfo WHERE Username= AND Password=

    Read the article

  • Sharing a global/static variable between a process and DLL

    - by minjang
    I'd like to share a static/global variable only between a process and a dll that is invoked by the process. The exe and dll are in the same memory address space. I don't want the variable to be shared among other processes. Elaboration of the problem: Say that there is a static/global variable x in a.cpp. Both the exe foo.exe and the dll bar.dll have a.cpp, so the variable x is in both images. Now, foo.exe dynamically loads (or statically) bar.dll. Then, the problem is whether the variable x is shared by the exe and dll, or not. In Windows, these two guys never share the x: the exe and dll will have a separate copy of x. However, in Linux, the exe and dll do share the variable x. Unfortunately, I want the behavior of Linux. I first considered using pragma data_seg on Windows. However, even if I correctly setup the shared data segment, foo.exe and bar.dll never shares the x. Recall that bar.dll is loaded into the address space of foo.exe. However, if I run another instance of foo.exe, then x is shared. But, I don't want x to be shared by different processes. So, using data_seg was failed. I may it use a memory-mapped file by making an unique name between exe and dll, which I'm trying now. Two questions: Why the behavior of Linux and Windows is different? Can anyone explain more about this? What would be most easiest way to solve this problem on Windows?

    Read the article

  • ActiveModel::MassAssignmentSecurity::Error in CustomersController#create (attr_accessible is set)

    - by megabga
    In my controller, I've got error when create action and try create model [can't mass-assignment], but in my spec, my test of mass-assignment model its pass!?! My Model: class Customer < ActiveRecord::Base attr_accessible :doc, :doc_rg, :name, :birthday, :name_sec, :address, :state_id, :city_id, :district_id, :customer_pj, :is_customer, :segment_id, :activity_id, :person_type, :person_id belongs_to :person , :polymorphic => true, dependent: :destroy has_many :histories has_many :emails def self.search(search) if search conditions = [] conditions << ['name LIKE ?', "%#{search}%"] find(:all, :conditions => conditions) else find(:all) end end end I`ve tired set attr_accessible in controller too, in my randomized way. the Controller: class CustomersController < ApplicationController include ActiveModel::MassAssignmentSecurity attr_accessible :doc, :doc_rg, :name, :birthday, :name_sec, :address, :state_id, :city_id, :district_id, :customer_pj, :is_customer autocomplete :business_segment, :name, :full => true autocomplete :business_activity, :name, :full => true [...] end The test, my passed test describe "accessible attributes" do it "should allow access to basics fields" do expect do @customer.save end.should_not raise_error(ActiveModel::MassAssignmentSecurity::Error) end end The error: ActiveModel::MassAssignmentSecurity::Error in CustomersController#create Can't mass-assign protected attributes: doc, doc_rg, name_sec, address, state_id, city_id, district_id, customer_pj, is_customer https://github.com/megabga/crm 1.9.2p320 Rails 3.2 MacOS pg

    Read the article

  • C++ unrestricted union workaround

    - by Chris
    #include <stdio.h> struct B { int x,y; }; struct A : public B { // This whines about "copy assignment operator not allowed in union" //A& operator =(const A& a) { printf("A=A should do the exact same thing as A=B\n"); } A& operator =(const B& b) { printf("A = B\n"); } }; union U { A a; B b; }; int main(int argc, const char* argv[]) { U u1, u2; u1.a = u2.b; // You can do this and it calls the operator = u1.a = (B)u2.a; // This works too u1.a = u2.a; // This calls the default assignment operator >:@ } Is there any workaround to be able to do that last line u1.a = u2.a with the exact same syntax, but have it call the operator = (don't care if it's =(B&) or =(A&)) instead of just copying data? Or are unrestricted unions (not supported even in Visual Studio 2010) the only option?

    Read the article

  • Beginning Java (Working with Arrays; Class Assignment)

    - by Jason
    I am to the point where I feel as if I correctly wrote the code for this homework assignment. We were given a skeleton and 2 classes that we had to import (FileIOHelper and Student). /* * Created: *** put the date here *** * * Author: *** put your name here *** * * The program will read information about students and their * scores from a file, and output the name of each student with * all his/her scores and the total score, plus the average score * of the class, and the name and total score of the students with * the highest and lowest total score. */ // import java.util.Scanner; import java.io.*; // C:\Users\Adam\info.txt public class Lab6 { public static void main(String[] args) throws IOException { // Fill in the body according to the following comments Scanner key boardFile = new Scanner(System.in); // Input file name String filename = getFileName(keyboardFile); //Open the file // Input number of students int numStudents = FileIOHelper.getNumberOfStudents(filename); Student students[] = new Student[numStudents]; // Input all student records and create Student array and // integer array for total scores int totalScore[] = new int[students.length]; for (int i = 0; i < students.length; i++){ for(int j = 1; j < 4; j++){ totalScore[i] = totalScore[i] + students[i].getScore(j); } } // Compute total scores and find students with lowest and // highest total score int maxScore = 0; int minScore = 0; for(int i = 0; i < students.length; i++){ if(totalScore[i] >= totalScore[maxScore]){ maxScore = i; } else if(totalScore[i] <= totalScore[minScore]){ minScore = i; } } // Compute average total score int allScores = 0; int average = 0; for (int i = 0; i < totalScore.length; i++){ allScores = allScores + totalScore[i]; } average = allScores / totalScore.length; // Output results outputResults(students, totalScore, maxScore, minScore, average); } // Given a Scanner in, this method prompts the user to enter // a file name, inputs it, and returns it. private static String getFileName(Scanner in) { // Fill in the body System.out.print("Enter the name of a file: "); String filename = in.next(); return filename; // Do not declare the Scanner variable in this method. // You must use the value this method receives in the // argument (in). } // Given the number of students records n to input, this // method creates an array of Student of the appropriate size, // reads n student records using the FileIOHelper, and stores // them in the array, and finally returns the Student array. private static Student[] getStudents(int n) { Student[] myStudents = new Student[n]; for(int i = 0; i <= n; i++){ myStudents[i] = FileIOHelper.getNextStudent(); } return myStudents; } // Given an array of Student records, an array with the total scores, // the indices in the arrays of the students with the highest and // lowest total scores, and the average total score for the class, // this method outputs a table of all the students appropriately // formatted, plus the total number of students, the average score // of the class, and the name and total score of the students with // the highest and lowest total score. private static void outputResults( Student[] students, int[] totalScores, int maxIndex, int minIndex, int average ) { // Fill in the body System.out.println("\nName \t\tScore1 \tScore2 \tScore3 \tTotal"); System.out.println("--------------------------------------------------------"); for(int i = 0; i < students.length; i++){ outputStudent(students[i], totalScores[i], average); System.out.println(); } System.out.println("--------------------------------------------------------"); outputNumberOfStudents(students.length); outputAverage(average); outputMaxStudent(students[maxIndex], totalScores[maxIndex]); outputMinStudent(students[minIndex], totalScores[minIndex]); System.out.println("--------------------------------------------------------"); } // Given a Student record, the total score for the student, // and the average total score for all the students, this method // outputs one line in the result table appropriately formatted. private static void outputStudent(Student s, int total, int avg) { System.out.print(s.getName() + "\t"); for(int i = 1; i < 4; i++){ System.out.print(s.getScore(i) + "\t"); } System.out.print(total + "\t"); if(total < avg){ System.out.print("-"); }else if(total > avg){ System.out.print("+"); }else{ System.out.print("="); } } // Given the number of students, this method outputs a message // stating what the total number of students in the class is. private static void outputNumberOfStudents(int n) { System.out.println("The total number of students in this class is: \t" + n); } // Given the average total score of all students, this method // outputs a message stating what the average total score of // the class is. private static void outputAverage(int average) { System.out.println("The average total score of the class is: \t" + average); } // Given the Student with highest total score and the student's // total score, this method outputs a message stating the name // of the student and the highest score. private static void outputMaxStudent( Student student, int score ) { System.out.println(student.getName() + " got the maximum total score of: \t" + score); } // Given the Student with lowest total score and the student's // total score, this method outputs a message stating the name // of the student and the lowest score. private static void outputMinStudent( Student student, int score ) { System.out.println(student.getName() + " got the minimum total score of: \t" + score); } } But now I get an error at the line totalScore[i] = totalScore[i] + students[i].getScore(j); Exception in thread "main" java.lang.NullPointerException at Lab6.main(Lab6.java:42)

    Read the article

  • Public class DiscoLight help

    - by luvthug
    Hi All, If some one can point me in the right direction for this code for my assigment I would really appreciate it. I have pasted the whole code that I need to complete but I need help with the following method public void changeColour(Circle aCircle) which is meant to allow to change the colour of the circle randomly, if 0 comes the light of the circle sgould change to red, 1 for green and 2 for purple. public class DiscoLight { /* instance variables */ private Circle light; // simulates a circular disco light in the Shapes window private Random randomNumberGenerator; /** * Default constructor for objects of class DiscoLight */ public DiscoLight() { super(); this.randomNumberGenerator = new Random(); } /** * Returns a randomly generated int between 0 (inclusive) * and number (exclusive). For example if number is 6, * the method will return one of 0, 1, 2, 3, 4, or 5. */ public int getRandomInt(int number) { return this.randomNumberGenerator.nextInt(number); } /** * student to write code and comment here for setLight(Circle) for Q4(i) */ public void setLight(Circle aCircle) { this.light = aCircle; } /** * student to write code and comment here for getLight() for Q4(i) */ public Circle getLight() { return this.light; } /** * Sets the argument to have a diameter of 50, an xPos * of 122, a yPos of 162 and the colour GREEN. * The method then sets the receiver's instance variable * light, to the argument aCircle. */ public void addLight(Circle aCircle) { //Student to write code here, Q4(ii) this.light = aCircle; this.light.setDiameter(50); this.light.setXPos(122); this.light.setYPos(162); this.light.setColour(OUColour.GREEN); } /** * Randomly sets the colour of the instance variable * light to red, green, or purple. */ public void changeColour(Circle aCircle) { //student to write code here, Q4(iii) if (getRandomInt() == 0) { this.light.setColour(OUColour.RED); } if (this.getRandomInt().equals(1)) { this.light.setColour(OUColour.GREEN); } else if (this.getRandomInt().equals(2)) { this.light.setColour(OUColour.PURPLE); } } /** * Grows the diameter of the circle referenced by the * receiver's instance variable light, to the argument size. * The diameter is incremented in steps of 2, * the xPos and yPos are decremented in steps of 1 until the * diameter reaches the value given by size. * Between each step there is a random colour change. The message * delay(anInt) is used to slow down the graphical interface, as required. */ public void grow(int size) { //student to write code here, Q4(iv) } /** * Shrinks the diameter of the circle referenced by the * receiver's instance variable light, to the argument size. * The diameter is decremented in steps of 2, * the xPos and yPos are incremented in steps of 1 until the * diameter reaches the value given by size. * Between each step there is a random colour change. The message * delay(anInt) is used to slow down the graphical interface, as required. */ public void shrink(int size) { //student to write code here, Q4(v) } /** * Expands the diameter of the light by the amount given by * sizeIncrease (changing colour as it grows). * * The method then contracts the light until it reaches its * original size (changing colour as it shrinks). */ public void lightCycle(int sizeIncrease) { //student to write code here, Q4(vi) } /** * Prompts the user for number of growing and shrinking * cycles. Then prompts the user for the number of units * by which to increase the diameter of light. * Method then performs the requested growing and * shrinking cycles. */ public void runLight() { //student to write code here, Q4(vii) } /** * Causes execution to pause by time number of milliseconds */ private void delay(int time) { try { Thread.sleep(time); } catch (Exception e) { System.out.println(e); } } }

    Read the article

  • Unable to assign command output to a variable

    - by Harish Maralihalli
    I am trying to assign the latest file name obtained from the below ls command but getting some error, it would be very nice if someone can answer how can I fix this! fn=`ls -lrt pur_bom_interface_daily*.log | cut -c59-102 | tail -1` or fn=$(ls -lrt pur_bom_interface_daily*.log | cut -c59-102 | tail -1) Error got: ls: 0653-341 The file pur_bom_interface_daily*.log does not exist Note: pur_bom_interface_daily*.log I am using * since there are multiple files starting their name with pur_bom_interface_daily and concatanated with the date on which they have got created.

    Read the article

  • PSEXEC - PATH VARIABLE NOT FOUND

    - by Magesh
    Hi, I use the PSEXEC to start the java process in local machine. When I run the PSEXEC without any user account it works fine. c:/psexec java testclass But when I run with an user account c:psexec -u user -p password java test It gives me the below error PsExec could not start java: The system cannot find the file specified I checked the environemt variable for the the above user and the PATH variable has been properly mapped to the java path. Could any one help me to resolve this issue.

    Read the article

  • Addressing a variable in VB

    - by Jeff
    Why doesn't Visual Basic.NET have the addressof operator like C#? In C#, one can int i = 123; int* addr = &i; But VB has no equivalent counter part. It seems like it should be important. UPDATE Since there's some interest, Im copying my response to Strilanc below. The case I ran into didnt necessitate pointers by any means, but I was trying to trouble shoot a unit test that was failing and there was some confusion over whether or not an object being used at one point in the stack was the same object as an object several methods away.

    Read the article

  • CSS variable height columns [migrated]

    - by Rob
    I have created a website, www.unionfamilies.com. I have a header, a main section consisting of two columns, and a footer. Currently, I have specified heights for header, main, footer, etc. I would like to make the site so the header stays on top, the columns adjust to match the height of the longest column, and the footer stays at the bottom. Can someone help me with this? I am new to CSS, so please be patient. Thank you.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >