Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error on token variabledeclaratorid expected after this token

Im getting "syntax error on token variabledeclaratorid expected after this token" on the following line

  listAq = new AQuery(this);

Here is my full code

 package com.example.test;

import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

import com.androidquery.AQuery;

public class TestActivity extends Activity {



    private AQuery aq;

    @Override
    public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);



    }

    listAq = new AQuery(this);

    ArrayAdapter<JSONObject> aa = new ArrayAdatper<JSONObject>(this, R.layout.activity_main, items){


        @Override

        public View getView(int position, View convertView, ViewGroup parent){

            if(convertView == null){
            convertView = getLayoutInflater().inflate(R.layout.activity_main, null);
            }

            JSONObject jo = getItem(position);

            AQuery aq = listAq.recycle(convertView);
            aq.id(R.id.name).text(jo.optString("titleNoFormating", "No Title"));
            aq.id(R.id.meta).text(jo.optString("publisher", ""));

            String tb = jo.optJSONObject("image").optString("tbUrl");
            aq.id(R.id.tb).progress(R.id.progress).image(tb,true, true,0,0,null,AQuery.FADE_IN_NETWORK,1.0f);
            return convertView;
        }
    };



}
like image 448
westnblue Avatar asked Jul 06 '13 03:07

westnblue


People also ask

What is syntax error on tokens?

The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.

What is VariableDeclaratorId?

It turns out VariableDeclaratorId is a class public class VariableDeclaratorId extends Expression implements prettyprint.PrettyPrintable. If you read the class description using it with the error message to determine that you forgot to define the variable type, I am impressed; I simply made an educated guess.


2 Answers

Move this inside onCreate

 AQuery listAq = new AQuery(this);
 ArrayAdapter<JSONObject> aa = new ArrayAdatper<JSONObject>(this, R.layout.activity_main, items){
 ....
like image 92
Raghunandan Avatar answered Nov 03 '22 01:11

Raghunandan


Few visible problems form your code

First in the below statement:

listAq = new AQuery(this);

listAq is of which type? It is not defined in your code It has to be somehting like

AQuery listAq;
listAq = new AQuery(this);

As you are trying to initialize with 'this', this stands for the current object. Current object will not be created until your constructor is called. Constructor is called after the variables initialization. So your statement is both sytantically and logically wrong. You need to move this statement in a non-static method to initialize your listAq object;

Another problematic statement:

ArrayAdapter<JSONObject> aa = new ArrayAdatper<JSONObject>(this, R.layout.activity_main, items){

You need to move this code again to a method to run. In java you need to have all executable statements in a method. Only class/instance variable declarations can be outside the method/constructors.

like image 41
Juned Ahsan Avatar answered Nov 03 '22 00:11

Juned Ahsan