无法在手机上启动应用

时间:2015-08-03 10:49:45

标签: c# android xamarin

我为android编写了简单的应用程序,在模拟器(Xamarin)上启动它,一切正常。

但是当我在手机上发布它时(#34;不幸的是#34; app"已停止") 我的代码出了什么问题?

我的xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center_vertical">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="267.9dp"
        android:layout_gravity="center_horizontal"
        android:id="@+id/frameLayout1">
        <ImageView
            android:src="@drawable/fone"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:gravity="center"
            android:id="@+id/imageView1" />
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal"
            android:id="@+id/linearLayout1"
            android:layout_marginBottom="0.0dp">
            <ImageButton
                android:src="@drawable/menu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:id="@+id/privateButton"
                android:layout_marginRight="98.9dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@drawable/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:id="@+id/logoButton"
                android:layout_marginRight="113.7dp"
                android:background="#00000000" />
            <ImageButton
                android:src="@drawable/cart"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:id="@+id/cartButton"
                android:background="#00000000" />
        </LinearLayout>
    </FrameLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="142.7dp"
        android:layout_gravity="center_horizontal"
        android:id="@+id/linearLayout2">
        <Button
            android:text="Суші"
            android:layout_width="192.8dp"
            android:layout_height="fill_parent"
            android:gravity="center"
            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:gravity="center"
            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_gravity="center_horizontal"
        android:layout_height="142.7dp"
        android:id="@+id/linearLayout3">
        <Button
            android:text="Сети"
            android:layout_width="192.8dp"
            android:layout_height="match_parent"
            android:gravity="center"
            android:id="@+id/button3"
            android:background="@drawable/sets"
            android:textColor="#ffffff"
            android:textSize="20sp"
            android:textStyle="bold" />
        <Button
            android:text="Холодні Закуски"
            android:gravity="center"
            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="fill_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:id="@+id/linearLayout4"
        android:layout_marginLeft="0.0dp">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal"
            android:background="#f2565c"
            android:id="@+id/linearLayout5">
            <ImageButton
                android:src="@drawable/back"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:id="@+id/previousButton"
                android:layout_marginRight="143.8dp"
                android:background="#00000000"
                android:layout_marginTop="17.8dp"
                android:clickable="true"
                android:layout_marginLeft="13.8dp" />
            <ImageButton
                android:src="@drawable/home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:id="@+id/homeButton"
                android:layout_marginRight="143.8dp"
                android:background="#00000000"
                android:layout_marginTop="13.6dp"
                android:clickable="true" />
            <ImageButton
                android:src="@drawable/next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:id="@+id/nextButton"
                android:layout_marginLeft="0.0dp"
                android:background="#00000000"
                android:layout_marginTop="17.8dp"
                android:clickable="true" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
&#13;
&#13;
&#13;

我的主要活动:

&#13;
&#13;
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", Theme = "@android:style/Theme.Black.NoTitleBar")]
    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);
            ImageButton next = FindViewById<ImageButton>(Resource.Id.nextButton);
            ImageButton previous = FindViewById<ImageButton>(Resource.Id.previousButton);
            ImageButton home = FindViewById<ImageButton>(Resource.Id.homeButton);

            next.Click += delegate
            {
                var intent = new Intent(this, typeof(MenuActivity));
                StartActivity(intent);
            };
            // 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++); };


        }
    }
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您是否在Android手机上启用了USB调试模式?