刚开始搞Android ,还没开始搞呢就出现了这个错,求解答下

节桃 2014-06-18 05:23:33

setContentView(R.layout.main);

一直提示找不到main,我用的新版的,layout里面有两个xml文件,没有main.xml,各位遇到这问题了吗?求解答下
...全文
215 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
节桃 2014-06-19
  • 打赏
  • 举报
回复
引用 9 楼 hjywyj 的回复:
[quote=引用 7 楼 ai1443363329 的回复:]是的,名字我改了,但是上面的那段代码运行还是出错了。。(⊙o⊙)…
删除下面这段代码 if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit(); } 新版用不惯的话就下个老版本的Eclipse吧[/quote]已经解决啦,引用的layout下的哪个文件 就在哪个文件下创建TextView,报错是因为创建的和引用的不同,此贴终结,多谢各位帮解释
  • 打赏
  • 举报
回复
引用 7 楼 ai1443363329 的回复:
是的,名字我改了,但是上面的那段代码运行还是出错了。。(⊙o⊙)…
删除下面这段代码 if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit(); } 新版用不惯的话就下个老版本的Eclipse吧
westlackrecluse 2014-06-18
  • 打赏
  • 举报
回复
看看你class类顶部导入的是android.R.还是你自己工程里的R
节桃 2014-06-18
  • 打赏
  • 举报
回复
引用 3 楼 icyblood198999 的回复:
你的layout是什么名字就是什么呗
是的,名字我改了,但是上面的那段代码运行还是出错了。。(⊙o⊙)…
节桃 2014-06-18
  • 打赏
  • 举报
回复
(⊙o⊙)哦 原来是layout下面的文件名字啊!!!我错了,我再试下
节桃 2014-06-18
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
setContentView(R.layout.fragment_main);
和main一样啊也是错,
哎,真难 2014-06-18
  • 打赏
  • 举报
回复
你看下你的layout,1楼是对的
icyblood198999 2014-06-18
  • 打赏
  • 举报
回复
你的layout是什么名字就是什么呗
节桃 2014-06-18
  • 打赏
  • 举报
回复

protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		TextView username=(TextView)findViewById(R.id.username);
//		username.setText(Html.fromHtml("Hello,大家好,<font color=red>我是你们的新导师</font>"));
		
		
		String userText="你知道我的名字吗";
		SpannableStringBuilder style=new SpannableStringBuilder(userText);
		style.setSpan(new ForegroundColorSpan(Color.RED), 1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		username.setText(style);
		
		
		
		
		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
		}
	}
  • 打赏
  • 举报
回复
setContentView(R.layout.fragment_main);

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