的setContentView错误信息
当我尝试和测试我的应用我收到以下错误(S):的setContentView错误信息
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>
我将不胜感激的任何援助。谢谢!
回答:
正如LogCat所说的,您需要在MainActivity的XML文件中定义android:layout_width
参数。它应该位于您的res/layout/
文件夹中,名称为activity_main.xml
或类似名称。
回答:
你的日志说,你需要暗示布局:
Binary XML file line #21: You must supply a layout_width attribute
要做到这一点定位布局的XML文件,并添加以下行:
android:layout_width="fill_parent"
回答:
二进制XML文件中的行#21:您必须提供layout_width属性
检查第21行的main.xml
并确保该视图具有layout_width属性
以上是 的setContentView错误信息 的全部内容, 来源链接: utcz.com/qa/257402.html