-1
My project when axecutar appears this error:
Error:(417, 63) error: cannot find symbol variable testando
Error location:
The app’s Gradle has all the right Recyclerview Imports:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.t2ti.cardapiobalcao"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//v7:22.2.1
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.4.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'commons-io:commons-io:2.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.17'
compile('org.simpleframework:simple-xml:2.7.1') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.google.firebase:firebase-messaging:9.0.2"
//compile 'com.google.firebase:firebase-core:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
Still the error continues and I can not fix.
Below the xml of main Activity
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:orientation="vertical"
android:elevation="1dp"
android:weightSum="1"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="63dp"
android:src="@drawable/logo"
android:id="@+id/imageView" />
<TextView
android:text="@string/txt_info1"
android:layout_width="match_parent"
android:id="@+id/txt_info1"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:layout_weight="0.91"
android:layout_height="match_parent" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<TextView
android:text="@string/txt_info2"
android:layout_width="match_parent"
android:id="@+id/txt_info2"
android:textAppearance="@style/TextAppearance.AppCompat"
android:layout_weight="1.28"
android:layout_height="match_parent" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<Button
android:layout_width="match_parent"
android:layout_height="35dp"
android:text="@string/bt_incluir_item"
android:id="@+id/button"
android:layout_gravity="center_horizontal"
android:onClick="cadastraItem"
android:elevation="0dp"
android:elegantTextHeight="false"
android:background="@drawable/botao_customizado"
android:textAppearance="@android:style/TextAppearance.StatusBar.EventContent.Title" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<TextView
android:text="@string/txt_info3"
android:layout_width="match_parent"
android:id="@+id/textView7"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:layout_weight="0.14"
android:layout_height="24dp" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="348dp">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/testando" />
</android.support.v4.widget.NestedScrollView>
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<TextView
android:text="@string/txt_info4"
android:layout_width="match_parent"
android:id="@+id/textView8"
android:layout_height="24dp"
android:layout_weight="0.19"
android:gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
</LinearLayout>
</ScrollView>
Mainactivity below modified variable name by recyclerViewTest
package com.t2ti.cardapiobalcao;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.squareup.picasso.Picasso;
import com.t2ti.cardapio.Constantes;
import com.t2ti.cardapio.RequisicaoWebService;
import com.t2ti.cardapio.helper.CardapioContract;
import com.t2ti.cardapio.helper.DatabaseOpenHelper;
import com.t2ti.cardapio.model.DataFish;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
ImageView imageView2;
String url = "http://media.prefeituradeimperatriz.com.br/pVCzLbf4KZ-ADFsQ9QPGLTWRw0c=/750x0/https://d2uzqu0gkpnx87.cloudfront.net/site/content/article/recicla_catatreco.jpeg";
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private BroadcastReceiver mRegistrationBroadcastReceiver;
private static final String TAG = "MainActivity";
private String currentUrl;
// CONNECTION_TIMEOUT and READ_TIMEOUT are in milliseconds
public static final int CONNECTION_TIMEOUT = 10000;
public static final int READ_TIMEOUT = 15000;
private RecyclerView mRVFishPrice;
private AdapterFish mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Make call to AsyncTask
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences
.getBoolean(Constantes.SENT_TOKEN_TO_SERVER, false);
if (!sentToken) {
Toast.makeText(MainActivity.this, R.string.msg_erro_token, Toast.LENGTH_LONG).show();
}
}
};
if (checkPlayServices()) {
// Start IntentService to register this application with GCM.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
new AsyncLogin().execute();
//imageView2 = (ImageView)findViewById(R.id.imageView2);
//loadImagefromUrl(url);
}
/**
* Check the device to make sure it has the Google Play Services APK. If
* it doesn't, display a dialog that allows users to download the APK from
* the Google Play Store or enable it in the device's system settings.
*/
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
/*
public void listaItens(View view) {
int categoria;
switch (view.getId()) {
case (R.id.buttonEntrada): {
categoria = Constantes.CATEGORIA_ENTRADA;
break;
}
case (R.id.buttonPratoPrincipal): {
categoria = Constantes.CATEGORIA_PRATO_PRINCIPAL;
break;
}
case (R.id.buttonBebida): {
categoria = Constantes.CATEGORIA_BEBIDA;
break;
}
case (R.id.buttonSobremesa): {
categoria = Constantes.CATEGORIA_SOBREMESA;
break;
}
default: {
categoria = Constantes.CATEGORIA_NAO_DEFINIDA;
}
}
Intent intent = new Intent(this, ListaItemActivity.class);
intent.putExtra("categoria", categoria);
startActivity(intent);
}*/
public void cadastraItem(View view) {
Intent intent = new Intent(this, CadastraItemActivity.class);
startActivity(intent);
}
/*
public void pedidosPendentes(View view) {
Intent intent = new Intent(this, PedidoPendenteActivity.class);
startActivity(intent);
}
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.txt_alert_atualizacao));
builder.setMessage(getResources().getString(R.string.txt_alert_confirma_atualizacao));
builder.setPositiveButton(R.string.txt_sim, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AtualizaDados().execute();
}
});
builder.setNegativeButton(R.string.txt_nao, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
return true;
}
return super.onOptionsItemSelected(item);
}
private class AtualizaDados extends AsyncTask<Void, Void, Boolean> {
private ProgressDialog dialog = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
dialog.setMessage(getResources().getString(R.string.msg_processando));
dialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
try {
RequisicaoWebService requisicaoWebService = new RequisicaoWebService();
List<com.t2ti.cardapio.model.DetalheDenuncia> detalhes = requisicaoWebService.getItensCardapio();
DatabaseOpenHelper databaseOpenHelper = new DatabaseOpenHelper(MainActivity.this);
SQLiteDatabase db = databaseOpenHelper.getWritableDatabase();
databaseOpenHelper.onUpgrade(db, 0, 0);
for (com.t2ti.cardapio.model.DetalheDenuncia detalhe : detalhes) {
ContentValues contentValues = new ContentValues();
contentValues.put(CardapioContract.DetalheDenuncia._ID, detalhe.getId());
contentValues.put(CardapioContract.DetalheDenuncia.COLUMN_NAME_TIPO_DENUNCIA, detalhe.getTipoDenuncia());
contentValues.put(CardapioContract.DetalheDenuncia.COLUMN_NAME_DENUNCIADO, detalhe.getDenunciado());
contentValues.put(CardapioContract.DetalheDenuncia.COLUMN_NAME_LOCAL_DENUNCIA, detalhe.getDescricao());
contentValues.put(CardapioContract.DetalheDenuncia.COLUMN_NAME_PONTO_REFERENCIA, detalhe.getpReferencia());
contentValues.put(CardapioContract.DetalheDenuncia.COLUMN_NAME_DESCRICAO_DENUNCIA, detalhe.getDescricao());
contentValues.put(CardapioContract.DetalheDenuncia.COLUMN_NAME_URL_IMAGEM, detalhe.getUrlImagem());
db.insert(CardapioContract.DetalheDenuncia.TABLE_NAME, null, contentValues);
}
db.close();
return true;
} catch(Exception e) {
Log.e("MainActivity", e.getMessage());
return false;
}
}
@Override
protected void onPostExecute(Boolean b) {
if(b) {
Toast.makeText(MainActivity.this, getResources().getString(R.string.msg_atualizado), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, getResources().getString(R.string.msg_erro_atualizar), Toast.LENGTH_SHORT).show();
}
if (dialog.isShowing()) {
dialog.dismiss();
}
}
}
private class AsyncLogin extends AsyncTask<String, String, String> {
ProgressDialog pdLoading = new ProgressDialog(MainActivity.this);
HttpURLConnection conn;
URL url = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
//this method will be running on UI thread
pdLoading.setMessage("\tLoading...");
pdLoading.setCancelable(false);
pdLoading.show();
}
@Override
protected String doInBackground(String... params) {
try {
// Enter URL address where your json file resides
// Even you can make call to php file which returns json data
//url = new URL("http://192.168.1.7/test/example.json");
url = new URL("https://cardapiobalcao-91464.firebaseapp.com/jsonData/prefeitura.json");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return e.toString();
}
try {
// Setup HttpURLConnection class to send and receive data from php and mysql
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("GET");
// setDoOutput to true as we recieve data from json file
conn.setDoOutput(true);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return e1.toString();
}
try {
int response_code = conn.getResponseCode();
// Check if successful connection made
if (response_code == HttpURLConnection.HTTP_OK) {
// Read data sent from server
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
// Pass data to onPostExecute method
return (result.toString());
} else {
return ("unsuccessful");
}
} catch (IOException e) {
e.printStackTrace();
return e.toString();
} finally {
conn.disconnect();
}
}
@Override
protected void onPostExecute(String result) {
//this method will be running on UI thread
pdLoading.dismiss();
List<DataFish> data=new ArrayList<>();
pdLoading.dismiss();
try {
JSONArray jArray = new JSONArray(result);
// Extract data from json and store into ArrayList as class objects
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
DataFish fishData = new DataFish();
fishData.fishImage= json_data.getString("image");
fishData.fishName= json_data.getString("channel");
fishData.catName= json_data.getString("title");
//fishData.sizeName= json_data.getString("size_name");
//fishData.price= json_data.getInt("price");
data.add(fishData);
}
// Setup and Handover data to recyclerview
mRVFishPrice = (RecyclerView)findViewById(R.id.recyclerViewTest);
mAdapter = new AdapterFish(MainActivity.this, data);
mRVFishPrice.setAdapter(mAdapter);
mRVFishPrice.setLayoutManager(new LinearLayoutManager(MainActivity.this));
} catch (JSONException e) {
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
}
}
}
You can edit your post and add Activity xml?
– StatelessDev