菜鸟一枚,tv.setText("Hello Android-" + new java.util.Date());这个一直报错滴说
最近刚开始看Android,这是一段疯狂Android讲义里面的代码,想试试看,发现会一直报错滴说packagecom.example.helloworld;import...
最近刚开始看Android,这是一段疯狂Android讲义里面的代码,想试试看,发现会一直报错滴说
package com.example.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
public class HelloWorldActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_hello_world,menu);
return true;
}
public void clickHandler(View source)
{
TextView tv=(TextView) findViewById(R.id.show);
tv.setText("Hello Android-" + new java.util.Date());
}
}
其实是两个错误
Description Resource Path Location Type
menu cannot be resolved or is not a field HelloWorldActivity.java /HelloWorld/src/com/example/helloworld line 20 Java Problem
Description Resource Path Location Type
The method setText(String) is undefined for the type TextView
HelloWorldActivity.java /HelloWorld/src/com/example/helloworld line 26
Java Problem
请各位高手帮忙啊~ 展开
package com.example.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
public class HelloWorldActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_hello_world,menu);
return true;
}
public void clickHandler(View source)
{
TextView tv=(TextView) findViewById(R.id.show);
tv.setText("Hello Android-" + new java.util.Date());
}
}
其实是两个错误
Description Resource Path Location Type
menu cannot be resolved or is not a field HelloWorldActivity.java /HelloWorld/src/com/example/helloworld line 20 Java Problem
Description Resource Path Location Type
The method setText(String) is undefined for the type TextView
HelloWorldActivity.java /HelloWorld/src/com/example/helloworld line 26
Java Problem
请各位高手帮忙啊~ 展开
3个回答
展开全部
final void setText(int resid)
final void setText(char[] text, int start, int len)
Sets the TextView to display the specified slice of the specified char array.
final void setText(int resid, TextView.BufferType type)
final void setText(CharSequence text)
Sets the string value of the TextView.
void setText(CharSequence text, TextView.BufferType type)
方法里没有形参是string类型的,尝试转成字符试试
final void setText(char[] text, int start, int len)
Sets the TextView to display the specified slice of the specified char array.
final void setText(int resid, TextView.BufferType type)
final void setText(CharSequence text)
Sets the string value of the TextView.
void setText(CharSequence text, TextView.BufferType type)
方法里没有形参是string类型的,尝试转成字符试试
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Menu不能识别,你ctrl+shift+o导下包。然后第二个说的是TextvIEW没有set一个String的方法,你导包后试试看再说吧。我记得是有这方法的。估计就 是没导包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询