setContentView(R.layout.main);报错

qq_38773160 2020-12-18 11:36:33


这两个地方老师报错
res/menu/main.xml 是这里错误吗

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.xys.MainActivity" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
android:showAsAction="never"/>
<imageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>

</menu>
...全文
15078 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
无厘头编程 2020-12-19
  • 打赏
  • 举报
回复
那么 Logcat 说啥?应该有 Error, NPE, Language error。
qq_38773160 2020-12-19
  • 打赏
  • 举报
回复
qq_38773160 2020-12-18
  • 打赏
  • 举报
回复
改成setContentView(R.layout.activity_main); 报错没有了,可以已运行就闪退 layout/activity_main/xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.xys.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
<ImageView
         android:id="@+id/imageID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"/>
</RelativeLayout>

JMSissi 2020-12-18
  • 打赏
  • 举报
回复
加载layout中的布局文件 而不是菜单的布局文件

80,469

社区成员

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

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