0

任何人都可以帮助不断收到此错误我在这行代码中得到它

TextView t1 = (TextView)findViewById(R.id.textCocktailName);

这是完整的代码片段:

package com.drunktxtapp;

import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.widget.TextView;
import android.view.View;


public class CocktailDetail {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bloody_mary);
        ImageView imageView1 = (ImageView)findViewById(R.id.imageCocktail);
        imageView1.setImageDrawable(getResources().getDrawable(R.drawable.bloodymary));
        Button b1 = (Button) findViewById(R.id.bYoutube);
        TextView t1 = (TextView) findViewById(R.id.textCocktailName);
        String cocktailName = getIntent().getStringExtra("Bloody Mary");
        t1.setText(cocktailName);
        b1.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=Alt-ehDc3fc")));
                }
        });
    }
}
4

2 回答 2

11
public class CocktailDetail { 
...
}

需要是:

public class CocktailDetail extends Activity {
...
}
于 2013-04-18T08:01:07.870 回答
0

使用 Activity 类扩展您的课程

于 2013-04-18T08:10:03.533 回答