FATAL EXCEPTION: Asynctask #1: An error occured while executing doInBackground()

Asked

Viewed 51 times

0

Could someone please help me and tell me what’s wrong?

public class SecondActivity extends AppCompatActivity {

//CONECTANDO O APP À INTERNET
HashMap<Integer,View> views = new HashMap<Integer,View>();
Assincrona assinc;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);

    //CONECTANDO O APP À INTERNET
    views.put(R.id.progressBar, findViewById(R.id.progressBar));
    views.put(R.id.txtServidor, findViewById(R.id.txtServidor));
    views.put(R.id.etProduto, findViewById(R.id.etProduto));
    views.put(R.id.etValor, findViewById(R.id.etValor));

    assinc=new Assincrona(3, 3, true,views,this);//

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();


        }
    });
}

//CONECTANDO O APP À INTERNET
public void conectar(View v){



    if(NetSource.isConected(this)){
        ViewMap.setVisibility(views, R.id.progressBar, true);

        Log.i("LOG", "conectado");

        assinc.play();

        Log.i("LOG", "depois do play");

    }

    else{

        Log.i("LOG", "sem conexão");

        ViewMap.setContentTextView(views, R.id.txtServidor, "Sem conexão");
        ViewMap.setVisibility(views, R.id.progressBar, false);
    }

}//


}



/**
* Created by Administrador on 21/10/2015.
* CONECTANDO A APP À INTERNET
*/

public class Assincrona extends offUIImplementation {


public Assincrona(int timeout, int tentativas, boolean askRetry,
                  HashMap<Integer, View> views, Context context) {
    super(timeout, tentativas, askRetry, views, context);

    configRetry("Falha de conexao!", "Tentar novamente?", "sim", "não");
    // TODO Auto-generated constructor stub
}

@Override
public GenericAsync configTypeAsync() {
    // TODO Auto-generated method stub
    return new Requisição();
}

@Override
public void fail(GenericAsync arg0) {

    setContentTextView(R.id.txtServidor, "Conexao falida!");
    setVisibility(R.id.progressBar, false);
}

@Override
public void sucess(GenericAsync arg0) {

    Log.i("LOG", "sucess");
    setContentTextView(R.id.txtServidor, arg0.getReturn());
    setVisibility(R.id.progressBar, false);

}





public class Requisição extends GenericAsync {

    @Override
    public String task(String... arg0) {



        RequestParameters[] parametros = {

                new RequestParameters("action", "1")
                //new RequestParameters("produto",        getContentEditText(R.id.etProduto)),
                //new RequestParameters("valor", getContentEditText(R.id.etValor))
        };





        return NetSource.sendGet("http://lascode.esy.es/webservice.php",
                parametros).toString();


        //return NetSource.sendGet("http://lascode.esy.es/webservice.php",
                //parametros).toString().replace("<br/>","\n");

    }

}

 /*public class Requisição extends GenericAsync{

    @Override
    public String task(String... arg0) {

        RequestParameters[] parametros = {new           
  RequestParameters("nome","andre"),
                new RequestParameters("apelido","figas")};

        return NetSource.sendPost("http://192.168.0.18/android/nome.php/",
                parametros).toString().replace("<br/>","\n");
    }



}*/

}


//Conteúdo do xml:
<EditText
    android:id="@+id/etProduto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="*Produto"
    android:inputType="text" />

<EditText
    android:id="@+id/etValor"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="*Valor"
    android:inputType="number" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Conteudo do Servidor"
    android:layout_gravity="center_horizontal"
    android:id="@+id/txtServidor" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Cadastrar novo produto"
    android:id="@+id/btn_txt_net"
    android:onClick="conectar"/>

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone" />


</LinearLayout>
  • Edit your question and put the properly formatted code

  • In that case, I will have to ask one more question: how to put the properly formatted code here?

  • 1

    Just use indentation of at least 4 spaces. And another thing, add to the question also the error log displayed in Logcat (where you copied the question title).

  • Behold here how to format text and code.

  • The error in the log is exactly what was placed in the title.

  • @Carlosximendes Only this mistake is little to investigate the problem. We need the stack trace complete (including the exception that was generated, on which line of the file was that occurred, and we need you to point out in the code which is this line).

  • It doesn’t trace back to any line in the project. The application runs normally, until when I click on the button to create data in the remote database, and the message "The application stopped!" appears. In the log, the exception appears which is in the title.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.