任何人都可以帮助您继续收到此错误 我在这行代码中得到它
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")));
}
});
}
}
答案 0 :(得分:11)
public class CocktailDetail {
...
}
需要:
public class CocktailDetail extends Activity {
...
}
答案 1 :(得分:0)
使用活动类
扩展您的课程