Syntax error on token(s) - animation

I'm trying to make an image move from left to right and right to left. This is the code I have:
package com.example.;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class PlayActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
}
ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
0.0f, 0.0f);
animation.setDuration(5000);
animation.setRepeatCount(5);
animation.setRepeatMode(2);
animation.setFillAfter(true);
imageView2.startAnimation(animation);
However on the last 5 lines it gives me these errors:
Multiple markers at this line
- Syntax error on token(s), misplaced
construct(s)
- Syntax error on token "5000", delete this
token
Multiple markers at this line
- Syntax error on token "5", delete this
token
- Syntax error on token(s), misplaced
Multiple markers at this line
- Syntax error on token(s), misplaced
construct(s)
- Syntax error on token "2", delete this
token
Multiple markers at this line
- Syntax error on token "true", delete this
token
- Syntax error on token(s), misplaced
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on token "animation", VariableDeclaratorId expected after
this token
Could somebody tell me what to fix? besides those 5 lines everything seems to be okay

This code works for me now
package com.example.;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class PlayActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
}
ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
0.0f, 0.0f);
protected TranslateAnimation setanimation(TranslateAnimation animation)
{
animation.setDuration(5000);
animation.setRepeatCount(5);
animation.setRepeatMode(2);
animation.setFillAfter(true);
imageView2.startAnimation(animation);
return animation;
}
}
The issue was that you where trying to set the animations properties outside of a function body. So i fixed it by creating the function protected TranslateAnimation setanimation(TranslateAnimation animation)to hold the code where you are setting the animations properties and now it compiles and runs fine although i don't know what your expected output is.
Hope this helps

Related

intl package and date formatting strange behaviour

I start to use intl package in my dart project.
After start to use this package i use this code:
DateTime now = new DateTime.now();
var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String nowFormatted = formatter.format(now);
And it works correctly.
After i use intl i obtain this message in log:
Uncaught LocaleDataException: Locale data has not been initialized, call initializeDateFormatting(<locale>).
I cannot understand why i should pass locale in this code snippet
intl: ^0.15.7
I've the same issue to the current Intl version so I've solved with
these imports:
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
and the code:
initializeDateFormatting();
DateTime now = DateTime.now();
var dateString = DateFormat('dd-MM-yyyy').format(now);
final String configFileName = 'lastConfig.$dateString.json';
Verify your imports:
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
Set initializeDateFormatting according to your language, example:
initializeDateFormatting('pt_BR', null);
If you encounter this problem, write initializeDateFormatting('az'); top of "Material App". I searched for 1 hour and nobody wrote it clearly.
it is really solved.
I have solved this use in this way:
DateTime now = new DateTime.now();
var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", 'en');
String nowFormatted = formatter.format(now);
But I have to make this to my dart file used to configure itnl support:
library translation_helper;
import 'dart:async';
import 'package:intl/date_symbol_data_local.dart';
import '../../resources/messages_all.dart';
void setupLanguage(){
//var germanDatesFuture = initializeDateFormatting('de_DE', null);
var enDatesFuture = initializeDateFormatting('en', null);
var germanMessagesFuture = initializeMessages('de');
var englishMessagesFuture = initializeMessages('en');
var italianMessagesFuture = initializeMessages('it');
var polishMessagesFuture = initializeMessages('pl');
Future
.wait([
enDatesFuture,
germanMessagesFuture,
englishMessagesFuture,
italianMessagesFuture,
polishMessagesFuture
]);
}
Before I was missing:
var enDatesFuture = initializeDateFormatting('en', null);
For more info I use:
dart 1.15.0
intl 0.12.7
Use this function in main
initializeDateFormatting();
and import like this
import 'package:intl/date_symbol_data_local.dart';
There's no need to call initializeDateFormatting directly from your code. Just call load method of app's localization delegates.
So you specify delegates like this:
final localizationsDelegates = <LocalizationsDelegate>[
AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
CupertinoLocalizationsDelegate()
];
...
MaterialApp(
localizationsDelegates: localizationsDelegates,
)
And pre-load them with system's locale:
import 'dart:ui' as ui;
...
for (final delegate in localizationsDelegates) {
await delegate.load(ui.Locale(ui.window.locale.languageCode));
}
In your pubspec.yaml, add this dependencie package: intl:
In your highest StatefulWidget (in your dart file), add these imports:
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
In its State, override initState add :
#override
void initState() {
super.initState();
initializeDateFormatting(); //very important
}
And the code:
DateTime now = new DateTime.now();
var formatter = new DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String nowFormatted = formatter.format(now);
My issue was that I was getting error specifically for the "en_US" Locale even when I was not particularly using it. But I solved it by:
initializeDateFormatting('en', null);
initializeDateFormatting('en_US,', null);
In your class with MaterialApp add this code
import 'package:intl/date_symbol_data_local.dart';
#override
void initState() {
// TODO: implement initState
super.initState();`enter code here`
initializeDateFormatting();
}
To initialize the date format as per the system locale.
import 'package:intl/intl_standalone.dart'; // For standlone app
import 'package:intl/intl_browser.dart'; // For standlone app
import 'package:intl/date_symbol_data_local.dart';
...
await initializeDateFormatting(await findSystemLocale(), null);
I got the same error. But, only when switching between locales ('en' and 'si') within the app. None of the other solutions worked for me. So I just came up with this dumbest solution, and it worked. Just wrapped date-formatting in a try-catch block while initializeDateFormatting() is being called inside the catch block
String date(DateTime date, String _languageCode) {
try {
var formatter = new DateFormat.yMMMMd(_languageCode);
return formatter.format(date);
} catch(e) {
initializeDateFormatting();
var formatter = new DateFormat.yMMMMd(_languageCode);
return formatter.format(date);
}
}
Depending on intl: ^0.18.0
Just add this line in the method that listens to each time the locale changes
Intl.defaultLocale = languageCode;
package: https://pub.dev/packages/intl

