Compiler not identify warnings, and how can I solve them? - warnings
I have 4 warnings the compiler not identify:
link
When I enter to Arm-Math library, all this errors are appear:
link 2
Why the compiler not recognize them?
And the main question, how can I solve those errors?
Arm-Math is official library, it should not make problems...
This is my code:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* #file : main.c
* #brief : Main program body
******************************************************************************
* #attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <stdint.h>
#define ARM_MATH_CM4
#include "arm_math.h" // for FFT
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#ifdef __GNUC__
/* With GCC, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
void startFFT (void);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* FFT settings */
#define SAMPLES 512 /* 256 real party and 256 imaginary parts */
#define FFT_SIZE SAMPLES / 2 /* FFT size is always the same size as we have samples, so 256 in our case */
/* Global variables */
float32_t Input[SAMPLES];
float32_t Output[FFT_SIZE];
int32_t threshold = 50000;
int32_t neighbor_threshold = 1000;
/* FFT */
arm_cfft_radix4_instance_f32 S; /* ARM CFFT module */
float32_t maxValue; /* Max FFT value is stored here */
uint32_t maxIndex; /* Index in Output array where max value is */
/* USER CODE END 0 */
/**
* #brief The application entry point.
* #retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* UART */
float32_t sine[256] = {1,-0.866025404,0.5,3.06287E-16,-0.5,0.866025404,-1,0.866025404,-0.5,8.57495E-16,0.5,-0.866025404,1,-0.866025404,0.5,6.86051E-15,-0.5,0.866025404,-1,0.866025404,-0.5,3.18506E-15,0.5,-0.866025404,1,-0.866025404,0.5,9.80227E-16,-0.5,0.866025404,-1,0.866025404,-0.5,1.95991E-15,0.5,-0.866025404,1,-0.866025404,0.5,9.3108E-15,-0.5,0.866025404,-1,0.866025404,-0.5,-6.37066E-15,0.5,-0.866025404,1,-0.866025404,0.5,3.43052E-15,-0.5,0.866025404,-1,0.866025404,-0.5,-2.89121E-14,0.5,-0.866025404,1,-0.866025404,0.5,-2.44975E-15,-0.5,0.866025404,-1,0.866025404,-0.5,-2.30318E-14,0.5,-0.866025404,1,-0.866025404,0.5,-8.33003E-15,-0.5,0.866025404,-1,0.866025404,-0.5,-1.71515E-14,0.5,-0.866025404,1,-0.866025404,0.5,1.42114E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-3.9693E-14,0.5,-0.866025404,1,-0.866025404,0.5,-2.00906E-14,-0.5,0.866025404,-1,0.866025404,-0.5,2.30307E-14,0.5,-0.866025404,1,-0.866025404,0.5,3.08725E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-2.79324E-14,0.5,-0.866025404,1,-0.866025404,0.5,2.49923E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-2.20521E-14,0.5,-0.866025404,1,-0.866025404,0.5,1.9112E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-7.30153E-14,0.5,-0.866025404,1,-0.866025404,0.5,1.32317E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-1.02916E-14,0.5,-0.866025404,1,-0.866025404,0.5,6.41949E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-6.12547E-14,0.5,-0.866025404,1,-0.866025404,0.5,1.47115E-15,-0.5,0.866025404,-1,0.866025404,-0.5,5.83124E-14,0.5,-0.866025404,1,-0.866025404,0.5,5.24343E-14,-0.5,0.866025404,-1,0.866025404,-0.5,7.34926E-15,0.5,-0.866025404,1,-0.866025404,0.5,4.6554E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-4.36139E-14,0.5,-0.866025404,1,-0.866025404,0.5,9.75172E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-3.77336E-14,0.5,-0.866025404,1,-0.866025404,0.5,-2.205E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-3.18533E-14,0.5,-0.866025404,1,-0.866025404,0.5,-2.79302E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-2.5973E-14,0.5,-0.866025404,1,-0.866025404,0.5,7.98763E-14,-0.5,0.866025404,-1,0.866025404,-0.5,-2.00928E-14,0.5,-0.866025404,1,-0.866025404,0.5,-3.96908E-14};
for (int32_t i= 0 ; i < SAMPLES ; i+=2)
{
Input[i] = sine [i/2];
Input[i+1] = 0;
}
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
printf("Hello-World \r\n");
HAL_Delay(1500);
startFFT();
printf("6 \r\n");
printf("FFT Max Value: %.2f: \r\n", maxValue);
printf("FFT Max Frequency: %0.2f: \r\n", ((int) maxIndex * 93.75));
HAL_Delay(2000);
printf("FFT Argument: \r\n");
for(int16_t i=0; i<SAMPLES/2; i++)
{
printf("%.2f Hz: %.2f \r\n", (i * 93.75), Output[i]);
HAL_Delay(2000);
}
}
/* USER CODE END 3 */
}
/**
* #brief System Clock Configuration
* #retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
RCC_OscInitStruct.MSICalibrationValue = 0;
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
RCC_OscInitStruct.PLL.PLLM = 1;
RCC_OscInitStruct.PLL.PLLN = 40;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
Error_Handler();
}
}
/**
* #brief USART2 Initialization Function
* #param None
* #retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 9600;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* #brief GPIO Initialization Function
* #param None
* #retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
/*Configure GPIO pin : PA5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/* FFT */
void startFFT (void)
{
printf("1 \r\n");
arm_cfft_radix4_init_f32(&S, FFT_SIZE, 0, 1); // Initialize the CFFT/CIFFT module, intFlag = 0, doBitReverse = 1// ################ need to be added to Init in main area in the ANC code ###########
printf("2 \r\n");
arm_cfft_radix4_f32(&S, Input); // Process the data through the CFFT/CIFFT module // ########### Doing FFT on the input, and save it their (?) // print the result of real and imag for checking
printf("3 \r\n");
arm_cmplx_mag_f32(Input, Output, FFT_SIZE); // Process the data through the Complex Magniture Module for calculating the magnitude at each bin
printf("4 \r\n");
arm_max_f32(Output, FFT_SIZE, &maxValue, &maxIndex); // Calculates maxValue and returns corresponding value
printf("5 \r\n");
return;
}
/* USER CODE END 4 */
/**
* #brief This function is executed in case of error occurrence.
* #retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* #brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* #param file: pointer to the source file name
* #param line: assert_param error line source number
* #retval None
*/
void assert_failed(char *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
I tried to use this code in CubeMxIDE and it work fine. but in Keil, it make problems
It looks like your code has successfully compiled. The error/warnings are probably live content-assist warnings from the IDE.
Related
PhpStorm - setting setters and getters
PhpStorm has a useful feature when quickly creating setters and getters: Code -> generate -> select the items to generate This is great for setting basic setters/getters. However from time to time I want to set more than just setters and getters. For instance I may want to create setters and getters for a one to many or many to many relationship. i.e. Many to many /** * {#inheritDoc} */ public function getOwner() { return $this->owner->toArray(); } /** * Set the list of user * #param Collection $owner */ public function setOwner( Collection $owner ) { $this->registeredUsers->clear(); foreach ( $owner as $item ) { $this->owner[] = $item; } } /** * Add merchant to the collection * #param Collection $owner */ public function addOwner( Collection $owner ) { foreach( $owner as $item ) { $this->owner->add( $item ); } } /** * #param Collection $owner */ public function removeOwner( Collection $owner ) { foreach( $owner as $item ) { $this->owner->removeElement( $item ); } } Is there a way to do this via the same code generation process?
Unfortunately ATM PhpStorm does not support such functionality. https://youtrack.jetbrains.com/issue/WI-25003 -- watch this ticket (star/vote/comment) to get notified about any progress (so far it's not planned for any specific future version -- possibly because of very low number of votes -- sort of: no votes = no interest = no need to invest resources into it right now). Related: https://youtrack.jetbrains.com/issue/WI-19891 The only alternative I can think of right now (that would use that Code Generation functionality) .. is to modify template for Getter/Setter so that it contains more than one method (example). This way you can generate setXXX/addXXX as well as getXXX/removeXXX methods in one go. Obviously, it would be applied in all cases, so if you need just get/set then you would need to manually remove add/remove methods -- that's a drawback of such approach. Note that File & Code Templates could be IDE-wide (Default schema) or project-specific (Project schema) .. so you may use such combined getters/setters in certain projects only. https://www.jetbrains.com/help/phpstorm/2016.1/file-and-code-templates-2.html The only other alternative is half manual and requires you to use Live Templates. Make actual live template (one time job) You need to manually find the place where you want this code to be placed Invoke Live Template expansion (so that code template gets inserted) Fill all live template variables to complete the code. With your addXXX/removeXXX code sample you may end up with just filling 1 or 2 template variables (just a quick estimation on what I see; the same variable can be used multiple times so will be filled in few places at the same time; entered text can be transformed (limited set of transformations) so it can be re-used in another variable automatically (e.g. you are typing owner and in another place it is used as Owner automatically).
Check this out: #set ($array = $TYPE_HINT.split('\|')); #set ($IS_COLLECTION = false); #set ($FIXED_RETURN_TYPE = $RETURN_TYPE); #set ($NAME_LENGTH = $FIELD_NAME.length()); #set ($NAME_BEFORE_LAST = $FIELD_NAME.length() - 1); #set ($LAST_CHARACTER = $FIELD_NAME.substring($NAME_BEFORE_LAST, $NAME_LENGTH)); #set ($METHOD_NAME_BEFORE_LAST = $NAME.length() - 1); #if (${LAST_CHARACTER} == 's') #set ($FIXED_PROPERTY_NAME = $FIELD_NAME.substring(0, $NAME_BEFORE_LAST)); #set ($FIXED_METHOD_NAMING_PART = $NAME.substring(0, $METHOD_NAME_BEFORE_LAST)); #else #set ($FIXED_PROPERTY_NAME = $FIELD_NAME); #set ($FIXED_METHOD_NAMING_PART = $NAME); #end #foreach($hint in $array) #if ($hint.toString().contains('[]')) #set ($ENTRY_HINT = $hint.toString().replace('[]', '')); #set ($HAS_ENTRY_HINT = true); #end #end #foreach($hint in $array) #if ($hint == 'Collection') #set ($IS_COLLECTION = true) #set ($FIXED_RETURN_TYPE = 'Collection') #break #elseif ($hint == 'ArrayCollection') #set ($IS_COLLECTION = true) #set ($FIXED_RETURN_TYPE = 'Collection') #break #elseif ($hint == 'array') #set ($IS_COLLECTION = true) #set ($FIXED_RETURN_TYPE = 'array') #elseif ($hint.toString().contains('[]')) #set ($IS_COLLECTION = true) #set ($FIXED_RETURN_TYPE = 'array') #end #end #if ($IS_COLLECTION) /** * #param ${ENTRY_HINT} $${FIXED_PROPERTY_NAME} * * #return ${CLASS_NAME} */ public function add${FIXED_METHOD_NAMING_PART}(#if (${HAS_ENTRY_HINT})${ENTRY_HINT} #else#end$${FIXED_PROPERTY_NAME})#if(${RETURN_TYPE}): ${CLASS_NAME}#else#end { #if ($FIXED_RETURN_TYPE == 'Collection') if(false === $this->${FIELD_NAME}->contains($${FIXED_PROPERTY_NAME})) { $this->${FIELD_NAME}->add($${FIXED_PROPERTY_NAME}); } #else if(false === in_array($${FIXED_PROPERTY_NAME}, $this->${FIELD_NAME}, true)) { $this->${FIELD_NAME}[] = $${FIXED_PROPERTY_NAME}; } #end return $this; } /** * #param ${ENTRY_HINT} $${FIXED_PROPERTY_NAME} * * #return ${CLASS_NAME} */ public function remove${FIXED_METHOD_NAMING_PART}(#if (${HAS_ENTRY_HINT})${ENTRY_HINT} #else#end$${FIXED_PROPERTY_NAME})#if(${RETURN_TYPE}): ${CLASS_NAME}#else#end { #if ($FIXED_RETURN_TYPE == 'Collection') if(true === $this->${FIELD_NAME}->contains($${FIXED_PROPERTY_NAME})) { $this->${FIELD_NAME}->removeElement($${FIXED_PROPERTY_NAME}); } #else if(true === in_array($${FIXED_PROPERTY_NAME}, $this->${FIELD_NAME}, true)) { $index = array_search($${FIXED_PROPERTY_NAME}, $this->${FIELD_NAME}); array_splice($this->${FIELD_NAME}, $index, 1); } #end return $this; } #end /** * #param ${TYPE_HINT} $${PARAM_NAME} * #return ${CLASS_NAME} */ public function set${NAME}(#if (${SCALAR_TYPE_HINT})${SCALAR_TYPE_HINT} #else#end$${PARAM_NAME})#if(${RETURN_TYPE}): ${CLASS_NAME}#else#end { $this->${FIELD_NAME} = $${PARAM_NAME}; return $this; } I've managed to create something like that, feel free to modify upon your needs. This is the fluent setter live template. It works with Doctrine's Collection/ArrayCollection, arrays. Extending this functionality is as simple as creating new #elseif statement. /** * #var array|string[] */ protected $oneField; /** * #var ArrayCollection|Collection|Another[] * * #ORM\OneToMany(targetEntity="Acme\DemoBundle\Entity\Another") */ protected $anotherField;
How to declare a EventSubscriber in config.yml using bazinga_geocoder.geocoder service?
I am planning to make a reverse geocoding based on the BazingaGeocoderBundle. A simple way to do that is write this simple code in the controller: $result = $this->container ->get('bazinga_geocoder.geocoder') ->using('google_maps') ->reverse(48.79084170157100,2.42479377175290); return $this->render("MinnAdsBundle:Motors:test.html.twig", array('result'=>var_dump($result))); Until here, things are going well. My objective is to make the code nicer & resuable. So, I used this article to write my own GeocoderEventSubscriber as describer below: <?php namespace Minn\AdsBundle\Doctrine\Event; use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Event\LifecycleEventArgs; //use Geocoder\Provider\ProviderInterface; use Bazinga\Bundle\GeocoderBundle\Geocoder\LoggableGeocoder; /** * Subscribes to Doctrine prePersist and preUpdate to update an * the address components of a MotorsAds entity * * #author majallouli */ class MotorsAdsGeocoderEventSubscriber implements EventSubscriber { protected $geocoder; public function __construct(LoggableGeocoder $geocoder){ $this->geocoder = $geocoder; } /** * Specifies the list of events to listen * * #return array */ public function getSubscribedEvents(){ return array( 'prePersist', 'preUpdate', ); } /** * Sets a new MotorsAds's address components if not present * * #param LifecycleEventArgs $eventArgs */ public function prePersist(LifecycleEventArgs $eventArgs){ $motorsAds = $eventArgs->getEntity(); if($motorsAds instanceof \Minn\AdsBundle\Entity\MotorsAds){ if( !$motorsAds->getCountry()){ $em = $eventArgs->getEntityManager(); $this->geocodeMotorsAds($motorsAds,$em); } } } /** * Sets an updating MotorsAds's address components if not present * or any part of address updated * * #param PreUpdateEventArgs $eventArgs */ public function preUpdate(PreUpdateEventArgs $eventArgs){ $motorsAds = $eventArgs->getEntity(); if($motorsAds instanceof \Minn\AdsBundle\Entity\MotorsAds){ if( !$motorsAds->getCountry() ){ $em = $eventArgs->getEntityManager(); $this->geocodeMotorsAds($motorsAds,$em); $uow = $em->getUnitOfWork(); $meta = $em->getClassMetadata(get_class($motorsAds)); $uow->recomputeSingleEntityChangeSet($meta, $motorsAds); } } } /** * Geocode and set the MotorsAds's address components * * #param type $motorsAds */ private function geocodeMotorsAds($motorsAds,$em){ $result = $this->geocode ->using('google_maps') ->reverse($motorsAds->getLat(),$motorsAds->getLng()); $motorsAds->setCountry( $em->getRepository("MinnAdsBundle:Country")->findCountryCode($result['countryCode'])); } } After that, I declared my EventSubscriber as a service: services: # ... geocoder_motorsads.listener: class: Minn\AdsBundle\Doctrine\Event\MotorsAdsGeocoderEventSubscriber arguments: [#bazinga_geocoder.geocoder] # almost sure that the error is here!! tags: - { name: doctrine.event_subscriber } Actually, I get this error: ContextErrorException: Notice: Undefined property: Minn\AdsBundle\Doctrine\Event\MotorsAdsGeocoderEventSubscriber::$geocode in /home/amine/NetBeansProjects/tuto/src/Minn/AdsBundle/Doctrine/Event/MotorsAdsGeocoderEventSubscriber.php line 78 I am almost sure that error is in the declaration of arguments of the EventSubscriber. Is it #bazinga_geocoder.geocoder? Thank you for your help!
Your property is $this->geocoder but you're calling $this->geocode, you're spelling it wrong.
Previous MouseJoints are not getting destroyed when bodies overlap - screenshot
I am getting some weird some weird behaviour with my code. My bodies with the same MASK and CATEGORY when overlapping and touchDragged, recreate the previous mouseJoints. //collision final short CATEGORY_PLAYER = 0x0001; // 0000000000000001 in binary final short CATEGORY_SCENERY = 0x0004; // 0000000000000100 in binary final short MASK_PLAYER = CATEGORY_SCENERY; // or ~CATEGORY_PLAYER short MASK_SCENERY = -1; Here is my MouseJoing implementation: /** * Creates the MouseJoint definition. * * #param body * First body of the joint (i.e. ground, walls, etc.) */ private void createMouseJointDefinition(Body body) { mouseJointDef = new MouseJointDef(); mouseJointDef.bodyA = body; mouseJointDef.collideConnected = false; mouseJointDef.maxForce = 500; } #Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { /* * Define a new QueryCallback. This callback will be used in * world.QueryAABB method. */ QueryCallback queryCallback = new QueryCallback() { #Override public boolean reportFixture(Fixture fixture) { boolean testResult; /* * If the hit point is inside the fixture of the body, create a * new MouseJoint. */ if (testResult = fixture.testPoint(touchPosition.x, touchPosition.y)) { mouseJointDef.bodyB = fixture.getBody(); mouseJointDef.target.set(touchPosition.x, touchPosition.y); mouseJoint = (MouseJoint) world.createJoint(mouseJointDef); } return testResult; } }; /* Translate camera point to world point */ camera.unproject(touchPosition.set(screenX, screenY, 0)); /* * Query the world for all fixtures that potentially overlap the touched * point. */ world.QueryAABB(queryCallback, touchPosition.x, touchPosition.y, touchPosition.x, touchPosition.y); return true; } #Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { /* Whether the input was processed */ boolean processed = false; /* If a MouseJoint is defined, destroy it */ if (mouseJoint != null) { world.destroyJoint(mouseJoint); mouseJoint = null; processed = true; } return processed; } #Override public boolean touchDragged(int screenX, int screenY, int pointer) { /* Whether the input was processed */ boolean processed = false; /* * If a MouseJoint is defined, update its target with current position. */ if (mouseJoint != null) { /* Translate camera point to world point */ camera.unproject(touchPosition.set(screenX, screenY, 0)); mouseJoint.setTarget(new Vector2(touchPosition.x, touchPosition.y)); } return processed; } Thanks for your time....
Fixed by iterating all created jointsworld.getJoints(worldJoints);and destroying the old ones. .
AS3, Access of undefined property
I want to use the Base64 class written by Subhero in AS3, so I created a ActionScript Project containing two files: StringCompress.as and Base64.as. The code is as following. (The code of Base64.as is a bit long, but I just want to show you the function it contains.) However, in StringCompress.as, these two lines return Base64.Encode(textBytes); and var textBytes:ByteArray = Base64.Decode(value); have the same error "Access of undefined property Base64". I don't know why, can anyone help me? Many Thanks!!! //code StringCompress.as code package { import flash.display.Sprite; import flash.utils.ByteArray; import flash.errors.IOError; import flash.events.Event; public class StringCompress extends Sprite { public function StringCompress() { } public static function Compress(value:String):String { var textBytes:ByteArray = new ByteArray(); textBytes.writeUTFBytes(value); textBytes.compress(); return Base64.Encode(textBytes); } public static function UnCompress(value:String):String { var textBytes:ByteArray = Base64.Decode(value); try { textBytes.uncompress(); } catch(e:IOError){ trace("The code to uncompress is not valid."); } return textBytes.toString(); } } } Base64.as code /* * A Base64 encoder/decoder implementation in Actionscript 3 * This work is made available under http://creativecommons.org/licenses/by-nc-sa/2.0/de/deed.en * * #author subhero#gmail.com * #version 0.5 */ package formatter { // import -> import flash.utils.ByteArray; import flash.errors.EOFError; // <- import // Base64 -> /* * A class used for transforming a ByteArray to a Base64-encoded string and vice versa. * Since the "built-in" class (mx.utils.Base64Encoder) is not documented yet, this class can be * used for Base64 encoding/decoding in the meantime. * The class will be deprecated as soon as Macromedia/Adobe decides to fully release the * "native" AS3 Base64 class (Flex2 full release respectively). * Its implementation is based upon a HowTo {#link http://www.kbcafe.com/articles/HowTo.Base64.pdf}, * a Java implementation {#link http://ostermiller.org/utils/Base64.java.html} and an * AS2-implementation by Jason Nussbaum {#link http://blog.jasonnussbaum.com/?p=108} * */ public class Base64 { // mx.utils.StringUtil public static function isWhitespace(char:String):Boolean{ switch (char){ case " ": case "\t": case "\r": case "\n": case "\f": return true; default: return false; } } // the Base64 "alphabet" private static var _b64Chars:Array=new Array( 'A','B','C','D','E','F','G','H', 'I','J','K','L','M','N','O','P', 'Q','R','S','T','U','V','W','X', 'Y','Z','a','b','c','d','e','f', 'g','h','i','j','k','l','m','n', 'o','p','q','r','s','t','u','v', 'w','x','y','z','0','1','2','3', '4','5','6','7','8','9','+','/' ) // the reverse-lookup object used for decoding private static var _b64Lookup:Object=_buildB64Lookup(); // the boolean to insert linebreaks after 76 chars into the Base64 encoded string private static var _linebreaks:Boolean; /* * The class method for encoding an array of bytes to a Base64 encoded string. * * #param bArr A ByteArray containing values to encode * #param linebreaks A boolean to insert a linebreak after 76 Base64-chars * #return The Base64 encoded string * */ public static function Encode(bArr:ByteArray, linebreaks:Boolean=false):String { _linebreaks= linebreaks; return _encodeBytes(bArr); } /* * The class method for decoding a Base64 encoded string to an array of bytes. * * #param str A Base64 encoded string * #return An array of bytes * */ public static function Decode(str:String):ByteArray { return _decodeSring(str); } /* * The private helper class method to build an object used for reverse B64 char lookup. * * #return An object with each B64 char as a property containing the corresponding value * */ private static function _buildB64Lookup():Object { var obj:Object=new Object(); for (var i:Number=0; i < _b64Chars.length; i++) { obj[_b64Chars[i]]=i; } return obj; } /* * The private helper class method to determine whether a given char is B64 compliant. * * #param char A character as string (length=1) * #return A boolean indicating the given char *is* in the B64 alphabet * */ private static function _isBase64(char:String):Boolean { return _b64Lookup[char] != undefined; } /* * The private class method for encoding an array of bytes into a B64 encoded string. * * #param bs An array of bytes * #return The B64 encoded string * * #see formatter.Base64.Encode() * */ private static function _encodeBytes(bs:ByteArray):String { var b64EncStr:String = ""; var bufferSize:uint; var col:uint=0; bs.position=0; while (bs.position < bs.length) { bufferSize= bs.bytesAvailable >= 3 ? 3 : bs.bytesAvailable; var byteBuffer:ByteArray=new ByteArray(); bs.readBytes(byteBuffer, 0, bufferSize); b64EncStr += _b64EncodeBuffer(byteBuffer); col+=4; if (_linebreaks && col%76 == 0) { b64EncStr += "\n"; col=0; } } return b64EncStr.toString(); } /* * The private class method for encoding a buffer of 3 bytes (24bit) to 4 B64-chars * (representing 6bit each => 24bit). * * #param buffer An array of bytes (1 <= length <= 3) * #return The byte buffer encoded to 4 B64 chars as string * * #see formatter.Base64._encodeBytes() * */ private static function _b64EncodeBuffer(buffer:ByteArray):String { var bufferEncStr:String = ""; bufferEncStr += _b64Chars[buffer[0] >> 2]; switch (buffer.length) { case 1 : bufferEncStr += _b64Chars[((buffer[0] << 4) & 0x30)]; bufferEncStr += "=="; break; case 2 : bufferEncStr += _b64Chars[(buffer[0] << 4) & 0x30 | buffer[1] >> 4]; bufferEncStr += _b64Chars[(buffer[1] << 2) & 0x3c]; bufferEncStr += "="; break; case 3 : bufferEncStr += _b64Chars[(buffer[0] << 4) & 0x30 | buffer[1] >> 4]; bufferEncStr += _b64Chars[(buffer[1] << 2) & 0x3c | buffer[2] >> 6]; bufferEncStr += _b64Chars[buffer[2] & 0x3F]; break; default : trace("Base64 byteBuffer outOfRange"); } return bufferEncStr.toString(); } /* * The private class method for decoding a string containing B64 chars to an array of bytes * * #param s The B64 encoded string * #return A decoded array of bytes * * #see formatter.Base64.Decode() * */ private static function _decodeSring(s:String):ByteArray { var b64EncString:String="" + s; var b64DecBytes:ByteArray=new ByteArray(); var stringBuffer:String=""; var lgth:uint=b64EncString.length; for (var i:uint=0; i < lgth; i++) { var char:String=b64EncString.charAt(i); if (!isWhitespace(char) && (_isBase64(char) || char == "=")) { stringBuffer += char; if (stringBuffer.length == 4) { b64DecBytes.writeBytes( _b64DecodeBuffer(stringBuffer) ); stringBuffer=""; } } } b64DecBytes.position=0; return b64DecBytes; } /* * The private class method for decoding a string buffer of 4 B64 chars * (each representing 6bit) to an array of 3 bytes. * * #param buffer A string containing B64 chars (length = 4) * #return An array of bytes containing the decoded values * * #see formatter.Base64._decodeBytes() * */ private static function _b64DecodeBuffer(buffer:String):ByteArray { var bufferEncBytes:ByteArray=new ByteArray(); var charValue1:uint=_b64Lookup[buffer.charAt(0)]; var charValue2:uint=_b64Lookup[buffer.charAt(1)]; var charValue3:uint=_b64Lookup[buffer.charAt(2)]; var charValue4:uint=_b64Lookup[buffer.charAt(3)]; bufferEncBytes.writeByte(charValue1 << 2 | charValue2 >> 4); if (buffer.charAt(2) != "=") bufferEncBytes.writeByte(charValue2 << 4 | charValue3 >> 2); if (buffer.charAt(3) != "=") bufferEncBytes.writeByte(charValue3 << 6 | charValue4); return bufferEncBytes; } } // <- Base64 }
You just didn't import base64 to class where you are using it. Add proper import line. Edit: Put Base64.as into folder formatter, then "import formatter.Base64;" it will work, alternatively - in Base64.as, in first line "package formatter {" delete word "formatter" and then add "import Base64;" in StringCompress.as.
Embedded HTML control for Blackberry?
Is there any api for viewing html content from w/in your blackberry application? To be clear, I don't mean launching the browser on top of my app to view a page. But rather rendering the page w/in my app.
Yes. Check out the net.rim.device.api.browser.field package or the Blackberry Browser section of application integration. Everything sort of finishes here: Field field = browserContent.getDisplayableContent(); See: JDE 4.0.0 API for the package RIM app integration guide Signed only api, as usual.
//BrowserField is available for 4.5 OS. RIM provide sample app for BrowserField Demo. you can find the sample example and run it. /* * BrowserFieldDemo.java * * Copyright © 1998-2010 Research In Motion Ltd. * * Note: For the sake of simplicity, this sample application may not leverage * resource bundles and resource strings. However, it is STRONGLY recommended * that application developers make use of the localization features available * within the BlackBerry development platform to ensure a seamless application * experience across a variety of languages and geographies. For more information * on localizing your application, please refer to the BlackBerry Java Development * Environment Development Guide associated with this release. */ package com.rim.samples.device.blackberry.browser; import java.io.IOException; import javax.microedition.io.HttpConnection; import net.rim.device.api.browser.field.*; import net.rim.device.api.io.http.HttpHeaders; import net.rim.device.api.system.Application; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.Status; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.system.*; /** * This sample application demonstrates how to create a web browser using the * net.rim.device.api.browser.field package. */ public final class BrowserFieldDemo extends UiApplication implements RenderingApplication { private static String REFERER = "referer"; private RenderingSession _renderingSession; private HttpConnection _currentConnection; private MainScreen _mainScreen; /** * Entry point for application * #param args Command line arguments (not used) */ public static void main(String[] args) { BrowserFieldDemo app = new BrowserFieldDemo(); // Make the currently running thread the application's event // dispatch thread and begin processing events. app.enterEventDispatcher(); } // Constructor public BrowserFieldDemo() { _mainScreen = new MainScreen(); pushScreen(_mainScreen); _renderingSession = RenderingSession.getNewInstance(); // Enable javascript //_renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread("http://www.google.com", null, null, null, this); thread.start(); } /** * Processes an http connection * * #param connection The connection to the web content * #param e The event triggering the connection */ void processConnection(HttpConnection connection, Event e) { // Cancel previous request if (_currentConnection != null) { try { _currentConnection.close(); } catch (IOException e1) { } } _currentConnection = connection; BrowserContent browserContent = null; try { browserContent = _renderingSession.getBrowserContent(connection, this, e); if (browserContent != null) { Field field = browserContent.getDisplayableContent(); if (field != null) { synchronized (Application.getEventLock()) { _mainScreen.deleteAll(); _mainScreen.add(field); } } browserContent.finishLoading(); } } catch (RenderingException re) { Utilities.errorDialog("RenderingSession#getBrowserContent() threw " + re.toString()); } finally { SecondaryResourceFetchThread.doneAddingImages(); } } /** * #see net.rim.device.api.browser.RenderingApplication#eventOccurred(net.rim.device.api.browser.Event) */ public Object eventOccurred(Event event) { int eventId = event.getUID(); switch (eventId) { case Event.EVENT_URL_REQUESTED : { UrlRequestedEvent urlRequestedEvent = (UrlRequestedEvent) event; PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(urlRequestedEvent.getURL(), urlRequestedEvent.getHeaders(), urlRequestedEvent.getPostData(), event, this); thread.start(); break; } case Event.EVENT_BROWSER_CONTENT_CHANGED: { // Browser field title might have changed update title. BrowserContentChangedEvent browserContentChangedEvent = (BrowserContentChangedEvent) event; if (browserContentChangedEvent.getSource() instanceof BrowserContent) { BrowserContent browserField = (BrowserContent) browserContentChangedEvent.getSource(); String newTitle = browserField.getTitle(); if (newTitle != null) { synchronized (getAppEventLock()) { _mainScreen.setTitle(newTitle); } } } break; } case Event.EVENT_REDIRECT : { RedirectEvent e = (RedirectEvent) event; String referrer = e.getSourceURL(); switch (e.getType()) { case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT : // Show redirect message. Application.getApplication().invokeAndWait(new Runnable() { public void run() { Status.show("You are being redirected to a different page..."); } }); break; case RedirectEvent.TYPE_JAVASCRIPT : break; case RedirectEvent.TYPE_META : // MSIE and Mozilla don't send a Referer for META Refresh. referrer = null; break; case RedirectEvent.TYPE_300_REDIRECT : // MSIE, Mozilla, and Opera all send the original // request's Referer as the Referer for the new // request. Object eventSource = e.getSource(); if (eventSource instanceof HttpConnection) { referrer = ((HttpConnection)eventSource).getRequestProperty(REFERER); } break; } HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setProperty(REFERER, referrer); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread(e.getLocation(), requestHeaders,null, event, this); thread.start(); break; } case Event.EVENT_CLOSE : // TODO: close the appication break; case Event.EVENT_SET_HEADER : // No cache support. case Event.EVENT_SET_HTTP_COOKIE : // No cookie support. case Event.EVENT_HISTORY : // No history support. case Event.EVENT_EXECUTING_SCRIPT : // No progress bar is supported. case Event.EVENT_FULL_WINDOW : // No full window support. case Event.EVENT_STOP : // No stop loading support. default : } return null; } /** * #see net.rim.device.api.browser.RenderingApplication#getAvailableHeight(net.rim.device.api.browser.BrowserContent) */ public int getAvailableHeight(BrowserContent browserField) { // Field has full screen. return Display.getHeight(); } /** * #see net.rim.device.api.browser.RenderingApplication#getAvailableWidth(net.rim.device.api.browser.BrowserContent) */ public int getAvailableWidth(BrowserContent browserField) { // Field has full screen. return Display.getWidth(); } /** * #see net.rim.device.api.browser.RenderingApplication#getHistoryPosition(net.rim.device.api.browser.BrowserContent) */ public int getHistoryPosition(BrowserContent browserField) { // No history support. return 0; } /** * #see net.rim.device.api.browser.RenderingApplication#getHTTPCookie(java.lang.String) */ public String getHTTPCookie(String url) { // No cookie support. return null; } /** * #see net.rim.device.api.browser.RenderingApplication#getResource(net.rim.device.api.browser.RequestedResource, * net.rim.device.api.browser.BrowserContent) */ public HttpConnection getResource( RequestedResource resource, BrowserContent referrer) { if (resource == null) { return null; } // Check if this is cache-only request. if (resource.isCacheOnly()) { // No cache support. return null; } String url = resource.getUrl(); if (url == null) { return null; } // If referrer is null we must return the connection. if (referrer == null) { HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null); return connection; } else { // If referrer is provided we can set up the connection on a separate thread. SecondaryResourceFetchThread.enqueue(resource, referrer); } return null; } /** * #see net.rim.device.api.browser.RenderingApplication#invokeRunnable(java.lang.Runnable) */ public void invokeRunnable(Runnable runnable) { (new Thread(runnable)).start(); } } /** * A Thread class to fetch content using an http connection */ final class PrimaryResourceFetchThread extends Thread { private BrowserFieldDemo _application; private Event _event; private byte[] _postData; private HttpHeaders _requestHeaders; private String _url; /** * Constructor to create a PrimaryResourceFetchThread which fetches the web * resource from the specified url. * * #param url The url to fetch the content from * #param requestHeaders The http request headers used to fetch the content * #param postData Data which is to be posted to the url * #param event The event triggering the connection * #param application The application requesting the connection */ PrimaryResourceFetchThread(String url, HttpHeaders requestHeaders, byte[] postData, Event event, BrowserFieldDemo application) { _url = url; _requestHeaders = requestHeaders; _postData = postData; _application = application; _event = event; } /** * Connects to the url associated with this object * * #see java.lang.Thread#run() */ public void run() { HttpConnection connection = Utilities.makeConnection(_url, _requestHeaders, _postData); _application.processConnection(connection, _event); } } ///////////////////////////////////////////////////////////////// /* * SecondaryResourceFetchThread.java * * Copyright © 1998-2010 Research In Motion Ltd. * * Note: For the sake of simplicity, this sample application may not leverage * resource bundles and resource strings. However, it is STRONGLY recommended * that application developers make use of the localization features available * within the BlackBerry development platform to ensure a seamless application * experience across a variety of languages and geographies. For more information * on localizing your application, please refer to the BlackBerry Java Development * Environment Development Guide associated with this release. */ package com.rim.samples.device.blackberry.browser; import java.util.Vector; import javax.microedition.io.HttpConnection; import net.rim.device.api.browser.field.BrowserContent; import net.rim.device.api.browser.field.RequestedResource; /** * This class provides the ability to set up an http connection if a referrer * exists (a browser making the request). */ class SecondaryResourceFetchThread extends Thread { /** * Callback browser field. */ private BrowserContent _browserField; /** * Images to retrieve. */ private Vector _imageQueue; /** * True is all images have been enqueued. */ private boolean _done; /** * Sync object. */ private static Object _syncObject = new Object(); /** * Secondary thread. */ private static SecondaryResourceFetchThread _currentThread; /** * Enqueues secondary resource for a browser field. * * #param resource - resource to retrieve. * #param referrer - call back browsr field. */ static void enqueue(RequestedResource resource, BrowserContent referrer) { if (resource == null) { return; } synchronized( _syncObject ) { // Create new thread. if (_currentThread == null) { _currentThread = new SecondaryResourceFetchThread(); _currentThread.start(); } else { // If thread alread is running, check that we are adding images for the same browser field. if (referrer != _currentThread._browserField) { synchronized( _currentThread._imageQueue) { // If the request is for a different browser field, // clear old elements. _currentThread._imageQueue.removeAllElements(); } } } synchronized( _currentThread._imageQueue) { _currentThread._imageQueue.addElement(resource); } _currentThread._browserField = referrer; } } /** * Constructor * */ private SecondaryResourceFetchThread() { _imageQueue = new Vector(); } /** * Indicate that all images have been enqueued for this browser field. */ static void doneAddingImages() { synchronized( _syncObject ) { if (_currentThread != null) { _currentThread._done = true; } } } /** * Connects to the requested resource * * #see java.lang.Runnable#run() */ public void run() { while (true) { if (_done) { // Check if we are done requesting images. synchronized( _syncObject ) { synchronized( _imageQueue ) { if (_imageQueue.size() == 0) { _currentThread = null; break; } } } } RequestedResource resource = null; // Request next image. synchronized( _imageQueue ) { if (_imageQueue.size() > 0) { resource = (RequestedResource)_imageQueue.elementAt(0); _imageQueue.removeElementAt(0); } } if (resource != null) { HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null); resource.setHttpConnection(connection); // Signal to the browser field that resource is ready. if (_browserField != null) { _browserField.resourceReady(resource); } } } } } /////////////////////////////////////////////////////////////////// /* * Utilities.java * * Copyright © 1998-2010 Research In Motion Ltd. * * Note: For the sake of simplicity, this sample application may not leverage * resource bundles and resource strings. However, it is STRONGLY recommended * that application developers make use of the localization features available * within the BlackBerry development platform to ensure a seamless application * experience across a variety of languages and geographies. For more information * on localizing your application, please refer to the BlackBerry Java Development * Environment Development Guide associated with this release. */ package com.rim.samples.device.blackberry.browser; import java.io.IOException; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import net.rim.device.api.io.http.HttpHeaders; import net.rim.device.api.io.http.HttpProtocolConstants; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.util.StringUtilities; /** * This class provides common functions required by the * BrowserContentManagerDemo and BrowserFieldDemo. This class allows the * aforementioned classes to make a connection to a specified url. */ class Utilities { /** * Connect to a web resource * #param url The url of the resource * #param requestHeaders The request headers describing the connection to be made * #param postData The data to post to the web resource * #return The HttpConnection object representing the connection to the resource, null if no connection could be made */ static HttpConnection makeConnection(String url, HttpHeaders requestHeaders, byte[] postData) { HttpConnection conn = null; OutputStream out = null; try { conn = (HttpConnection) Connector.open(url); if (requestHeaders != null) { // From // http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3 // // Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP // request if the referring page was transferred with a secure protocol. String referer = requestHeaders.getPropertyValue("referer"); boolean sendReferrer = true; if (referer != null && StringUtilities.startsWithIgnoreCase(referer, "https:") && !StringUtilities.startsWithIgnoreCase(url, "https:")) { sendReferrer = false; } int size = requestHeaders.size(); for (int i = 0; i < size;) { String header = requestHeaders.getPropertyKey(i); // Remove referer header if needed. if ( !sendReferrer && header.equals("referer")) { requestHeaders.removeProperty(i); --size; continue; } String value = requestHeaders.getPropertyValue( i++ ); if (value != null) { conn.setRequestProperty( header, value); } } } if (postData == null) { conn.setRequestMethod(HttpConnection.GET); } else { conn.setRequestMethod(HttpConnection.POST); conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(postData.length)); out = conn.openOutputStream(); out.write(postData); } } catch (IOException e1) { errorDialog(e1.toString()); } finally { if (out != null) { try { out.close(); } catch (IOException e2) { errorDialog("OutputStream#close() threw " + e2.toString()); } } } return conn; } /** * Presents a dialog to the user with a given message * #param message The text to display */ public static void errorDialog(final String message) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { Dialog.alert(message); } }); } }