cherrywong2
cherrywong2
2017-10-04 04:30
采纳率: 0%
浏览 1.1k

Android小白,请各位大佬帮忙看看什么问题,一个关于摄氏华氏转换的小小小程序

做一个摄氏华氏转换的时候,在模拟器上运行有这样的问题
java程序
public class MainActivity extends ActionBarActivity {

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

}
public void button1_click(View view){
int c;
double f;
EditText txtc=(EditText) findViewById(R.id.txtc);
EditText txtf=(EditText) findViewById(R.id.txtf);
c=Integer.parseInt(txtc.getText().toString());
f=(9.0*c)/5.0+32.0;
txtf.setText(String.valueOf(f));
}
}

xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ftoc.MainActivity" >

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/c" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equals"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/f" />


android:id="@+id/txtc"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="number"/>
android:id="@+id/button1"
android:text="@string/shift"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="button1_Click"/>
android:id="@+id/txtf"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>

log猫
10-04 03:31:06.777: E/AndroidRuntime(913): at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
10-04 03:31:06.777: E/AndroidRuntime(913): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
10-04 03:31:06.777: E/AndroidRuntime(913): at com.example.ftoc.MainActivity.onCreate(MainActivity.java:16)
10-04 03:31:06.777: E/AndroidRuntime(913): at android.app.Activity.performCreate(Activity.java:5933)
10-04 03:31:06.777: E/AndroidRuntime(913): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
10-04 03:31:06.777: E/AndroidRuntime(913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
10-04 03:31:06.777: E/AndroidRuntime(913): ... 10 more
10-04 03:31:10.772: I/Process(913): Sending signal. PID: 913 SIG: 9
10-04 04:06:59.931: D/AndroidRuntime(1228): Shutting down VM
10-04 04:06:59.936: E/AndroidRuntime(1228): FATAL EXCEPTION: main
10-04 04:06:59.936: E/AndroidRuntime(1228): Process: com.example.ftoc, PID: 1228
10-04 04:06:59.936: E/AndroidRuntime(1228): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ftoc/com.example.ftoc.MainActivity}: java.lang.RuntimeException: Binary XML file line #10: You must supply a layout_width attribute.
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.access$800(ActivityThread.java:144)
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.os.Handler.dispatchMessage(Handler.java:102)
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.os.Looper.loop(Looper.java:135)
10-04 04:06:59.936: E/AndroidRuntime(1228): at android.app.ActivityThread.main(ActivityThread.java:5221)
10-04 04:06:59.936: E/AndroidRuntime(1228): at java.lang.reflect.Method.invoke(Native Method)
10-04 04:06:59.936: E/AndroidRuntime(1228): at java.lang.reflect.Method.invoke(Method.java:372)
10-04 04:06:59.936: E/AndroidRuntime(1228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
10-04 04:06:59.936: E/AndroidRuntime(1228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
。。。。。。。。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • caozhy
    点赞 评论
  • skyunicorn
    小麟 2017-10-06 08:14

    你贴的xml代码全不全?为什么都没有声明是什么控件?

    点赞 评论
  • YXTS122
    YXTS122 2017-10-25 04:32

    我运行一下看看。。。。

    点赞 评论
  • YXTS122
    YXTS122 2017-10-26 03:46
     public class MainActivity extends Activity {
        EditText txtc;
        EditText txtf;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            txtc=(EditText) findViewById(R.id.txtc);
            txtf=(EditText) findViewById(R.id.txtf);
        }
        public void button1_click(View view){
            int c;
            double f;
            c=Integer.parseInt(txtc.getText().toString());
            f=(9.0*c)/5.0+32.0;
            txtf.setText(String.valueOf(f));
            }}
    
    

    图片说明

    点赞 评论

相关推荐