Android Toast throwing error

My main activity "My_Gallery" is calling a function from another class "DataCall". In DataCall I am trying to Toast a variable to make sure I have the correct info in there.

Toast.makeText(DataCall.this, url_param_string, Toast.LENGTH_SHORT).show();

But I am getting the following error under DataCall.this

Cannot use this in a static context

Not sure what I am missing. Thanks in advance for any feedback.

Also I am new to Eclipse and I see in debug mode there is a window for variables but it is empty.

Answers


That's exactly the error. You can't call this on a static context, like a static function.

If you need a context for Toast. Try the application context: Context.getApplicationContext()


Dentro del metodo agrega un parametro adicional que indique el contexto: ejemplo:

public static void sendMessage(String message, Context contexto) 
{
    if (mRfcommClient.getState() != Bluetooth_lib.STATE_CONNECTED) 
    {   
      Toast.makeText(contexto, "No conectado", Toast.LENGTH_SHORT).show(); 
    } 
}

Need Your Help

OnCtrlColor Not Working?

visual-c++ mfc release-mode debug-mode dialogbasedapp

I used the following overloaded method to change the text color to red in a listbox, in a Visual C++ MFC dialog based application. When I build the program in DEBUG mode, it works perfectly. But wh...

There is already an object named 'tableName' in the database

c# sql sql-server visual-studio sqlexception

i want to create database and i use entity framework but when i run my wpf project, i take this error. This error appears for 2 tables. In here, my error: