java.lang.RuntimeException:无法启动活动并跳过帧
我正在开发一个android温度转换器应用程序(它不工作)。起初,我在LogCat上看到了这条消息 应用程序可能在其主线程上做了太多工作 然后我删除了从未使用过的代码 现在,这是错误: java.lang.RuntimeException:无法启动活动 代码:Main_Activity.java fragment_main.xml中的代码java.lang.RuntimeException:无法启动活动并跳过帧,java,android,eclipse,Java,Android,Eclipse,我正在开发一个android温度转换器应用程序(它不工作)。起初,我在LogCat上看到了这条消息 应用程序可能在其主线程上做了太多工作 然后我删除了从未使用过的代码 现在,这是错误: java.lang.RuntimeException:无法启动活动 代码:Main_Activity.java fragment_main.xml中的代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x
<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.example.tempconverter.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textCelsius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="55dp"
android:text="Celsius"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="hardcodedtext" />
<EditText
android:id="@+id/editCelsius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textCelsius"
android:layout_marginLeft="52dp"
android:layout_toRightOf="@+id/textCelsius"
android:ems="7"
android:inputType="number" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textFahrenheit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editCelsius"
android:layout_marginTop="31dp"
android:text="Fahrenheit"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="hardcodedtext" />
<Button
android:id="@+id/buttonConvert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editFahrenheit"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="Convert"
tools:ignore="hardcodedtext" />
<EditText
android:id="@+id/editFahrenheit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editCelsius"
android:layout_alignTop="@+id/textFahrenheit"
android:ems="7"
android:inputType="number" />
</RelativeLayout>
这是LogCat的一部分现在。。。
显然,你夸大了错误的观点。您有一个
RuntimeException
,您应该有一个NullPointerException
,因为setContentView
试图将错误的布局设置为(并且方法findViewById
尝试在其中查找视图):
setContentView(R.layout.activity_main);
而您所有的EditText
s、TextView
s和按钮都位于fragment\u main.xml
尝试按如下方式设置内容视图:
setContentView(R.layout.fragment_main);
或者,将fragment\u main.xml
重命名为activity\u main.xml
评论更新:
这些类型的错误“无法加载memtrack模块”发生在带有emulator的某些设备上。为了避免这种情况,请始终使用多个设备(真实或非真实)进行测试。日志猫此处不包含有用的内容,您应该在崩溃时发布日志猫(但是文本,而不是图像),您的意思是我应该选择“日志猫”verbose“而不是“errors”?检查布局上的ID是否与findViewById
方法相对应。不,我的意思是:启动应用程序,当它崩溃时,转到eclipse并粘贴到输出的位置。您是否尝试调试它?我尝试过这个:setContentView(R.layout.fragment\u main);我收到了相同的错误消息”无法加载memtrack模块“@Rsaleh您在emulator上这样做了吗?您在真实设备上试用了吗?非常感谢,我更改了“运行配置”,现在可以正常工作:”)@Rsaleh很高兴提供帮助!有时,带有某些设备的emulator会出现以下错误:“无法加载memtrack模块。”显然,这是模拟器当前的错误。若要避免,请使用多个设备(真实或非真实)进行测试。@Rsaleh感谢您接受我的答案。你尽了最大努力来解决你的问题,我只是给出了线索+1对这个,好极了!快乐编码。
setContentView(R.layout.fragment_main);