I have 2 .java
files : AnswerActivity.java
public class AnswerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_answer);
new JSONTask().execute("https://example.com/api.php");
}
}
and JSONTask.java
public class JSONTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
//--- some code cut here ---//
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Intent i = new Intent(this, AnswerActivity.class);
Toast.makeText(i, result, Toast.LENGTH_LONG).show();
}
}
my last 2 lines always gives me error :
Intent i = new Intent(this, AnswerActivity.class);
Toast.makeText(i, result, Toast.LENGTH_LONG).show();
I want to display the result
into AnswerActivity as a Toast. but why I always get this error message?
Error:(68, 20) error: no suitable constructor found for Intent(JSONTask,Class<AnswerActivity>)
constructor Intent.Intent(String,Uri) is not applicable
(argument mismatch; JSONTask cannot be converted to String)
constructor Intent.Intent(Context,Class<?>) is not applicable
(argument mismatch; JSONTask cannot be converted to Context)
Error:(69, 14) error: no suitable method found for makeText(Intent,String,int)
method Toast.makeText(Context,CharSequence,int) is not applicable
(argument mismatch; Intent cannot be converted to Context)
method Toast.makeText(Context,int,int) is not applicable
(argument mismatch; Intent cannot be converted to Context)
what did I miss here? thank you