当我尝试测试我的应用时,我收到以下错误:
02-16 13:05:09.251: E/AndroidRuntime(1346): FATAL EXCEPTION: main
02-16 13:05:09.251: E/AndroidRuntime(1346): Process: biz.midl.debteliminator, PID: 1346
02-16 13:05:09.251: E/AndroidRuntime(1346): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.midl.debteliminator/biz.midl.debteliminator.MainActivity}: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_width attribute.
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.os.Handler.dispatchMessage(Handler.java:102)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.os.Looper.loop(Looper.java:136)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-16 13:05:09.251: E/AndroidRuntime(1346): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 13:05:09.251: E/AndroidRuntime(1346): at java.lang.reflect.Method.invoke(Method.java:515)
02-16 13:05:09.251: E/AndroidRuntime(1346): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-16 13:05:09.251: E/AndroidRuntime(1346): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-16 13:05:09.251: E/AndroidRuntime(1346): at dalvik.system.NativeStart.main(Native Method)
02-16 13:05:09.251: E/AndroidRuntime(1346): Caused by: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_width attribute.
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:492)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5948)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6117)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1831)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1743)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:58)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.LayoutInflater.rInflate(LayoutInflater.java:757)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-16 13:05:09.251: E/AndroidRuntime(1346): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.Activity.setContentView(Activity.java:1929)
02-16 13:05:09.251: E/AndroidRuntime(1346): at biz.midl.debteliminator.MainActivity.onCreate(MainActivity.java:25)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.Activity.performCreate(Activity.java:5231)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-16 13:05:09.251: E/AndroidRuntime(1346): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
第(25)行如下:
public class MainActivity extends Activity {
double interestRate;
double r, r1;
int nRemaining, nStarting, nDifference, originalBalance,
outstandingBalance, originalTerm;
double minPayment, newPayment, newPmt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //<------Error is here
我的布局称为“主要”。
如果错误发生在这里,这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="biz.midl.debteliminator.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我将不胜感激。谢谢!
答案 0 :(得分:2)
正如LogCat所说,您需要在MainActivity的XML文件中定义android:layout_width
参数。它应位于res/layout/
文件夹中,名称为activity_main.xml
或类似名称。
答案 1 :(得分:2)
您的日志表明您需要使用以下内容进行布局:
Binary XML file line #21: You must supply a layout_width attribute
为此,找到布局的XML文件并添加以下行:
android:layout_width="fill_parent"
答案 2 :(得分:2)
二进制XML文件行#21:您必须提供layout_width属性
检查main.xml
的第21行并确保该视图具有layout_width属性