0

所以我知道 myIntent是未定义的,与此类的构造函数有关,但我对 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;


}
4

3 回答 3

1

我猜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 不是...

于 2013-01-16T20:15:04.803 回答
0

意图未定义

当变量未在作用域(或)类型中对编译器不明确时,您将收到这些错误。

serviceIntent = new Intent(BROADCAST_SEEKBAR);

在这一行中,您没有输入变量intent

它应该是这样的

Intent serviceIntent = new Intent(BROADCAST_SEEKBAR);
于 2013-01-16T20:14:53.610 回答
0

确保你有:

import android.content.Intent;

在您的导入中,变量intentserviceIntent声明为类变量或局部变量,例如:

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);
于 2013-01-16T20:17:12.487 回答