Processing: Calling Capture class within a class possible?

I'm trying to learn how to create classes in Processing, but I can't get the Capture class to work with the same code I would use in the main file of the program.
import processing.video.*;
class Game{
Capture video;
void videoFunction()
{
video = new Capture(this, width, height, 30);
video.start();
}
}
The error I'm getting is that the constructor Capture(filename.Game, int, int, int) is undefined
I'm guessing the problem is either with using this or with using the width and height variables. I can see that in the error message this is printed as the filename of the class, and not the filename of the main PDE.
How do I get the class to recognise this as the main filename, or width, and height as the width and height of the main program?
Is your Game class inside the Processing sketch, or is it in its own tab?
If it's inside the main sketch tab, then you can use the name of the sketch to specify what you mean by "this". Something like this:
void setup(){
Test2 t = new Test2();
t.printClass();
}
class Test2{
void printClass(){
print(TestSketch.this.getClass());
}
}
Note that in the above example, the name of my sketch is TestSketch.
If it's in its own tab, then you need to pass an instance of the Processing sketch into the Game class via its constructor. Something like this:
From the main sketch tab:
void setup(){
Test t = new Test(this);
t.printClass();
}
And in its own tab called Test:
class Test{
TestSketch testSketch;
public Test(TestSketch testSketch){
this.testSketch = testSketch;
}
void printClass(){
print(testSketch.getClass());
}
}

Haxe application exits when deployed to windows

