Why identifier expected with this demo code - gtk

I am trying demo code from this page:
public class My_combobox{
private Gtk.ListStore liststore;
private ComboBox combobox;
liststore = new Gtk.ListStore(1, typeof (string));
Gtk.TreeIter iter;
liststore.append(out iter);
liststore.set(iter, 0, "Rafael Nadal", -1);
liststore.append(out iter);
liststore.set(iter, 0, "Roger Federer", -1);
liststore.append(out iter);
liststore.set(iter, 0, "Novak Djokovic", -1);
cellrenderertext = new CellRendererText();
combobox = new ComboBox();
combobox.set_model(liststore);
combobox.pack_start(cellrenderertext, true);
combobox.add_attribute(cellrenderertext, "text", 0);
//combobox.changed.connect(on_combobox_changed);
}
However, I am getting following errors:
$ valac formatGUI_v2.vala --pkg=gtk+-3.0
formatGUI_v2.vala:65.12-65.12: error: syntax error, expected identifier
liststore = new Gtk.ListStore(1, typeof (string));
^
formatGUI_v2.vala:65.31-65.31: error: syntax error, `new' modifier not allowed on creation method
liststore = new Gtk.ListStore(1, typeof (string));
^
formatGUI_v2.vala:73.44-73.44: error: syntax error, `new' modifier not allowed on creation method
cellrenderertext = new CellRendererText();
^
formatGUI_v2.vala:74.25-74.25: error: syntax error, `new' modifier not allowed on creation method
combobox = new ComboBox();
^
Compilation failed: 4 error(s), 0 warning(s)
Where is the problem and how can it be corrected?
I tried to put code in constructor:
public class My_combobox{
public void My_combobox(){
private Gtk.ListStore liststore;
private ComboBox combobox;
liststore = new Gtk.ListStore(1, typeof (string));
Gtk.TreeIter iter;
liststore.append(out iter);
liststore.set(iter, 0, "Rafael Nadal", -1);
liststore.append(out iter);
liststore.set(iter, 0, "Roger Federer", -1);
liststore.append(out iter);
liststore.set(iter, 0, "Novak Djokovic", -1);
cellrenderertext = new CellRendererText();
combobox = new ComboBox();
combobox.set_model(liststore);
combobox.pack_start(cellrenderertext, true);
combobox.add_attribute(cellrenderertext, "text", 0);
//combobox.changed.connect(on_combobox_changed);
}
}
But still, I get following errors, both with gtk3 and gtk2:
$ valac formatGUI_v2.vala --pkg=gtk+-2.0
formatGUI_v2.vala:64.11-64.13: error: syntax error, following expression/statement delimiter `;' missing
private Gtk.ListStore liststore;
^^^
formatGUI_v2.vala:64.14-64.14: error: syntax error, expected identifier
private Gtk.ListStore liststore;
^
formatGUI_v2.vala:66.13-66.13: error: syntax error, expected identifier
liststore = new Gtk.ListStore(1, typeof (string));
^
formatGUI_v2.vala:66.32-66.32: error: syntax error, `new' modifier not allowed on creation method
liststore = new Gtk.ListStore(1, typeof (string));
^
formatGUI_v2.vala:74.42-74.42: error: syntax error, `new' modifier not allowed on creation method
cellrenderertext = new CellRendererText();
^
formatGUI_v2.vala:75.26-75.26: error: syntax error, `new' modifier not allowed on creation method
combobox = new ComboBox();
^
Compilation failed: 6 error(s), 0 warning(s)

The demo code you link to does make the difference between declaring the fields in the class and then initialising them in the constructor, but that has been lost in the example in your question.
Your code should be more of the form:
public class My_combobox
{
// Here you declare the field
private Gtk.ListStore liststore;
// Here, in the constructor, you instantiate and initialise
// the ListStore and assign it to the field. This is called when
// the class is instantiated as an object at runtime
public My_combobox()
{
liststore = new Gtk.ListStore(1, typeof (string));
Gtk.TreeIter iter;
liststore.append(out iter);
liststore.set(iter, 0, "Rafael Nadal", -1);
}
}

Related

Triggerhandler class and trigger issue - showing nullpoint exception error

trigger AssignedResourceTrigger on AssignedResource (after insert,after update){
if(trigger.isAfter & AssignedResourceTriggerHandler.isRecursive){
if(trigger.isInsert || trigger.isUpdate){
AssignedResourceTriggerHandler.assignedResourceOnServiceAppointment(trigger.new);
AssignedResourceTriggerHandler.isRecursive = false;
}
}
}
This is the error:
AssignedResourceTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.AssignedResourceTriggerHandler: line 9, column 1 Trigger.AssignedResourceTrigger: line 3, column 1

Can not call procedure by JPA - could not determine data type of parameter

When trying to call procedure with timestamp parameters by the code:
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource)
.withSchemaName("time_series")
.withProcedureName("refresh_continuous_aggregate")
.declareParameters(new SqlParameter("continuous_aggregate", Types.VARCHAR),
new SqlParameter("window_start", Types.TIMESTAMP),
new SqlParameter("window_end", Types.TIMESTAMP));
MapSqlParameterSource inParams = new MapSqlParameterSource()
.addValue("continuous_aggregate", "time_series.current_data_hourly", Types.VARCHAR)
.addValue("window_start", "2020-11-12 01:02:03.123456789", Types.TIMESTAMP)
.addValue("window_end", "2021-02-12 01:02:03.123456789", Types.TIMESTAMP);
Map<String, Object> execute = simpleJdbcCall.execute(inParams);
I'm getting error:
ERROR o.s.i.handler.LoggingHandler ->
org.springframework.jdbc.BadSqlGrammarException:
CallableStatementCallback; bad SQL grammar [{call
time_series.refresh_continuous_aggregate(?, ?, ?)}]; nested exception
is org.postgresql.util.PSQLException: ERROR: could not determine data
type of parameter $2
The similar error I'm getting when I try to use native query with dynamic parameters:
String queryStr = "CALL time_series.refresh_continuous_aggregate(?1, ?2, ?3)";
Query query = entityManager.createNativeQuery(queryStr)
.setParameter(1, continuousAggregate)
.setParameter(2, windowStart, TemporalType.TIMESTAMP)
.setParameter(3, windowEnd, TemporalType.TIMESTAMP);
Object singleResult = query.getSingleResult();
ERROR o.h.e.jdbc.spi.SqlExceptionHelper -> ERROR: syntax error at or
near "$2"
And by using StoredProcedureQuery:
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("time_series.refresh_continuous_aggregate")
.registerStoredProcedureParameter("continuous_aggregate", String.class, ParameterMode.IN)
.registerStoredProcedureParameter("window_start", Date.class, ParameterMode.IN)
.registerStoredProcedureParameter("window_end", Date.class, ParameterMode.IN)
.setParameter("continuous_aggregate", "time_series.current_data_hourly")
.setParameter("window_start", new Date(), TemporalType.TIMESTAMP)
.setParameter("window_end", new Date(), TemporalType.TIMESTAMP);
query.execute();
WARN o.h.e.jdbc.spi.SqlExceptionHelper -> SQL Error: 0, SQLState:
42P18 ERROR o.h.e.jdbc.spi.SqlExceptionHelper -> ERROR: could not
determine data type of parameter $2
It looks like JDBC drivers issue.

How to use and compile standard c Lib in vala?

I'm just start few test in vala.
Vala is new for me . Sure I started to read a lot of tuto, but I don't understand my mistake.
how to use and compile the follow code?
using Gtk;
#include <stdio.h>
// compile with valac --pkg gtk+-3.0 hello_world_gtk_01.vala
public const int EXIT_SUCCESS=0;
int main (string[] args)
{
Gtk.init (ref args);
var window = new Window ();
window.title = "Hello, World!";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size (350, 70);
window.destroy.connect (Gtk.main_quit);
stdout.printf ("Version de gtk: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION);
stdout.printf ("Version de gtk: %u.%u.%u\n", get_major_version() , get_minor_version(), get_micro_version());
string name, str;
name = "Version de gtk: ";
sprintf(str, "%d", get_major_version());
name = name+ str;
sprintf(str, "%d", get_minor_version());
name = name+ str;
sprintf(str, "%d", get_micro_version());
name = name+ str+ "\n";
var label = new Label (name);
window.add (label);
window.show_all ();
Gtk.main ();
return EXIT_SUCCESS;
}
What is bad ?
Gcc said
hello_world_gtk_01.vala:2.2-2.9: error: syntax error, invalid preprocessing directive
#include <stdio.h>
^^^^^^^^
hello_world_gtk_01.vala:2.10-2.10: error: syntax error, expected identifier
#include <stdio.h>
^
Compilation failed: 2 error(s), 0 warning(s)
could you help me to understand how to manage stdio?
Vala generates C code, but you can't pass C straight from the Vala file to the generated C. The Vala [CCode] attribute gives fine control over the generated C, but you won't need that in most cases. For an example of standard C names and their GLib equivalents take a look at the glib-2.0.vapi file in the Vala repository. Other standard C and POSIX extensions are in posix.vapi. There is also an in depth tutorial on writing a binding from Vala to a C library. Writing a binding, however, is a more advanced topic and what you are trying to achieve in your example doesn't need a new binding.
Your example uses string interpolation. In Vala a data type can have a method, so one way to write what you want would be:
name = "Version de gtk: %u.%u.%u\n".printf( get_major_version (), get_minor_version (), get_micro_version ());
Vala also has a string template syntax, #"", and and then an expression, $(), inside the string is evaluated. For example:
name = #"Version de gtk: $(get_major_version ()).$(get_minor_version ()).$(get_micro_version ())\n";
This works because uint, the return value of the function calls, has a to_string () method that is implicitly called by the string template.
Here's your example modified to use the string template method:
using Gtk;
// compile with valac --pkg gtk+-3.0 hello_world_gtk_01.vala
public const int EXIT_SUCCESS=0;
int main (string[] args)
{
Gtk.init (ref args);
var window = new Window ();
window.title = "Hello, World!";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size (350, 70);
window.destroy.connect (Gtk.main_quit);
stdout.printf ("Version de gtk: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION);
stdout.printf ("Version de gtk: %u.%u.%u\n", get_major_version() , get_minor_version(), get_micro_version());
var name = #"Version de gtk: $(get_major_version ()).$(get_minor_version ()).$(get_micro_version ())\n";
var label = new Label (name);
window.add (label);
window.show_all ();
Gtk.main ();
return EXIT_SUCCESS;
}

SQL Parse Error: Parameter name expected using firebird

I'm using the script in firebird:
SET TERM ^ ;
execute block as
declare a_cursor CURSOR FOR(select contaSelect.cdcontacontabil, spedcontavincSelect.nuversao, spedcontavincSelect.cdcontasped
from ectbconta contaSelect join ectbspedcontavinc spedcontavincSelect on contaSelect.cdempresa=spedcontavincSelect.cdempresa and contaSelect.cdconta=spedcontavincSelect.cdconta where contaSelect.cdempresa = 1);
​
declare variable contacontabil varchar(40);
declare variable versao integer;
declare variable contasped integer;
​
begin
open a_cursor;
while(1=1) do
begin
fetch a_cursor INTO contacontabil, versao, contasped;
if (row_count = 0) then leave;
insert into ectbspedcontavinc (cdempresa, cdconta, nuversao, cdcontasped)
select contaInsert.cdempresa, contaInsert.cdconta, :versao, :contasped from ectbconta contaInsert
where contaInsert.cdcontacontabil =:contacontabil and contaInsert.cdempresa in(2, 3, 4)
and not exists (select * from ectbspedcontavinc spedcontavincInsert
where spedcontavincInsert.cdempresa=contaInsert.cdempresa and spedcontavincInsert.cdconta=contaInsert.cdconta and spedcontavincInsert.nuversao=:versao and spedcontavincInsert.cdcontasped=:contasped);
end
end
^
​
SET TERM ; ^
​
COMMIT WORK;
Ocurred this message:
Error Message:
---------------------------------------- SQL Parse Error:
Parameter name expected
D:\Java\Firebird_2_5\bin>isql.exe -z ISQL Version: WI-V2.5.5.26952
Firebird 2.5 Use CONNECT or CREATE DATABASE to specify a database SQL>
I don't know what do.
public class CriaScriptSpedContaVincService {
private static final Integer GRUPO_EMPRESA_CTB = 3;
private static final Integer CD_EMPRESA_CONSOLIDADORA = 102;
public void criaCriaScriptSpedContaVinc() {
StringBuilder script = new StringBuilder();
IContabEmpresa contabEmpresa = new ContabEmpresaProvider();
List<Integer> empresas = contabEmpresa.retornaEmpresasDoGrupoContabil(GRUPO_EMPRESA_CTB);
for (Integer cdEmpresa : empresas) {
script.append("INSERT INTO ECTBSPEDCONTAVINC (CDEMPRESA, CDCONTA, NUVERSAO, CDCONTASPED) ");
script.append("SELECT ");
script.append(cdEmpresa);
script.append(" AS CDEMPRESA, C.CDCONTA, C.NUVERSAO, C.CDCONTASPED ");
script.append("FROM ECTBSPEDCONTAVINC C WHERE C.CDEMPRESA = ");
script.append(CD_EMPRESA_CONSOLIDADORA);
script.append(" AND NOT EXISTS (SELECT * FROM ECTBSPEDCONTAVINC CV WHERE CV.CDEMPRESA = ");
script.append(cdEmpresa);
script.append(" AND CV.CDCONTA = C.CDCONTA);");
script.append(TextUtil.NOVA_LINHA);
}
String caminhaCompletoArquivo = "t:/xande/script2.sql";
FileUtil.escreveArquivo(script, caminhaCompletoArquivo);
System.out.println("Fechou mano... ;)");
}
}

Cocos2d-x HockeyApp integration

I tried to integrate HockeyApp in my cocos2d-x project, using following link:-
http://support.hockeyapp.net/kb/client-integration-android/hockeyapp-for-android-ndk-early-access
But it gives me following error when I tried to run ndk-build command
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:47:7: error: expected nested-name-specifier before 'AndroidLogBufferWriteFunc'
using AndroidLogBufferWriteFunc = int (*)(int bufID, int prio, const char *tag,
^
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:47:7: error: 'AndroidLogBufferWriteFunc' has not been declared
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:47:33: error: expected ';' before '=' token
using AndroidLogBufferWriteFunc = int (*)(int bufID, int prio, const char *tag,
^
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:47:33: error: expected unqualified-id before '=' token
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:53:1: error: 'AndroidLogBufferWriteFunc' does not name a type
AndroidLogBufferWriteFunc g_android_log_buf_write = nullptr;
^
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc: In function 'void logger::initializeCrashLogWriter()':
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:60:3: error: 'g_android_log_buf_write' was not declared in this scope
g_android_log_buf_write = reinterpret_cast<AndroidLogBufferWriteFunc>(
^
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:60:46: error: expected type-specifier before 'AndroidLogBufferWriteFunc'
g_android_log_buf_write = reinterpret_cast<AndroidLogBufferWriteFunc>(
^
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:60:46: error: expected '>' before 'AndroidLogBufferWriteFunc'
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:60:46: error: expected '(' before 'AndroidLogBufferWriteFunc'
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:60:46: error: 'AndroidLogBufferWriteFunc' was not declared in this scope
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:61:54: error: expected ')' before ';' token
dlsym(RTLD_DEFAULT, "__android_log_buf_write"));
^
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc: In function 'int logger::writeToCrashLog(const char*)':
jni/../../breakpad/android/google_breakpad/../../src/client/linux/log/log.cc:68:7: error: 'g_android_log_buf_write' was not declared in this scope
if (g_android_log_buf_write) {
^
make: *** [obj/local/armeabi/objs/breakpad_client/src/client/linux/log/log.o] Error 1
GCC 4.6.3 doesn't support C++11 type aliases:
in
Breakpad\src\client\linux\log\log.cc
replace
using AndroidLogBufferWriteFunc = int (*)(int bufID, int prio, const char *tag,const char *text);
with
typedef int (*AndroidLogBufferWriteFunc)(int bufID, int prio, const char *tag,const char *text);