Note that there are some explanatory texts on larger screens.

plurals
  1. POIntent inside AsyncTask (Not accessible in scope)
    primarykey
    data
    text
    <p>First of all, I want to apologize for my BAD English.</p> <p>I'm using a AsyncTask class, called from Main_Activity, and when in PostExecute I call de intent, I get an error "Not Enclosing Instance type is accesible in scope"</p> <pre><code>package com.example.pfc; import android.os.Bundle; import android.app.Activity;`enter code here` import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView; public class Principal extends Activity { private Button BotonSalir; private Button BotonAtras; private Button BotonClientes; private Button BotonMaquinas; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_principal); BotonSalir = (Button) findViewById(R.id.BotonSalir); BotonAtras = (Button) findViewById(R.id.BotonAtras); BotonClientes = (Button) findViewById(R.id.BotonClientes); BotonMaquinas = (Button) findViewById(R.id.BotonMaquinas); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_principal, menu); return true; } public void Atras(View view){ finish(); } public void ListaClientes(View view){ SendClientes send = new SendClientes(); send.execute("clientes"); } public void ListaMaquinas(View view){ SendMaquinas send = new SendMaquinas(); send.execute("servidores"); } } </code></pre> <p>And now the asynctask "Send":</p> <pre><code>package com.example.pfc; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeoutException; import org.json.JSONException; import org.json.JSONObject; import android.content.Intent; import android.os.AsyncTask; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Address; import com.rabbitmq.client.BasicProperties; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.ConsumerCancelledException; import com.rabbitmq.client.QueueingConsumer; import com.rabbitmq.client.RpcClient; import com.rabbitmq.client.ShutdownSignalException; public class SendClientes extends AsyncTask &lt;String,Void,Void&gt; { private String requestQueueName = "rpc_queue"; private String replyQueueName; private QueueingConsumer consumer; protected Void doInBackground(String... p) { String mensaje = p[0]; ConnectionFactory cFactory = new ConnectionFactory(); Connection connection; //JSON Object JSONObject json = new JSONObject(); try { json.put("Request", mensaje); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Conexion try { Address[] addrs= new Address[1]; addrs[0] = Address.parseAddress("84.126.242.244"); connection = cFactory.newConnection(addrs); cFactory.setPort(5672); Channel channel = connection.createChannel(); replyQueueName = channel.queueDeclare().getQueue(); consumer = new QueueingConsumer(channel); channel.basicConsume(replyQueueName, true,consumer); String corrId = java.util.UUID.randomUUID().toString(); //Propiedades enviadas al servidor AMQP.BasicProperties props = new AMQP.BasicProperties() .builder() .correlationId(corrId) .replyTo(replyQueueName) .build(); channel.basicPublish("", replyQueueName, props, json.toString().getBytes()); //Esperando respuesta del servidor while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); if (delivery.getProperties().getCorrelationId().equals(corrId)) { String respuesta = new String(delivery.getBody()); break; } } //Eliminamos la cola del servidor, tras haber recibido el mensaje channel.queueDelete(replyQueueName); //cerramos canal y conexion channel.close(); connection.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ShutdownSignalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ConsumerCancelledException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // TODO Auto-generated method stub return null; } //Capturamos la respuesta en el posexecute protected void onPostExecute(String respuesta) { //Lanzamos el intent a la actividad de usuarios, poniendo en el intent la respuesta del servidor. Intent intent = new Intent(Principal.this, Activity_Usuarios.class); //Error "No enclosing instance of the type Principal is accessible in scope" } </code></pre> <p>}</p> <p>Thanks in advance.</p> <p>Bye!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload