2014-12-01 65 views
-1

我對這個有錯誤,,可惜停止機器人,我得到了錯誤不幸的是停止

package com.example.myapp; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

public class MyActivity extends Activity { 
    /** 
    * Called when the activity is first created. 
    */ 

    public int myNum = 0; 
    public TextView counterNum = (TextView) findViewById(R.id.counterNum); 
    public Button counterBtn = (Button) findViewById(R.id.counterBtn); 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     counterBtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       counterNum.setText(String.valueOf(++myNum)); 
      } 
     }); 
    } 
} 

請幫我告訴我爲什麼我得到停止。

這裏main.xml中

<?xml version="1.0" encoding="utf-8"?> 

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="0" 
     android:id="@+id/counterNum" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="68dp" 
     android:textColor="#ffffffff" 
     android:textSize="100dp" 
     android:textIsSelectable="false" 
     android:numeric="integer"/> 

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="+" 
     android:id="@+id/counterBtn" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="147dp" 
     android:textSize="45dp" 
     android:textColor="#ff0a000a" 
     android:width="100dp" 
     android:height="100dp"/> 

我logcat的

12月12日至3日:19:37.718一〇六三年至1063年/ COM。 example.myapp E/Trace:錯誤 打開跟蹤文件:No such文件或目錄(2) 12-03 12:19:38.348 1063-1063/com.example.myapp D/libEGL:loaded /system/lib/egl/libEGL_emulation.so 12-03 12:19:38.359 1063- 1063/com.example.myapp D /:HostConnection :: get()建立新的主機連接0x2a0dbe58,tid 12-03 12:19:38.399 1063-1063/com.example.myapp D/libEGL:loaded/system /lib/egl/libGLESv1_CM_emulation.so 12-03 12:19:38.409 1063-1063/com.example.myapp D/libEGL:loaded /system/lib/egl/libGLESv2_emulation.so 12-03 12:19:38.588 1063-1063/com.example.myapp W/EGL_emulation:eglSurfaceAttrib未實現 12-03 12:19:38.609 1063-1063/com.example.myapp D/OpenGLRenderer:啓用調試模式0

我正在使用IntellIJ Idea

+0

它得到了「停止」,因爲有錯誤,發佈錯誤 – tyczj 2014-12-01 15:49:47

+0

添加您的堆棧跟蹤 – 2014-12-01 15:51:01

+0

哪裏是你的logcat的? – Machado 2014-12-01 15:55:37

回答

0

字符'+'不能設置爲xml本身的文本。

設置 '+' 作爲/values/strings.xml文件中的文本如下:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="plus_sign">+</string> 
</resources> 

XML版式文件:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/plus_sign" /> 
0

在你string.xml文件,您可以設置一個不允許使用特殊字符的字符串。 嘗試在「+」之前加「\」。見下:

<resources> 
    <string name="plus_sign">\+</string> 
</resources> 

或者你可以用它編碼&#43; 請參見下面的代碼:

<resources> 
    <string name="plus_sign">&#43</string> 
</resources> 

你可以在這裏找到編碼:link

相關問題