gpt4 book ai didi

java - Intent 未定义

转载 作者:行者123 更新时间:2023-12-01 14:55:12 25 4
gpt4 key购买 nike

所以我知道我的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

原因是Activity是Context的子类,而Adapters不是......

关于java - Intent 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14366963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com