I am making a game engine in haxe/openfl. so far it's just supposed to display the image that belongs to the thing object. what I have built so far runs perfectly on when deployed as a flash application, but closes instantly when I deploy it as a windows application. It just creates a blank screen in html5. I have not tested other targets. I am using HIDE, and every time it crashes, HIDE brings up the message: "File c:\Users\Adu\Documents\HaxeProjects\Downloaded\Export\windows\cpp\bin\Downloaded.exe was changed. Reload?" and gives me the options yes or no. My answer doesn't seem to change the situation. when I manually go into the export directory and run the application, it gives the error: "Error Custom([file_write,stderr]). Here is my code:
Main:
package;
import openfl.display.Graphics;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.Lib;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.ui.Keyboard;
import openfl.events.*;
class Main
{
static var obj(default,default):ObjectManager; //contains the list that all gameobjects add themselves to
static var stage = Lib.current.stage;
public static function main() // this is the gameloop
{
// static entry point
startUp();
var running = true; // gives me a way to exit the gameloop
while (running)
{
logic();
render();
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event)
{
if (event.keyCode == Keyboard.ESCAPE)
{
running=false;
}
});
}
}
static function startUp() // runs once, when the game is started
{
obj= new ObjectManager();
stage.align = openfl.display.StageAlign.TOP_LEFT;
stage.scaleMode = openfl.display.StageScaleMode.NO_SCALE;
}
static function logic() // loops, this handles the logic
{
var thing = new GameObject("assets/pixel_thing.png", 1, obj);
var mech = new GameObject("assets/mechwarrior.png", 0, obj);
}
static function render() // runs right after logic and draws everything to the screen
{
for (i in obj.objects) //iterates through a list of gabeobjects and draws them, it is 2 dimensional so that I can draw objects in blocks
{
for (j in i)
{
Lib.current.addChild(j);
}
}
}
}
GameObject:
package ;
import openfl.display.BitmapData;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.Lib;
import openfl.text.TextField;
import openfl.text.TextFormat;
class GameObject extends Sprite
{
public function new(?image:String, zOrder:Int, objectManager:ObjectManager) // image is the image, zorder is which layer it's drawn on, lower layers are drawn on top objectmanager is just there to help me pass the list to the object
{
super();
var data = Assets.getBitmapData(image);//this is the image data
var bitmap:Bitmap = new Bitmap(data);//this is the actual image
Lib.current.stage.addChild(bitmap);//this sraws the image when the object is instantiated
objectManager.objects[zOrder].push(this);// this adds it to the list of objects
}
}
ObjectManager:
package ;
class ObjectManager
{
public var objects = new Array<Array<GameObject>>();
}
why is it that it works on flash but not windows? How do I fix this?
First off - this doesn't work fine on flash either. Are you running this in the flash debug player? If you don't, which I assume is the case, you won't see any exceptions.
There's a null reference error at this line:
objectManager.objects[zOrder].push(this);// this adds it to the list of objects
You are accessing the array at index zOrder, which doesn't exist. objects is being initialized to [], which does not include the "inner arrays" (it can't, really, how would it know how many of them there should be?).
Now, Windows builds don't give you very helpful debug information by default. A simple way around is to use neko (which mostly behaves the same as hxcpp builds, except it compiles faster and performs worse) for debugging, where you get a stacktrace by default on crashes.
Sure enough, it's the same issue as in flash, the only difference is that native builds crash while flash just "ignores it" and tries to carry on.
Invalid field access : objects
Called from GameObject::new line 92
Called from GameObject::$init line 83
Called from Main::logic line 61
Called from Main::main line 38
Called from Reflect::callMethod line 58
Called from ApplicationMain::main line 91
Called from openfl.Lib::create line 113
For better hxcpp build debug info, you might want to have a look at the crashdumper lib.

WAV Audio recording for Sphinx-4 fail

