I am instantiating and sending multiple instances of HTTPService
On a Mac, however, many of the calls fail with a 2032 error.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
click="windowedapplication1_clickHandler(event)"
creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
[Bindable]
private var r:int=0;
[Bindable]
private var f:int=0;
private var a:Array= ['url1', 'url2', 'url3', 'url4', 'url5'];
private var sa:Array=[];
protected function windowedapplication1_clickHandler(event:MouseEvent):void
{
for(var i:int=0; i<sa.length; i++) {
sa[i].send();
}
}
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
for(var i:int=0; i<100; i++) {
var random:int=Math.floor(Math.random() * a.length);
var s:HTTPService=new HTTPService();
s.addEventListener(ResultEvent.RESULT, sr);
s.addEventListener(FaultEvent.FAULT, sf);
s.resultFormat="text";
s.url=a[random];
sa.push(s);
}
//s.useProxy=true;
}
private function sf(e:FaultEvent):void {
f++;
t.text="MESSAGE: " + e.message + "HEADERS:" + e.headers + "FAULTCONTENT: " + e.fault.content
+ "ERROR: " + e.fault.errorID + "|" + e.fault.faultCode + "|" + e.fault.faultDetail + "|" + e.fault.faultString
+ "FAULTMESSAGE:" + e.fault.message + "FAULRNAME:" + e.fault.name + "ROOTCAUSE:" + e.fault.rootCause
+ "AT " + e.fault.getStackTrace();
}
private function sr(e:ResultEvent):void {
r++;
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Label x="10" y="19" text="Result {r}"/>
<s:Label x="10" y="120" text="Fault {f}"/>
<s:TextArea x="10" y="198" width="610" height="294" id="t"/>
</s:WindowedApplication>
It works as expected on PC (I get all 100 results as successful) but on a Mac, I get wuite a few that fail.
Why is this happening and how do I get around it?
It seems Win7 and Mac OS X block very quick requests to different addressed.
Adding a 1 second timeout works fine
Related
I am new to flex and my question is how to reset mx hslider value with "reset" button.
here is a sample script:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.SliderEvent;
private var txtvalue:int = 0;
protected function Focal_changeHandler(event:SliderEvent):void
{
txtvalue = Focal.value;
if(txtvalue == 0)
Slider_txt.text = "Low";
if(txtvalue == 1)
Slider_txt.text = "Middle";
if(txtvalue == 2)
Slider_txt.text = "High";
}
]]>
</fx:Script>
<mx:HSlider id="Focal" x="476" y="345" maximum="2" minimum="0" value="0" buttonMode="true" enabled="true" snapInterval="1" tickInterval="1" allowTrackClick="true" liveDragging="true" change="Focal_changeHandler(event)"/>
<s:Label id="Slider_txt" x="472" y="319" text= "Low"/>
<s:Button x="476" y="459" label="Reset" id="Res_btn"/>
</s:Application>
Normally you could do
<s:Button x="476" y="459" label="Reset" id="Res_btn" click="{Focal.value = 0}"/>
But since you'd need to update the text as well, it's better to do an own method for that:
<s:Button x="476" y="459" label="Reset" id="Res_btn" click="onResetClick()"/>
and in your code part:
protected function Focal_changeHandler(event:SliderEvent):void
{
updateSliderText();
}
private function onResetClick():void
{
Focal.value = 0;
updateSliderText();
}
private function updateSliderText():void
{
txtvalue = Focal.value;
if (txtvalue == 0)
Slider_txt.text = "Low";
if (txtvalue == 1)
Slider_txt.text = "Middle";
if (txtvalue == 2)
Slider_txt.text = "High";
}
I don't know why this class shows errors in every line. This was fine but suddenly i close and open my netbeans IDE and it shows every-line error.
I tried to figure out where the problem is, but i can't. I notice that every button,table,label are missing, otherwise variable, database connection is ok.
My imports are:
import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import Main.SqlConnection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
import Main.Check;
import java.awt.Color;
import java.awt.event.KeyEvent;
Errors look like this image .
How do i solve this ?
Do i need to recover my project ?
add try{ block just before following line
private void btn_SaveActionPerformed(java.awt.event.ActionEvent evt) {
Your solution as follows
Consider following method. It don't contain a try keyword. add try keyword there. Then it will be fixed.
private void btn_SaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try { //this line is not present in your code. add this
StringBuffer stringBuffer = new StringBuffer();
if (value_for_show_table == 61) {
stringBuffer.append("insert into class6a where ");
} else if (value_for_show_table == 62) {
stringBuffer.append("insert into class6b where ");
} else if (value_for_show_table == 71) {
stringBuffer.append("insert into class7a where ");
} else if (value_for_show_table == 72) {
stringBuffer.append("insert into class7b where ");
} else if (value_for_show_table == 81) {
stringBuffer.append("insert into class8a where ");
} else if (value_for_show_table == 82) {
stringBuffer.append("insert into class8b ");
}
stringBuffer.append("where '" + txt_Username.getText() + "','" + txt_roll.getText() + "','" + txt_Bangla1st.getText() + "',"
+ "'" + txt_Bangla2nd.getText() + "','" + txt_English1st.getText() + "','" + txt_English2nd.getText() + "',"
+ "'" + txt_Math.getText() + "','" + txt_Social.getText() + "','" + txt_Religion.getText() + "',");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Roll number can't be duplicate");
}
}
Additionally It may happen according to many reasons. There are one of them.
When project cannot find the JDK location or when missing core library of java
When using a reserved word as a parameter or class name
I'm trying to render images using BrowserField . But i'm having the problem that images shows like this (bad rendering):
The image is bigguer than screen , and i have used this code to load it:
public ImagesScreen(String urlImage,int number)
{
super(VERTICAL_SCROLL | HORIZONTAL_SCROLL);
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.USER_SCALABLE, Boolean.TRUE);
browserField = new BrowserField(config);
scale = initscale = Float.valueOf(formatNumber(((float) 1 / (1703 / Display.getWidth())), 8, "."));
add(browserField);
Log.info("scala " + scale);//" + scale + "
String htmlContent = "<html><meta name='viewport' content='width = device-width,maximum-scale=10.0, minimum-scale=0.001, initial-scale=" + scale + ", user-scalable=yes' /><body style='margin: 0px;padding: 0px;float: left;'>";
for (int i = 1; i <= number;i++)
{
htmlContent += "<img width='1703' alt='' src='" + urlImage + "000"+i+".png"+"'/>";
}
System.out.println(urlImage);
htmlContent += "</body></html>";
browserField.displayContent(htmlContent, "http://localhost");
UiApplication.getUiApplication().pushScreen(this);
};
If i let the scale be 1 , it stills having that problem. Thanks for reading :) .
Let the BrowserField do all the work:
String imgFile = "..."; // here the image file pathname
String style = "..."; // here the css style
String imgTag = "<div class=\"image\"> <img src="
+ imgFile
+ "></img></div><div class=\"clear\"></div>";
String browserContent = "<html><style>" + style + "</style>" + imgTag + "</html>";
byte[] contentBytes;
try {
contentBytes = browserContent.getBytes("UTF-8");
browser.displayContent(contentBytes, "text/html; charset=UTF-8", "");
} catch (UnsupportedEncodingException e) {
...
}
I am using trend lines from amcharts.
I am using java and passing the values from database uins blazeds [??].
I'm taking an array collection to fetch the values from the database and put it in trendlines.
So what's the error in the code and what should the correct code be?
<?xml version="1.0" encoding="utf-8"?>
<!-- This example is made using amStock Flex component. Visit http://flex.amcharts.com to see more examples -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:amcharts="http://www.amcharts.com/com_internal"
backgroundColor="#FFFFFF"
width="100%" height="100%"
creationComplete="init()"
viewSourceURL="srcview/index.html">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:Producer id="producer" destination="RandomDataPush1"
acknowledge="ack(event)" fault="handleFault(event)"/>
<mx:Consumer id="consumer" destination="RandomDataPush1"
message="messageHandler(event)" fault="handleFault(event)" />
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import com.amcharts.events.SerialChartEvent;
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.messaging.events.MessageAckEvent;
import mx.messaging.events.MessageEvent;
import mx.messaging.events.MessageFaultEvent;
import mx.messaging.messages.AsyncMessage;
import mx.rpc.events.ResultEvent;
private var dataString:String =
[Bindable]
private var chartData:ArrayCollection = new ArrayCollection();
/* private function generateChartData():void
{
var firstDate:Date = new Date();
firstDate.setMinutes(firstDate.getMinutes() - 2000);
for(var i:Number = 0; i < 2000; i++)
{
var newDate:Z = new Date(firstDate);
newDate.setMinutes(newDate.getMinutes() + i);
var a:Number = Math.round(Math.random() * (40 + i)) + 100 + i;
var b:Number = Math.round(Math.random() * (1000 + i)) + 500 + i * 2;
chartData.addItem({date:newDate, a:a, b:b});
}
} */
private var Bindable:Object;
private function parseData():void{
// parse data string
var rowArray:Array = dataString.split("\n");
for(var i:uint = 0; i < rowArray.length; i++){
var row:Array = rowArray[i].split(",");
var dateArray:Array = row[0].split("-");
var date:Date = new Date(Number(dateArray[0]), Number(dateArray[1]) - 1, Number(dateArray[2]));
var open:Number = row[1];
var high:Number = row[2];
var low:Number = row[3];
var close:Number = row[4];
//chartData.addItem({date:date, open:open, high:high, low:low, close:close});
}
}
private function onClose():void
{
var msg:AsyncMessage = new AsyncMessage();
msg.body = "Close";
//msg.headers["symbol"]="IBKR";
msg.headers["symbol"]="EUR";
producer.send(msg);
consumer.subscribe();
//PopUpManager.removePopUp(this);
}
public function init():void {
// Alert.show("Hi from init..");
var msg:AsyncMessage = new AsyncMessage();
msg.body = "New";
//msg.headers["symbol"]="IBKR";
msg.headers["symbol"]="EUR";
producer.send(msg);
consumer.subscribe();
var ar:ArrayCollection=new ArrayCollection();
ar.addItemAt("EUR",0);
//pair_chart.dataProvider=ar;
//pair_chart.selectedIndex=0;
var ar1:ArrayCollection=new ArrayCollection();
ar1.addItemAt("Candle",0);
ar1.addItemAt("Bar",1);
}
private function ack(event:MessageAckEvent):void
{
//Alert.show(""+event.message.body);
chart.dataProvider = event.message.body as ArrayCollection;
//mybarChart.dataProvider = event.message.body as ArrayCollection;
}
private function handleFault(event:MessageFaultEvent):void
{
Alert.show("fault"+event.faultString);
}
private function messageHandler(event:MessageEvent):void
{
var dateTime:Date = new Date();
var obj:Object = new Object();
//Alert.show("hi "+event.message.body);
//obj.time = format.format(new Date()).toString();
//chart.dataProvider = event.message.body as ArrayCollection;
//FlexGlobals.topLevelApplication.crntpos.ui.chartArrCollection.addAll(event.message.body as ArrayCollection);
chartData.addAll(event.message.body as ArrayCollection);
//Alert.show("chartData.length "+chartData.length);
chart.dataProvider = chartData;
//Alert.show("hi "+chartData.list);
//mybarChart.dataProvider=FlexGlobals.topLevelApplication.crntpos.ui.chartArrCollection;
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10">
<amcharts:AmStockChart width="100%" height="100%">
<amcharts:dataSets>
<amcharts:DataSet id="chart" color="#00CC00" dataProvider="{chartData}" categoryField="date" title="First data set">
<amcharts:fieldMappings>
<amcharts:FieldMapping fromField="a" toField="value"/>
<amcharts:FieldMapping fromField="b" toField="volume"/>
</amcharts:fieldMappings>
</amcharts:DataSet>
</amcharts:dataSets>
<amcharts:panels>
<!-- to enabled drawing icons, you only need to set drawingIconsEnabled="true" on StockPanel -->
<amcharts:StockPanel drawingIconsEnabled="true" title="Value" height="50%" showCategoryAxis="true">
<amcharts:stockGraphs>
<amcharts:StockGraph bulletBorderColor="#FFFFFF" bullet="round" id="g1" valueField="value" compareField="value" comparable="true"/>
</amcharts:stockGraphs>
<amcharts:stockLegend>
<amcharts:StockLegend/>
</amcharts:stockLegend>
</amcharts:StockPanel>
</amcharts:panels>
<amcharts:periodSelector>
<amcharts:PeriodSelector position="bottom" width="157">
<amcharts:periods>
<amcharts:PeriodButton selected="true" label="1 Hour" period="hh" count="1"/>
<amcharts:PeriodButton label="2 Hours" period="hh" count="2"/>
<amcharts:PeriodButton label="6 Hours" period="hh" count="6"/>
<amcharts:PeriodButton label="1 Day" period="DD" count="1"/>
<amcharts:PeriodButton label="MAX" period="MAX"/>
</amcharts:periods>
</amcharts:PeriodSelector>
</amcharts:periodSelector>
<amcharts:chartScrollbarSettings>
<amcharts:ChartScrollbarSettings height="30" graph="{g1}"/>
</amcharts:chartScrollbarSettings>
<amcharts:categoryAxesSettings>
<amcharts:CategoryAxesSettings minPeriod="mm"/>
</amcharts:categoryAxesSettings>
<amcharts:chartCursorSettings>
<amcharts:ChartCursorSettings showValueAxisValue="true" crosshair="true"/>
</amcharts:chartCursorSettings>
</amcharts:AmStockChart>
</s:VGroup>
</s:Application>
I'm having a strange problem when trying to updated a div with a couple of paragrahs of text from AJAX.
Here are functions I'm using:
var receivePapers = getXmlHttpRequestObject();
function get_papers(myCat){
if (receivePapers.readyState == 4 || receivePapers.readyState == 0) {
receivePapers.open("GET", 'http://server/path/tocode/file.php?get_papers=1&student_id=1&category=' + myCat, true);
receivePapers.onreadystatechange = handlereceivePapers;
receivePapers.send(null);
}
}
function handlereceivePapers() {
if (receivePapers.readyState == 4) {
var container_div = document.getElementById('paper_container');
var xmldoc = receivePapers.responseXML;
var paper_nodes = xmldoc.getElementsByTagName("paper");
var n_papers = paper_nodes.length;
// Clear the whole container div.
container_div.innerHTML = "";
container_div.innerHTML = "<table class='categoryHeader' width='100%'><tr><th class ='categoryHeader' width='80%' ><br/> " + paper_nodes[1].getElementsByTagName("category")[0].firstChild.nodeValue + "</br> <br/><br/></th></tr>";
container_div.innerHTML += "<tr><td>";
for (i = 0; i < n_papers; i++) {
var paper_id = paper_nodes[i].getElementsByTagName("paper_id");
var paper_title = paper_nodes[i].getElementsByTagName("paper_title");
var paper_desc = paper_nodes[i].getElementsByTagName("paper_desc");
var paper_time = paper_nodes[i].getElementsByTagName("paper_time");
var user_real_name = paper_nodes[i].getElementsByTagName("user_real_name");
var summary_div = document.createElement('div');
summary_div.innerHTML += "<table class='paper'><tr><td class='paperLike' width=80px rowspan=2 valign='top'><div id='" + paper_id[0].firstChild.nodeValue + "'> <img src='images/Like.png' style='padding-top:5px' border='0' /></div></td><td><table width='100%'><tr><td class='paperTitle' style='background-color:white; text-align=left; '><a class='paperTitle' style='padding-left:0;' href='#" + paper_id[0].firstChild.nodeValue + "'>" + paper_title[0].firstChild.nodeValue + "</a></td><td class='paperName' style='margin-right:0; width:200px; background-color:white; text-align:right; vertical-align:text-top;'><span align='right' style='background-color:white; text-align:right; vertical-align:text-top; ' > " + user_real_name[0].firstChild.nodeValue + "</span></td></tr></table></td><td rowspan='2' class='paperLength' style='width:80px; text-align:right; padding-top:8px;' >" + paper_time[0].firstChild.nodeValue + " minutes</td></tr><tr><td class='paperDescription' align='left' colspan='1'>" + paper_desc[0].firstChild.nodeValue + "</td></tr></table>";
container_div.appendChild(summary_div);
}
container_div.innerHTML += "</tr></td></table";
}
}
Here is the XML that's getting returned:
<root>
<paper id="23">
<paper_id>23</paper_id>
<paper_title>title</paper_title>
<paper_desc>
First paragraph of desc
<br/>
<br/>
Second paragraph of desc
<br/>
<br/>
Third paragraph of desc
<br/>
</paper_desc>
<paper_time>45</paper_time>
<user_real_name>Bob Student</user_real_name>
<user_id>2322</user_id>
<category>Languages</category>
</paper>
...
When I push the content to container_div only the first paragraph is showing up. If I stick a Javascript alert() in to return paper_desc it only contains the first paragraph. I've tried looking for other nodes but this says there's only 1 node:
alert(paper_nodes[i].getElementsByTagName("paper_desc").length);
You use paper_desc[0].firstChild.nodeValue
paper_desc[0] is a set of nodes: text nodes and br nodes. You get only the first child of this set, so you get only the first text.
Your alert() call only shows you have only one paper_desc node, not how many nodes you have inside.
I also found strange that you used paper_nodes[1] but I don't know if there is a second node in your XML and if you really want to target it.