Java android应用程序停止工作,没有在emulator上显示演示
编码有什么问题……这是我的java页面 请帮助我,因为我是一个初学者,我感到困惑。。。。。 我正在制作一个简单的add 1 and sub 1应用程序,跟踪travis(新波士顿)youtube tutuorials…其中的xml代码显示了9条警告,因为我没有像travis sir nt在教程中使用的那样使用带文本的字符串Java android应用程序停止工作,没有在emulator上显示演示,java,android,eclipse,android-layout,Java,Android,Eclipse,Android Layout,编码有什么问题……这是我的java页面 请帮助我,因为我是一个初学者,我感到困惑。。。。。 我正在制作一个简单的add 1 and sub 1应用程序,跟踪travis(新波士顿)youtube tutuorials…其中的xml代码显示了9条警告,因为我没有像travis sir nt在教程中使用的那样使用带文本的字符串 int counter; Button add, sub; TextView display; @Override protected void onCreate(Bund
int counter;
Button add, sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter =0;
add = (Button) findViewById("R.id.bAdd");
sub = (Button) findViewById("R.id.bSub");
display = (TextView) findViewById("R.id.tvDisplay");
add.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//TODO Auto-generated method stub
counter++;
display.setText("Your total is" + counter);
}
});
sub.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//TODO Auto-generated method stub
counter--;
display.setText("Your total is" + counter);
}
});
}
private TextView findViewById(String string) {
// TODO Auto-generated method stub
return null;
}
}
这是我的.xml页面
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/tvDisplay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:layout_gravity="center"
android:gravity="center"
></TextView>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="add one"
android:textSize="20dp"
android:layout_gravity="center"
android:id="@+id/bAdd" >
</Button>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Sub one"
android:textSize="20dp"
android:layout_gravity="center"
android:id="@+id/bSub">
</Button>
android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”
android:orientation=“垂直”
>
findViewById
采用int参数而不是字符串:
findViewById(R.id.bAdd);
我删除了这部分私有TextView findViewById(String String){//TODO自动生成的方法存根返回null;},但它再次显示findViewById不适用于arguments@user3427015什么您所要做的就是从发送到
findviewbyd
方法的参数中删除引号,就像在我的示例中一样,仅适用于所有通话。thnx很多先生,因为我是一名初学者,在过去5小时内我一直在搜索错误,您帮了我很多。thnx 4r您的耐心…@user3427015欢迎您,但您可以通过查看网站上的一些示例轻松找到这一点。快乐编码!