当我计算某些东西时,Android App会崩溃

时间:2016-07-28 19:12:29

标签: java android variables

我正在创建一款适用于Android的应用程序,只需点击一下,当我计算和打印并计算点数时,应用程序崩溃,我会给你错误和代码,但我找不到任何有趣的东西,所以我要求你的帮助^^

代码:

package com.example.fixe.sollsicesapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {



    int clicker = 1;
    int amount;
    int amount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AddListenerOnmb();

    }

    private void AddListenerOnmb() {
        Button button = (Button) findViewById(R.id.mb);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TextView tx = (TextView) findViewById(R.id.textView2);
                amount = clicker + amount;
                tx.setText(amoun);
            }
        });






    }


}

错误:

7-28 19:10:47.045 2700-2756/com.example.fixe.sollsicesapp I/OpenGLRenderer: Initialized EGL, version 1.4
07-28 19:10:54.083 2700-2700/com.example.fixe.sollsicesapp W/ResourceType: No package identifier when getting value for resource number 0x00000001
07-28 19:10:54.083 2700-2700/com.example.fixe.sollsicesapp D/AndroidRuntime: Shutting down VM
07-28 19:10:54.084 2700-2700/com.example.fixe.sollsicesapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.fixe.sollsicesapp, PID: 2700
                                                                             android.content.res.Resources$NotFoundException: String resource ID #0x1
                                                                                 at android.content.res.Resources.getText(Resources.java:312)
                                                                                 at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
                                                                                 at android.widget.TextView.setText(TextView.java:4417)
                                                                                 at com.example.fixe.sollsicesapp.MainActivity$1.onClick(MainActivity.java:33)
                                                                                 at android.view.View.performClick(View.java:5198)
                                                                                 at android.view.View$PerformClick.run(View.java:21147)
                                                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

阅读!

1 个答案:

答案 0 :(得分:1)

tx.setText(amount);替换为tx.setText(String.valueOf(amount));