Reputation: 1479
So I get that my Intent
is undefined, something to do with the constructor of this class, but I'm too new at Java to figure out the problem, maybe you can help?
serviceIntent = new Intent(this, myPlayService.class);
the code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
podcastPlayerLayout = inflater.inflate(R.layout.activity_podcast_player, container, false);
try {
serviceIntent = new Intent(this, myPlayService.class);
// --- set up seekbar intent for broadcasting new position to service ---
intent = new Intent(BROADCAST_SEEKBAR);
initViews();
setListeners();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
e.getClass().getName() + " " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
//Adding Listener to button
streamSetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
fileStreamAdress = streamSetButton.getText().toString();
playPauseButtonClicked();
}
});
playPauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
fileStreamAdress = streamSetButton.getText().toString();
playPauseButtonClicked();
}
});
// Inflate the layout for this fragment
return podcastPlayerLayout;
}
Upvotes: 0
Views: 82
Reputation: 82533
Make sure you have:
import android.content.Intent;
among your imports, and the variable intent
and serviceIntent
declared as either class variables or local variables, like:
Intent intent, serviceIntent;
Also, make sure you're using the correct Context. In your case, this
probably isn't what you're looking for. Try:
serviceIntent = new Intent(MyActivity.this, myPlayService.class); //OR
serviceIntent = new Intent(getBaseContext(), myPlayService.class); //OR
serviceIntent = new Intent(getApplicationContext(), myPlayService.class);
Upvotes: 0
Reputation: 86948
I'm guessing this
is referring to the Adapter not a Context. Try:
serviceIntent = new Intent(getApplicationContext(), myPlayService.class);
or
serviceIntent = new Intent(MainActivity.this, myPlayService.class);
// Where MainActivity is the Activity class's name
The reason is Activity is a subclass of Context, while Adapters are not...
Upvotes: 1
Reputation: 66637
Intent is undefined
You will get these errors when variable is not defined in scope (or) type is not clear for compiler.
serviceIntent = new Intent(BROADCAST_SEEKBAR);
In this line you haven't type of the variable intent
.
It should be something like
Intent serviceIntent = new Intent(BROADCAST_SEEKBAR);
Upvotes: 0