2016-07-28 134 views
-6

我創建了一個android的應用程序,一個小點擊者喜歡,當我計算和打印和使數學的點數,應用程序崩潰,我要給你的錯誤和代碼,但我無法找到任何東西在裏面有趣的,所以我要問你的幫助^^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) 

THK閱讀!

+1

不要張貼這樣的代碼,而包括其在後。你有兩次聲明'int amount; int amount;'變量,以及輸入'tx.setText(amoun);'你最後缺少't'。 – Vucko

回答

1

更換tx.setText(amount);tx.setText(String.valueOf(amount));

+1

是的,這也是。由於他傳遞了一個int,所以被誤認爲資源ID :) – Vucko