Stack Overflow

Subscribe to Stack Overflow feed
most recent 30 from stackoverflow.com 2017-11-22T13:16:57Z
Updated: 9 hours 4 min ago

Access Violation Writing location 0x00000028

21 hours 37 min ago

I'm having some issues with the Assignment Operator. Although there are no red underlining errors, when I compile the program would break at

emp1 = emp2;

in main.cpp, everything was working until I added the assignment operation function.

Any Advice will be greatly appreciated.

Edit: Just thought I should show specific code that relates to the issue instead of the whole thing.

Here's what I've written:

ListOfEmp.h

public: ListOfEmp(); ListOfEmp(const ListOfEmp &); ~ListOfEmp(); const ListOfEmp& operator=(const ListOfEmp e); };

ListOfEmp.cpp

ListOfEmp::ListOfEmp():head(NULL) { } ListOfEmp::ListOfEmp(const ListOfEmp &e) { *this = e; } ListOfEmp::~ListOfEmp() { clear(); } const ListOfEmp& ListOfEmp::operator=(const ListOfEmp e){ if (this != &e) { clear(); EmpNode* copy = NULL; EmpNode* orig = e.head; while (orig != NULL) { if (head = NULL) { head = copy = new EmpNode((orig->emp).name, (orig->emp).salary); } else { copy->next = new EmpNode((orig->emp).name, (orig->emp).salary); copy = copy->next; } orig = orig->next; } } return *this; } void ListOfEmp::clear() { EmpNode* temp = head; while (temp != NULL) { temp = temp->next; delete head; head = temp; } }

Main.cpp

int main() { ListOfEmp emp1; emp1.insertAtfront("John", 20000.00); emp1.insertAtfront("Dave", 24500.50); emp1.insertAtfront("Joshua", 33567.60); emp1.deleteMostRecent(); emp1.getSalary("Dave"); cout << endl; cout << emp1; cout << endl; ListOfEmp emp2; emp2.insertAtfront("Julio", 54000.00); emp2.insertAtfront("Mike", 12000.00); emp2.getSalary("Mike"); cout << endl; cout << emp2; cout << endl; emp1 = emp2; cout << emp1; cout << endl; cout << emp2; system("pause"); }

Multiple buttons on page, representing multiple selection

21 hours 47 min ago

I have a ASP.net MVC 5 page with 10 options on, each should be represented by a button - the colour and text of which changes if it's selected.

Selected: Green & "Interested" Not Selected: Grey & "I'm Interested"

When the user clicks a button it should asynchronously toggle it's own switch - then change it's text and colour accordingly.

This needs to be sent to an MVC app and stored in a database.

I could use checkboxes and a server roundtrip with 1 button to also achieve this - but it's not good UX for my situation.

