[英]Intent is undefined
因此,我知道我的Intent
是未定义的,与此类的构造函数有关,但是我对Java太陌生,无法找出问题所在,也许您可以提供帮助?
serviceIntent = new Intent(this, myPlayService.class);
编码:
@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;
}
我猜this
是指适配器而不是上下文。 尝试:
serviceIntent = new Intent(getApplicationContext(), myPlayService.class);
要么
serviceIntent = new Intent(MainActivity.this, myPlayService.class);
// Where MainActivity is the Activity class's name
原因是活动是上下文的子类,而适配器不是...
意向未定义
如果未在范围(或)类型中为变量定义编译器时未定义变量,则会出现这些错误。
serviceIntent = new Intent(BROADCAST_SEEKBAR);
在这一行中,您没有键入intent
变量。
应该是这样的
Intent serviceIntent = new Intent(BROADCAST_SEEKBAR);
确保您具有:
import android.content.Intent;
在您的导入中,并将变量intent
和serviceIntent
声明为类变量或局部变量,例如:
Intent intent, serviceIntent;
另外,请确保您使用的是正确的上下文。 就您而言, this
可能不是您想要的。 尝试:
serviceIntent = new Intent(MyActivity.this, myPlayService.class); //OR
serviceIntent = new Intent(getBaseContext(), myPlayService.class); //OR
serviceIntent = new Intent(getApplicationContext(), myPlayService.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.