2 hate debug hate_debug 于 2014.09.01 23:21 提问

菜鸟一枚~tv.setText("Hello Android-" + new java.util.Date());这个一直报错滴说

小女女是菜鸟,最近刚开始看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

请各位高手帮忙啊~

1个回答

fuweiping
fuweiping   2014.09.02 15:17

Project > Clean.

import android.R;
或者
import your.application.packagename.R;

Csdn user default icon
上传中...
上传图片
插入图片