I recorded a wav file using Audacity for testing transcriber demo from Sphinx-4, I followed the instruction in this post: Sphinx4 speech recognition trasncribe demo not working accurately for short wav file
especially in this answer:
It must be 16khz 16bit mono little-endian file.
I even reduced the noise afterward. But I get the null error when I try to print the hypothesis which mean there was a problem with my recording:
Loading models...
Exception in thread "main" java.lang.NullPointerException
at transcriber.Transcriber.main(Transcriber.java:41)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 minutes 14 seconds)
Line 41 where I print the hypothesis. what can I do to get it work?
Thanks
Edit:
The code is:
package transcriber;
import java.net.URL;
import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
import edu.cmu.sphinx.result.WordResult;
/**
*
* #author ha
*/
public class Transcriber {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws Exception {
System.out.println("Loading models...");
Configuration configuration = new Configuration();
// Load model from the jar
configuration.setAcousticModelPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz");
configuration.setDictionaryPath("resource:/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d");
configuration.setLanguageModelPath("models/language/en-us.lm.dmp");
StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);
URL audioUrl = new URL("file:WAV/Hello.wav");
recognizer.startRecognition(audioUrl.openStream());
SpeechResult result = recognizer.getResult();
System.out.println(recognizer.getResult().getHypothesis());
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n",
result.getHypothesis());
}
System.out.println("Stop Recognition..");
recognizer.stopRecognition();
}
}
Replace
System.out.println(recognizer.getResult().getHypothesis());
with
System.out.println(result.getHypothesis());

JavaFX display scene background image

I’m developing a JavaFX application on Eclipse Kepler using the built-in FX library from Java SDK1.7.0_45. I want to display a background image in a scene. Following the tutorial provided in the Java documentation, following code should work:
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage primaryStage) {
GridPane grid = new GridPane();
Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
scene.getStylesheets().add(Main.class.getResource("Login.css").toExternalForm());
primaryStage.show();
}
}
My CSV file looks like this:
.root {
-fx-background-image: url("background.jpg");
}
But I just get a blank screen instead. I have 3 files in the src/application folder: background.jpg, Main.java and Login.css.
I have tried adding a backslash, putting the image into a separate folder, providing an absolute path, providing several types of images, using ../application/background.jpg, changing the code to file:background.jpg, providing the URL directly into the code and dismissing the CSS file, using an imageview instead, ..... but nothing works.
I've taken a look at several other stackoverflow links, all seemed to fail:
JavaFX How to set scene background image (renders a blank screen)
Setting background image by javafx code (not css) exception)
Cannot load image in JavaFX
and many more.
The strange thing is, when I supply an image from a server as a hyperlink, everything works fine. Supplying the path to a local file never works though. What am I doing wrong? Can somebody show me how to display a local image? Is this a bug?
This worked fine for me with a .png, the only noticeable difference I had as opposed to you, was that I split up the .css file, and my background.png into a sub-package of the main one. Example:
my directory structure looks as follows:
sotestproject ----|
|
|---package sotestProject ---SOTestProject.java
|
|
|
|
package sotestProject.style
|
|---Login.css
|
|---background.png
using this breakdown, the following files with code successfully produced a background with an image:
SoTestProject.java:
package sotestproject;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
/**
*
* #author William
*/
public class SOTestProject extends Application {
#Override
public void start(Stage primaryStage) {
GridPane grid = new GridPane();
Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
scene.getStylesheets().add(SOTestProject.class.getResource("style/Login.css").toExternalForm());
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Login.css:
.root {
-fx-background-image: url("background.png");
}
And then obviously my background.png is in the same directory as the .css file. The main 'change' in code is to note that with the scene.getStyleSheet() I used a reference to style/ instead of just the resource.
I hope this helps!
One thing to note: I'm compiling against the 32-bit jdk 7.0_45. That shouldn't make any difference, but there it is.
Partly thanks to the answer from WillBD, I decided to ditch Eclipse Kepler and start all over in Netbeans. I used the exact same code I provided in my question and now everything works just fine. I guess this is a bug between JavaFX and Eclipse Kepler.
Image file must be in the 'bin/application' directory and add your css definitions to the 'src/application/filename.css'
I've had the same problem in NetBeans and tried basically everything. Eventually, I discovered that the file extension "jpg" was written in capital letters in this "project hierarchy box" on the left side of NetBeans.
I changed that part of my code to all capital letters and tadaaa everything worked just fine.

Resources