遗憾的是<applicationname>已停止</applicationname>

时间:2014-05-28 23:51:50

标签: java android android-emulator crash

所以我不知道这里关于双重帖子的规则是什么,我在其他问题上没有得到任何后续支持..任何我的问题都说明了,继承我的logcat

05-28 19:45:03.464: I/ActivityManager(274): Start proc xela.kasea.flyffresell for activity xela.kasea.flyffresell/.Main: pid=793 uid=10046 gids={50046, 1028}
05-28 19:45:03.474: D/dalvikvm(793): Not late-enabling CheckJNI (already on)
05-28 19:45:04.154: I/ARMAssembler(36): generated scanline__00000077:03010104_00008001_00000000 [ 89 ipp] (110 ins) at [0x41548840:0x415489f8] in 564149 ns
05-28 19:45:04.294: D/dalvikvm(793): GC_FOR_ALLOC freed 81K, 6% free 2642K/2784K, paused 26ms, total 27ms
05-28 19:45:04.294: I/dalvikvm-heap(793): Grow heap (frag case) to 3.318MB for 714016-byte allocation
05-28 19:45:04.334: D/dalvikvm(793): GC_FOR_ALLOC freed 2K, 5% free 3337K/3484K, paused 34ms, total 34ms
05-28 19:45:04.414: I/Tag2(793): This is my error msg
05-28 19:45:04.414: D/AndroidRuntime(793): Shutting down VM
05-28 19:45:04.414: W/dalvikvm(793): threadid=1: thread exiting with uncaught exception (group=0x41465700)
05-28 19:45:04.425: E/AndroidRuntime(793): FATAL EXCEPTION: main
05-28 19:45:04.425: E/AndroidRuntime(793): java.lang.RuntimeException: Unable to start activity ComponentInfo{xela.kasea.flyffresell/xela.kasea.flyffresell.Main}: java.lang.NullPointerException
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.os.Looper.loop(Looper.java:137)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.ActivityThread.main(ActivityThread.java:5103)
05-28 19:45:04.425: E/AndroidRuntime(793):  at java.lang.reflect.Method.invokeNative(Native Method)
05-28 19:45:04.425: E/AndroidRuntime(793):  at java.lang.reflect.Method.invoke(Method.java:525)
05-28 19:45:04.425: E/AndroidRuntime(793):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-28 19:45:04.425: E/AndroidRuntime(793):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-28 19:45:04.425: E/AndroidRuntime(793):  at dalvik.system.NativeStart.main(Native Method)
05-28 19:45:04.425: E/AndroidRuntime(793): Caused by: java.lang.NullPointerException
05-28 19:45:04.425: E/AndroidRuntime(793):  at xela.kasea.flyffresell.Main.onCreate(Main.java:31)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.Activity.performCreate(Activity.java:5133)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-28 19:45:04.425: E/AndroidRuntime(793):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
05-28 19:45:04.425: E/AndroidRuntime(793):  ... 11 more
05-28 19:45:04.433: W/ActivityManager(274):   Force finishing activity xela.kasea.flyffresell/.Main
05-28 19:45:04.743: I/WindowManager(274): Screenshot max retries 4 of Token{41792b40 ActivityRecord{418a4ce0 u0 xela.kasea.flyffresell/.Main}} appWin=Window{41943b50 u0 Starting xela.kasea.flyffresell} drawState=4
05-28 19:45:04.743: W/WindowManager(274): Screenshot failure taking screenshot for (400x800) to layer 21010
05-28 19:45:05.133: D/AlertService(580): Beginning updateAlertNotification
05-28 19:45:05.214: D/AlertService(580): No fired or scheduled alerts
05-28 19:45:05.263: W/ActivityManager(274): Activity pause timeout for ActivityRecord{418a4ce0 u0 xela.kasea.flyffresell/.Main}
05-28 19:45:05.593: D/AlertService(580): Scheduling next alarm with AlarmScheduler. sEventReminderReceived: null
05-28 19:45:05.853: D/AlarmScheduler(580): No events found starting within 1 week.
05-28 19:45:06.503: I/Process(793): Sending signal. PID: 793 SIG: 9
05-28 19:45:06.513: I/ActivityManager(274): Process xela.kasea.flyffresell (pid 793) has died.

并且继承我的main.java。注意:我只使用一个班级。