How can I do this? (I'm using bootstrap).

I can style the buttons using Bootstrap easily enough but don't even know where to start for asynchronously updating the options or having them display correctly when the page loads.

thx.

EDIT

model is - each of the 10 items has an Id (the number may go up from 10 in future) - and this will be stored with the user Id in a database.

public class User { public int Id { get; set; } public string Name { get; set; } } public class Option { public int Id { get; set; } public string Name { get; set; } } public class userOption { public int Id { get; set; } public int UserId { get; set; } public int OptionId { get; set; } }

SQLServer "Cannot insert explicit value for identity column" even when I SET IDENTITY_INSERT ON

21 hours 48 min ago

I REALLY review several times, that's the reason I am asking; looking for guidance...

I have one table, as the script below. Then, I set IDENTITY_INSERT ON. Then I try to do an insert select, (I NEED the very same ids)

It throws me always:

Msg 544, Level 16, State 1, Line 2 Cannot insert explicit value for identity column in table 'Table1' when IDENTITY_INSERT is set to OFF.

Does anybody knows why? Any set up at DB level can overrule the IDENTITY_INSERT ON??

I appreciate any advice. Thanks in Advance and Kind Regards.

Script to table:

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].Table1( [TableId] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](256) NOT NULL, [RowVersion] [timestamp] NOT NULL, [AddedDate] [datetime2](7) NOT NULL, [stuff2] [int] NOT NULL, [ModifiedDate] [datetime2](7) NOT NULL, [LastModifiedBy] [int] NOT NULL, CONSTRAINT [Table1_PK] PRIMARY KEY CLUSTERED ( [TableId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

The insert statement:

SET IDENTITY_INSERT [dbo].Table1 ON; INSERT INTO [dbo].Table1 ([TableId], [Name], [AddedDate], [stuff2], [ModifiedDate], [LastModifiedBy]) SELECT [RoleID], [Name], [AddedDate], [stuff2], [ModifiedDate], [LastModifiedBy] FROM [dbo].Table2

Run a process every alternate x hours

22 hours 2 min ago

I have a python script which I am running like this as shown below:

python3 ./bin/abc.py --log_file ./web/prr.log

Now I need to make sure that above process runs after every 3 hours. Below is the flow:

  • If the process is running already, then kill the process and sleep for 3 hours.
  • After sleeping for 3 hours, if process is not running, start the process again by executing above python command and then sleep for three hours.
  • Repeat the above process.

So meaning, I need to make sure that my process is running every alternate 3 hours so I need to find a way to kill the process after every 3 hours. I was thinking to use watch command here but not sure how can I use it here. I am working with Ubuntu 14.

Note: I can't modify the python script so I need to do it from outside of it.

Leetcode 110. Balanced Binary Tree Can I ask why my solution is wrong?

Tue, 11/21/2017 - 23:23

The original question is attached here: https://leetcode.com/problems/balanced-binary-tree/description/

public class BalancedBinaryTree { static boolean balance = true; public boolean isBalanced(TreeNode root) { if (root == null) return true; return (Math.abs(depth(root.left) - depth(root.right)) <= 1) && balance; } public int depth(TreeNode root) { if (balance) { if (root == null) return 0; int lengthOfLeft = depth(root.left); int lengthOfRight = depth(root.right); if (Math.abs(lengthOfLeft - lengthOfRight) > 1) { balance = false; } return Math.max(lengthOfLeft, lengthOfRight) + 1; } else { return 0; } }

iPhone X ignoring superView.top constraints

Tue, 11/21/2017 - 23:10

I am currently in the process of updating my app for iPhone X but even though i set my collection view's top constraint to superView.top with a constraint of 0, my background still appears and reveal shows that the collection view doesn't go all the way to the top.

Simulator image

Reveal image

constraint requested

view controller hierarchy

Note - the imageview is in the top cell on the collection view. It is apart of a navigation stack however the navigation bar is hidden on this view controller

Access JSON data in JAVA like JavaScript

Tue, 11/21/2017 - 21:52

I hope I am not asking a question which don't make any sense. Lets say I have JSON data like below. In JAVA we can access data by using get method (ex. jsonObj.get("field1")). When it comes to JavaScript we can access data directly using field name (ex. jsonObj.field1). So my question is, is there anyway in JAVA (or any 3rd party class) which allow me to access JSON data directly using field name?

{ "field1" : "value1", "field2" : "value2" }

Check if a sentence has the same words forward and backwards.

Tue, 11/21/2017 - 18:21

I am trying to check if a sentence is the same forwards and backwards or a "sentence palindrome." The sentence "You can cage a swallow, can't you, but you can't swallow a cage, can you?" should return (True) as a palindrome. Ignore everything that is not a letter.

My problem: Not sure how to compare words specifically. This currently works for words checking if they are palindromes, but I need to figure out what to change to compare each word.

public static boolean isWordPalindrome(String input) { Deque<Character> q = new LinkedList<>( ); Deque<Character> q2 = new LinkedList<>( ); Character letter; // One character from the input string int mismatches = 0; // Number of spots that mismatched int i; // Index for the input string int x; for (i = 0; i < input.length( ); i++) { letter = input.charAt(i); // read next character in the string if (letter.toString().equals(',') || letter.toString().equals('"') || letter.toString().equals('?') || letter.toString().equals('!') || letter.toString().equals('.') || letter.toString().equals(' ')) { //throwaway.add(letter); //ignore above chars and put in throwaway stack } if (Character.isLetter(letter)) // if letter put into q's { q.add(letter); q2.addFirst(letter); } } // end of for loop System.out.println("q: " + q); System.out.println("q2:" + q2); while (!q.isEmpty( )) { if (!Objects.equals(q.remove(), q2.remove())) mismatches++; }

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/view/KeyEventCompat

Tue, 11/21/2017 - 16:01

I am going to enter a phone number, but when I type in the number, the app crash immediately. The following error occurred

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xbdl.dmtoilet, PID: 3155 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/view/KeyEventCompat; at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:526) at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59) at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319) at com.android.internal.policy.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2310) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4127) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4089) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857) at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3434) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.KeyEventCompat" on path: DexPathList[[zip file "/data/app/com.xbdl.dmtoilet-1/base.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.xbdl.dmtoilet-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.xbdl.dmtoilet-1/lib/x86, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:526)  at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)  at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:319)  at com.android.internal.policy.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2310)  at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4127)  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4089)  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787)  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844)  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695)  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661)  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669)  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642)  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922)  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896)  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857)  at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3434)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  Suppressed: java.lang.ClassNotFoundException: android.support.v4.view.KeyEventCompat at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 28 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available I/Process: Sending signal. PID: 3155 SIG: 9

