c# - 无法启动应用程序

标签 c# android xamarin

当我启动我的应用程序时,我会看到:“不幸的是,应用程序名称 已停止。”和这个“引起:java.lang.RuntimeException:二进制 XML 文件第 1 行:您必须提供 layout_width 属性。”

我的 axml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="25px"
    android:minHeight="25px">
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="210.9dp"
        android:id="@+id/frameLayout1">
        <ImageView
            android:src="@drawable/fone"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:id="@+id/imageView1" />
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:id="@+id/linearLayout1"
            android:layout_marginBottom="0.0dp">
            <ImageButton
                android:src="@android:drawable/ic_menu_gallery"
                android:layout_width="49.0dp"
                android:layout_height="50.8dp"
                android:id="@+id/privateButton"
                android:layout_marginRight="98.9dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@drawable/logo"
                android:layout_width="75.3dp"
                android:layout_height="64.1dp"
                android:id="@+id/logoButton"
                android:layout_marginRight="113.7dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@android:drawable/ic_menu_gallery"
                android:layout_width="49.0dp"
                android:layout_height="50.8dp"
                android:id="@+id/cartButton"
                android:background="#00000000" />
        </LinearLayout>
        <LinearLayout />
    </FrameLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="142.7dp"
        android:id="@+id/linearLayout2">
        <Button
            android:text="Суші"
            android:layout_width="192.8dp"
            android:layout_height="fill_parent"
            android:id="@+id/button1"
            android:background="@drawable/sushi"
            android:textColor="#ffffff"
            android:textSize="20sp"
            android:textStyle="bold" />
        <Button
            android:text="Роли"
            android:layout_width="192.8dp"
            android:layout_height="fill_parent"
            android:id="@+id/button2"
            android:background="@drawable/rolli"
            android:textColor="#ffffff"
            android:textSize="20sp"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="142.7dp"
        android:id="@+id/linearLayout3">
        <Button
            android:text="Сети"
            android:layout_width="192.8dp"
            android:layout_height="match_parent"
            android:id="@+id/button3"
            android:background="@drawable/sets"
            android:textColor="#ffffff"
            android:textSize="20sp"
            android:textStyle="bold" />
        <Button
            android:text="Холодні Закуски"
            android:layout_width="192.8dp"
            android:layout_height="match_parent"
            android:id="@+id/button4"
            android:background="@drawable/holodni"
            android:textColor="#ffffff"
            android:textSize="20sp"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="60.2dp"
        android:id="@+id/linearLayout4"
        android:layout_marginLeft="0.0dp">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:background="#f2565c"
            android:id="@+id/linearLayout5">
            <ImageButton
                android:src="@drawable/back"
                android:layout_width="49.0dp"
                android:layout_height="50.8dp"
                android:id="@+id/previousButton"
                android:layout_marginRight="113.9dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@drawable/home"
                android:layout_width="49.0dp"
                android:layout_height="50.8dp"
                android:id="@+id/homeButton"
                android:layout_marginRight="113.9dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@drawable/next"
                android:layout_width="49.0dp"
                android:layout_height="50.8dp"
                android:id="@+id/nextButton"
                android:layout_marginLeft="0.0dp"
                android:background="#00000000" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

我的主要 Activity :

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Murakami
{
    [Activity(Label = "Murakami", MainLauncher = true, Icon = "@drawable/logo")]
    public class MainActivity : Activity
    {
       // int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            //Button button = FindViewById<Button>(Resource.Id.MyButton);
            //button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
            
            
        }
    }
}

最佳答案

问题出在您的 xml 文件上。

         ...
            <ImageButton
                android:src="@drawable/logo"
                android:layout_width="75.3dp"
                android:layout_height="64.1dp"
                android:id="@+id/logoButton"
                android:layout_marginRight="113.7dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@android:drawable/ic_menu_gallery"
                android:layout_width="49.0dp"
                android:layout_height="50.8dp"
                android:id="@+id/cartButton"
                android:background="#00000000" />
        </LinearLayout>
        <LinearLayout />  // this line is not required. DELETE this line.

你创建了一个新的 LinearLayout 但没有给它任何属性。我认为它是偶然的。

希望对您有所帮助。

关于c# - 无法启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774427/

相关文章:

android - 为什么我在cordova上打开软键盘时有白色区域?

ios - 拦截ios后退按钮发送回基本 View Controller

c# - 无法使SQL Server Compact 3.5/4与ASP .NET MVC 2一起使用

c# - LINQ-所有条件

android - 如何在 LinearLayout 中将 imageButons 居中并在其下方设置 textView?

android - Stripe 不再支持在 Xamarin Android 中使用 TLS 1.0 发出的 API 请求?

ios - 当我使用 MvxSimpleTableViewSource 时,xamarin ios Tableview 没有重新加载

c# - 在 C# 中使用 ToString() 格式化数字以具有尾随零

c# - 电话号码标准化 : Any pre-existing libraries?

java - 当用户禁用 GPS 时如何在 MapActivity 上收到警报