安卓应用力,只要它打开关闭 [英] Android: Application force closing as soon as it opens

查看:160
本文介绍了安卓应用力,只要它打开关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Android摆弄周围Netbeans和做了一个简单的数学应用程序。某处应用突然发力,只要打开它(在模拟器上)关闭的方式......我想评论的所有code在承载主要活动类,但无济于事。因为它没有给我一个特定的错误消息,我有种丢失。

任何原因,为什么会这样?

下面是请求的布局文件:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    < TextView的机器人:ID =@ + ID /结果
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=/>
        <的LinearLayout机器人:方向=横向
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT>    <的TextView的android:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=@字符串/数字/>
    < EditText上机器人:ID =@ + ID / N
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_weight =1
                        机器人:数字=十进制/>
                <按钮机器人:ID =@ + ID /钙
                  机器人:文字=@字符串/计算
                        机器人:layout_width =WRAP_CONTENT
                        机器人:layout_height =WRAP_CONTENT/>
    < / LinearLayout中>
< / LinearLayout中>

的建议我检查logcat的,这是错误列表

  E / AndroidRuntime(881):未捕获的处理程序:螺纹主力退出,由于未捕获的异常
E / AndroidRuntime(881):了java.lang.RuntimeException:无法实例活动ComponentInfo {org.me.mathdroid / org.me.mathdroid.MainActivity}:显示java.lang.NullPointerException
E / AndroidRuntime(881):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
E / AndroidRuntime(881):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E / AndroidRuntime(881):在android.app.ActivityThread.access $ 2100(ActivityThread.java:116)
E / AndroidRuntime(881):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1794)
E / AndroidRuntime(881):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(881):在android.os.Looper.loop(Looper.java:123)
E / AndroidRuntime(881):在android.app.ActivityThread.main(ActivityThread.java:4203)
E / AndroidRuntime(881):在java.lang.reflect.Method.invokeNative(NativeMethod)
E / AndroidRuntime(881):在java.lang.reflect.Method.invoke(Method.java:521)
E / AndroidRuntime(881):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:791)
E / AndroidRuntime(881):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E / AndroidRuntime(881):在dalvik.system.NativeStart.main(本机方法)E / AndroidRuntime(881):显示java.lang.NullPointerException:产生的原因
E / AndroidRuntime(881):在android.app.Activity.findViewById(Activity.java:1610)
E / AndroidRuntime(881):在org.me.mathdroid.MainActivity<&初始化GT;(MainActivity.java:22)。
E / AndroidRuntime(881):在java.lang.Class.newInstanceImpl(本机方法)
E / AndroidRuntime(881):在java.lang.Class.newInstance(Class.java:1472)
E / AndroidRuntime(881):在android.app.Instrumentation.newActivity(Instrumentation.java:1097)
E / AndroidRuntime(881):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
E / AndroidRuntime(881):11 ...更多


解决方案

我想通了什么问题了,在主要活动我设置一个EditText和TextView的与R类的那些对象,之前设置的内容查看。很抱歉的麻烦。

I'm tinkering around with android on Netbeans and did a simple math application. Somewhere along the way the application suddenly force closes as soon as it opens(On the emulator)... I tried commenting all the code in the class that hosts the main activity but to no avail. Since it doesn't give me a specific error message, I feel kind of lost.

Any reason why this is happening?

Here is the layout file as requested:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView  android:id="@+id/result"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text=""/>
        <LinearLayout android:orientation="horizontal"
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content">

    	<TextView android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:text="@string/number" />
    	<EditText android:id="@+id/n"
    	  android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:layout_weight="1"
                        android:numeric="decimal"/>
                <Button android:id="@+id/calc"
                  android:text="@string/calculate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />
    </LinearLayout>
</LinearLayout>

As suggested I checked logcat and this is the list of errors

E/AndroidRuntime(  881): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  881): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.me.mathdroid/org.me.mathdroid.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(  881):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
E/AndroidRuntime(  881):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime(  881):        at android.app.ActivityThread.access$2100(ActivityThread.java:116)
E/AndroidRuntime(  881):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
E/AndroidRuntime(  881):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  881):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  881):        at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime(  881):        at java.lang.reflect.Method.invokeNative(NativeMethod)
E/AndroidRuntime(  881):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  881):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime(  881):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime(  881):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(  881): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  881):        at android.app.Activity.findViewById(Activity.java:1610)
E/AndroidRuntime(  881):        at org.me.mathdroid.MainActivity.<init>(MainActivity.java:22)
E/AndroidRuntime(  881):        at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(  881):        at java.lang.Class.newInstance(Class.java:1472)
E/AndroidRuntime(  881):        at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
E/AndroidRuntime(  881):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
E/AndroidRuntime(  881):        ... 11 more

解决方案

I have figured out what the problem was, in the main activity I was setting an Edittext and TextView objects with the ones in the R class, before setting the contentView. Sorry for the trouble.

这篇关于安卓应用力,只要它打开关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