But when I remove the editText input type, I can type the characters normally , But when I enter numbers and backspace the key will still cause the app to flick back

The configuration information as follow

config = [ buildToolsVersion: "26.0.2", compileVersion : 26, minSdkVersion : 21, targetVersion : 26, versionCode : 1, versionName : "1.0", packageName : "com.xbdl.dmtoilet", ] lib = [ support_version : "27.0.0", ]

EditText code as follow

<EditText android:id="@+id/phoneEditText" style="@style/style_et.login" android:layout_height="63dp" android:drawableStart="@mipmap/ic_phone" android:hint="@string/text_hint_input_phone" android:inputType="phone" android:paddingStart="16dp" app:layout_constraintBottom_toTopOf="@+id/pwdLayout" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" tools:text="" /> <style name="style_et"> <item name="android:layout_height">@dimen/dimen_height_button</item> <item name="android:layout_width">match_parent</item> <item name="android:theme">@style/MyEditText</item> <item name="android:textSize">@dimen/dimen_font_text_small_2</item> <item name="android:drawablePadding">@dimen/dimen_distance_min</item> </style> <style name="style_et.login"> <item name="android:background">@null</item> </style> <style name="MyEditText" parent="Theme.AppCompat.Light"> <item name="colorControlNormal">#EDEDEE</item> <item name="colorControlActivated">#009AF7</item> </style>

how i can include Angular 2 project in react project?

Tue, 11/21/2017 - 12:59

I am building project using Angular 2 and it's will be part of react site, i trying to include angular project in react but it's not working:

in my react component i am using it like this:

var html = '<appr-root></app-root> <script type="text/javascript" src="/static/shahid/widget/inline.bundle.js"></script> <script type="text/javascript" src="/static/shahid/widget/polyfills.bundle.js"></script> <script type="text/javascript" src="/static/shahid/widget/styles.bundle.js"></script> <script type="text/javascript" src="/static/shahid/widget/vendor.bundle.js"></script> <script type="text/javascript" src="/static/shahid/widget/main.bundle.js"></script>`' <div dangerouslySetInnerHTML={{__html: html}} />

is there away to include it without using iframe?

Is there a race condition in this code?

Tue, 11/21/2017 - 12:59

I need to increase a counter in 5 threads until it reaches 500. Whit 5 threads like this, is working. But i need to know if it have a race condition.

Another problem with this code is that it gives me the prints in the wrong order.

class HiloContador extends Thread { static int count = 0; @Override public void run() { for (int i = 0; i < 100; i++) { synchronized (new Integer(count)) { ++count; System.out.println(count); } } } }

Output: 4 6 8 9 10 11 12 5 14 15 3 17 18

Some ideas?

Remove JavaFx Spinner Arrows

Tue, 11/21/2017 - 12:59

I want remove the arrows of a JavaFX Spinner. I read how to remove the arrows of MenuButton in this link using CSS...but can't figure out how to do in my case .

Any idea how ..thanks .

jQuery tabs keep loading when tab loses focus