package xela.kasea.flyffresell;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class Main extends Activity implements OnClickListener{

    EditText perin, amountPrUnit, buy, sell;
    ToggleButton lazy;
    Button clear, submit, ret;
    double ans, subAnswer;
    TextView pEarned, tAmount;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display);
        Log.i("Tag2", "This is my error msg");
        initalizer();
        lazy.setOnClickListener(this);
        clear.setOnClickListener(this);
        submit.setOnClickListener(this);
        ret.setOnClickListener(this);
        /*String a = perin.getText().toString();
        String b = amountPrUnit.getText().toString();
        String c = buy.getText().toString();
        String d = sell.getText().toString(); */
    }

    private void initalizer() {
        // TODO Auto-generated method stub
        perin = (EditText) findViewById(R.id.etHowRich);
        amountPrUnit =  (EditText) findViewById(R.id.etAmountPrUnit);
        buy = (EditText) findViewById(R.id.etBuying);
        sell = (EditText) findViewById(R.id.etSellingPrUnit);
        lazy = (ToggleButton) findViewById(R.id.tbBuying);
        clear = (Button) findViewById(R.id.bClear);
        submit = (Button) findViewById(R.id.bSubmit);
        ret = (Button) findViewById(R.id.bReturn);
        pEarned = (TextView) findViewById(R.id.tvEarned);
        tAmount = (TextView) findViewById(R.id.tvAmount);
        /*int a = Integer.parseInt(perin.getText().toString());
        int b = Integer.parseInt(amountPrUnit.getText().toString());
        int c = Integer.parseInt(buy.getText().toString());
        int d = Integer.parseInt(sell.getText().toString());*/
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        int a = Integer.parseInt(perin.getText().toString());
        int b = Integer.parseInt(amountPrUnit.getText().toString());
        int c = Integer.parseInt(buy.getText().toString());
        int d = Integer.parseInt(sell.getText().toString());
        switch(v.getId()){
        case R.id.bClear:
            perin.setText("");
            amountPrUnit.setText("");
            buy.setText("");
            sell.setText("");
            lazy.setChecked(false);
            break;
        case R.id.bReturn:
            setContentView(R.layout.display);
            break;
        case R.id.bSubmit:
            pEarned.setText(c*d-(a-(b*c)));
            tAmount.setText(c*d+(a-(a-(b*c))));
            setContentView(R.layout.finish);
            break;
        case R.id.tbBuying:
            if (lazy.isChecked()){
            buy.setText("");
            double subAnswer = 0;
            int ans = 0;
            subAnswer = a/b;
            ans = (int) Math.floor(subAnswer);
            /*new Integer((int) ans).toString();
            Integer.toString(answer);*/
            buy.setText(ans);;
            }
            break;
        }
    }
}

这个应用程序要做的是,用几个用户输入的数字并用它们做一些数学运算。

如果你需要它,那就是清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xela.kasea.flyffresell"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

3 个答案:

答案 0 :(得分:1)

我认为用户的这个评论需要一个答案来解释Java中null的基本主题:

  

如果我可以问,是什么NullPointerException?

null指针意味着您正在尝试操作没有分配任何内存的Object变量。 NullPointerException是Java告诉你的方式:&#34;嘿,你试图操纵的变量(即设置一个监听器)指的是没有内存位置;没有为此变量实例化Object,或者它已经被垃圾收集了。你正试图去使用尚未建成的建筑的浴室。&#34;

堆栈跟踪很好(你应该和他成为朋友)并告诉我们代码的哪一行Exception被抛出:

05-28 19:45:04.425: E/AndroidRuntime(793): Caused by: java.lang.NullPointerException 
05-28 19:45:04.425: E/AndroidRuntime(793):  at xela.kasea.flyffresell.Main.onCreate(Main.java:31)

这意味着您需要检查该行代码并确定哪个变量为null。大多数现代IDE都可以选择引入断点,允许您在运行时查看变量的状态。一旦知道哪个变量为null,您就可以更轻松地找出原因。因此,在您的情况下,导致问题的行是Main.java的第31行。从评论我们知道你说的那条线是:

ret.setOnClickListender(this);

这给我们留下了一个选择; ret必须为null。然后我们问自己:

  

在正常情况下会发生什么情况可能会导致null

1)变量未初始化;我们忘了初始化它。不是我们的情况。

2)收集了变量。不是我们的情况。

3)当我们尝试初始化变量时出错了。可能是我们的情况。

在这种情况下,我们不会通过调用某个类的构造函数来初始化变量,我们通过一个方法(即findViewById())来完成。此方法需要intid应该是我们要设置View的{​​{1}},并且它返回ret或{{1}问题。所以,如果正确地想到这一点,那么错误可能就是我们使用了错误的id。

这个答案更多的是展示思维模式而不是实际解决方案,因为实际上没有足够的信息来解决问题。

答案 1 :(得分:0)

检查您的logs行中是否有NullPointerException xela.kasea.flyffresell.Main.onCreate(Main.java:31)

可能是其中一个按钮clear, submit, ret, lazy可能是null

答案 2 :(得分:0)

根据您的错误消息:

05-28 19:45:04.425: E/AndroidRuntime(793): Caused by: java.lang.NullPointerException
05-28 19:45:04.425: E/AndroidRuntime(793):  at xela.kasea.flyffresell.Main.onCreate(Main.java:31)

问题必须是布局中的按钮“bReturn

 ret = (Button) findViewById(R.id.bReturn);

可能不存在。

更新:我发现了问题,为什么在单击bReturn按钮时再次加载内容视图?:

case R.id.bReturn:
        setContentView(R.layout.display);