Tue, 11/21/2017 - 12:58

I am trying to create an ajax-loading jQuery tab, as per the example at http://jqueryui.com/tabs/#ajax

However I noticed that, after the ajax loading starts, if I change the selected tab, the XHR request is aborted and restarted again when I then re-select the ajax tab.

How can I keep the tab loading even if the user changes the current tab? As of now, I have only been able to prevent it reloading each time with the following option:

beforeLoad: function(e, ui) { if(ui.panel.data('loaded') || ui.panel.data('loading')) { e.preventDefault(); return; } ui.panel.data('loading', true); setTimeout(function() { block_element(ui.panel.css('min-height', 175), I18N('FULLCALENDAR_LOADING')); }, 500); ui.jqXHR.success(function() { ui.panel.data('loading', false); ui.panel.data('loaded', true); }); ui.jqXHR.error(function() { ui.panel.data('loading', false); ui.panel.data('loaded', false); }); // se era specificata una funzione if(typeof old === 'function') { // la chiamo old.call(this, e, ui); } }

Using .gitconfig and .gitattributes of a submodule

Tue, 11/21/2017 - 12:58

in my git repo A I am using a submodule (B), which comes with a .gitattributes and a .gitconfig. Those basically set a git filter for .vcxproj files (.gitattributes) and 'implementing' the it (.gitconfig).

When I am in the repository B itself the .gitattribute/.gitconfig setup works find. I enabled it via

git config --local input.path ../.gitconfig

But how can I activate those filters when I am in the repository A and have B as submodule in A?

Angular error: The left-hand side of an assignment expression must be a variable or a property access

Tue, 11/21/2017 - 12:58

** Do not understand or know how to fix this error** this is the code. I dont know how to fix this code. It seems to be something to do with pushItem function i think. (filling in text) ghdfggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg

> **app.component.ts** import { Component, NgModule } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { //bind this array to li in html items = ['Sistema', 'Playstation', 'Web']; newItem = ''; pushItem = function() { if(this.newItem ! = ''){ this.items.push(this.newItem); this.newItem = ''; } } } @import '~font-awesome/css/font-awesome.css'; .main{ width: 500px; text-align: center; margin: 0 auto; border: 2px solid #d7d7d7; border-bottom: 0px; margin-top: 20px; font-family: sans-serif; } h1{ text-align: center; background-color: #5c8297; padding: 30px 0px; margin-top: 0px; color: #f7f7f7; } .addItem{ position: relative; padding-bottom: 0px; height: 30px; } .addText{ width: 80%; height: 30px; padding: 5px; font-size: 20px; } button{ height: 45px; width: 50px; padding: 5px; } ul{ list-style: none; font-size: 20px; color: #686868; margin-left: -40px; margin-bottom: 0px; } li{ border-bottom: 1px solid #bfbfbf; background: #d7d7d7; padding: 10px 0px; margin-bottom: 5px; } span{ cursor: pointer; position: relative; float: right; margin-right: 15px; } > **app.component.html** <div class = 'main'> <h1>Item List</h1> <div class = 'add'> <input [(ngModel)] = 'newItem' placeholder="add item" class = 'addText'> <button>Add</button> </div> <ul> <Li *ngFor = 'let i of items'> {{i}} <span><i class="fa fa-times" aria-hidden="true"></i></span> </Li> </ul> </div>

Error nessage

SQL apply functions to multiple id rows

Tue, 11/21/2017 - 12:58

I'm using SQL Server 2008, and trying to gather individual customer data appearing over multiple rows in my table, an example of my database is as follows:

custID | status | type | value ------------------------- 1 | 1 | A | 150 1 | 0 | B | 100 1 | 0 | A | 153 1 | 0 | A | 126 2 | 0 | A | 152 2 | 0 | B | 101 2 | 0 | B | 103

For each custID, my task is to find a flag if status=1 for any row, if type=B for any row, and the average of value in all cases where type=B. So my solution should look like:

custID | statusFlag | typeFlag | valueAv ------------------------------------------- 1 | 1 | 1 | 100 2 | 0 | 1 | 102

I can get answers for this using lots of row_number() over (partition by .. ), to create ids, and creating subtables for each column selecting the desired id. My issue is this method is awkward and time consuming, as I have many more columns than shown above to do this over, and many tables to repeat it for. My ideal solution would be to define my own aggregate() function so I could just do:

select custID, ag1(statusFlag), ag2(typeFlag) group by custID

but as far as I can tell custom aggregates can't be defined in SQL server. Is there a nicer general approach to this problem, which doesn't require defining lots of id's ?

Where does mysql store Wordpress post data?

Tue, 11/21/2017 - 12:58

I am wondering where Wordpress store its Wordpress post data. I have a Wordpress on Mac High Sierra, there is a data folder in this path, /usr/local/mysql/data/wp_db.Within it, there are some files with extension .frm, .ibd... It seems like the post data are in wp_usermeta.ibd, wp_term_taxonomy.ibd, wp_posts.ibd etc. but when I try to transfer them to the new Wordpress installation, they either prevents mysql from starting or just won't show up. These data are from a very old system backups I can't do a data dump from the old Mac.(the old Mac is long done.) Any idea? Thanks

Symfony2 - embedded form not getting displayed

Tue, 11/21/2017 - 12:58

I have 3 entities orders entity, product entity and orderProducts entity which has all the ordered products. So basically the mapping for orderProducts is one order can have many products. I want to embed orderProducts form into orders. The problem I’m facing is the embedded form is not displayed.

Order Entity:

class Orders { ... /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var \DateTime * * @ORM\Column(name="order_date", type="datetime") */ private $orderDate; /** * @var integer * * @ORM\ManyToOne(targetEntity="Recipient", inversedBy="orders", cascade={"persist"}) * @ORM\JoinColumn(name="recipient_id", referencedColumnName="id") * @Assert\NotNull() */ private $recipientId; ... /** * * @ORM\OneToMany(targetEntity="OrderProducts", mappedBy="orders") */ private $orderProducts; /** * Constructor */ public function __construct() { $this->orderProducts = new ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set orderDate * * @param \DateTime $orderDate * @return Orders */ public function setOrderDate($orderDate) { $this->orderDate = $orderDate; return $this; } /** * Get orderDate * * @return \DateTime */ public function getOrderDate() { return $this->orderDate; } /** * Set recipientId * * @param guid $recipientId * @return Orders */ public function setRecipientId($recipientId) { $this->recipientId = $recipientId; return $this; } /** * Get recipientId * * @return guid */ public function getRecipientId() { return $this->recipientId; } .... /** * Set orderProducts * * @param \Inventory\SystemBundle\Entity\OrderProducts $orderProducts * @return Orders */ public function setOrderProducts(\Inventory\SystemBundle\Entity\OrderProducts $orderProducts = null) { $this->orderProducts = $orderProducts; return $this; } /** * Get orderProducts * * @return \Inventory\SystemBundle\Entity\OrderProducts */ public function getOrderProducts() { return $this->orderProducts; } /** * Add orderProducts * * @param \Inventory\SystemBundle\Entity\OrderProducts $orderProducts * @return Orders */ public function addOrderProduct(\Inventory\SystemBundle\Entity\OrderProducts $orderProducts) { $this->orderProducts[] = $orderProducts; return $this; } /** * Remove orderProducts * * @param \Inventory\SystemBundle\Entity\OrderProducts $orderProducts */ public function removeOrderProduct(\Inventory\SystemBundle\Entity\OrderProducts $orderProducts) { $this->orderProducts->removeElement($orderProducts); }

}

Product Entity

class Product { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; ... /** * * @ORM\OneToMany(targetEntity="OrderProducts", mappedBy="product") */ private $orderProducts; ... public function __construct() { $this->orderProducts = new ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } ... /** * Add orderProducts * * @param \Inventory\SystemBundle\Entity\OrderProducts $orderProducts * @return Product */ public function addOrderProduct(\Inventory\SystemBundle\Entity\OrderProducts $orderProducts) { $this->orderProducts[] = $orderProducts; return $this; } /** * Remove orderProducts * * @param \Inventory\SystemBundle\Entity\OrderProducts $orderProducts */ public function removeOrderProduct(\Inventory\SystemBundle\Entity\OrderProducts $orderProducts) { $this->orderProducts->removeElement($orderProducts); } /** * Get orderProducts * * @return \Doctrine\Common\Collections\Collection */ public function getOrderProducts() { return $this->orderProducts; } }

orderProducts Entity

class OrderProducts { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="Orders", inversedBy="order_products") * @ORM\JoinColumn(name="order_id", referencedColumnName="id") */ private $orders; /** * @ORM\ManyToOne(targetEntity="Product", inversedBy="order_products") * @ORM\JoinColumn(name="product_id", referencedColumnName="id") */ private $product; /** * @var string * * @ORM\Column(name="quantity", type="string", length=255) */ private $quantity; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set order * * @return $this */ public function setOrders(Orders $orders) { $this->orders = $orders; return $this; } /** * Get order * * @return mixed */ public function getOrders() { return $this->orders; } /** * Set product * * @return $this */ public function setProduct(Product $product) { $this->product = $product; return $this; } /** * Get product * * @return mixed */ public function getProduct() { return $this->product; } /** * Set quantity * * @param string $quantity * @return OrderProducts */ public function setQuantity($quantity) { $this->quantity = $quantity; return $this; } /** * Get quantity * * @return string */ public function getQuantity() { return $this->quantity; }

}

OrdersType.php

public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('orderDate', 'date', array('attr' => array('class' => 'form-control', 'style' => 'margin:10px;width:200px;height:25px;display:inline-block;'))) ->add('recipientId', new RecipientType()) ->add('orderProducts', 'collection', array( 'type' => new OrderProductsType(), 'options' => array('label' => false), 'cascade_validation' => true, 'allow_add' => true )) //->add('orderProducts', CollectionType::class, array('entry_type' => OrderProductsType::class)) ; } /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Inventory\SystemBundle\Entity\Orders' )); } /** * @return string */ public function getName() { return 'orders'; }

OrderProductsType.php

public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('product', 'entity', array('label' => 'Product ','attr' => array('class' => 'form-control', 'style' => 'margin:10px;width:200px;height:25px;display:inline-block;'), 'class' => 'InventorySystemBundle:Product', 'choice_label' => 'product_name', ) ) ->add('quantity', 'text', array('attr' => array('class' => 'form-control', 'style' => 'margin:10px;width:200px;height:25px;display:inline-block;'))) ; } /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Inventory\SystemBundle\Entity\OrderProducts' )); } /** * @return string */ public function getName() { return 'orderproducts'; }

createAction from OrdersController.php

public function createAction(Request $request) { $order = new Orders(); $orderProducts = new OrderProducts(); $order->addOrderProduct($orderProducts); $request_all = $request->request->all(); $form = $this->createCreateForm($order); try { $form->handleRequest($request); } catch (\Exception $e) { echo "failed : ".$e->getMessage(); } $recipientId = $request_all['inventory_systembundle_orders']['recipientId']; $productId = $request_all['inventory_systembundle_orders']['product']; $quantity = $request_all['inventory_systembundle_orders']['quantity']; if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($order); $em->flush(); $product = $em->getRepository('InventorySystemBundle:Product')->find($productId); $em = $this->getDoctrine()->getManager(); $orderProducts->setProduct($product); $orderProducts->setOrders($order); $orderProducts->setQuantity($quantity); $em->persist($orderProducts); $em->flush(); return $this->redirect($this->generateUrl('orders_new')); } return array( 'order' => $order, 'form' => $form->createView(), ); }

I’m not sure what i am missing out. I’m not sure whether I’m going wrong with the associations. Can someone please help me with this?

Can' fix fxml.LoadException

Tue, 11/21/2017 - 12:58

I know that many people ask about this problem, and Iread about this error and I tried to fix that, but I don't know why it's still does not work.

I got this code:

package application; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.stage.Stage; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; public class Main extends Application { @Override public void start(Stage primaryStage) { try { Parent root = FXMLLoader.load(getClass().getResource("/application/Login.fxml")); Scene scene = new Scene(root,400,400); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } }

And I tried to change getResource part like this "/Login.fxml". But it still does not work.

This is how project files look:

Pages