2017-10-14 67 views
1

我有问题。当我点击按钮,应用程序而不是去列表的其他页面,应用程序崩溃。我已尝试添加任务以获得更好的性能,但错误依然存在。我不知道那个代码有什么问题。对我来说这应该没问题。Xamarin该应用程序可能在其主线程上做了太多工作Android

编辑:我有更改正在等待Navigation.PushAsync(new SrchPage());但仍然不起作用。下面我得到了这些错误。

第一个错误:

应用程序可以做它的主线程的Android太多的工作

第二个错误:

UNHANDLED EXCEPTION: 
10-15 10:13:46.781 I/MonoDroid(27288): 
Xamarin.Forms.Xaml.XamlParseException: No embeddedresource found for 
Ap.SrchPage 
10-15 10:13:46.781 I/MonoDroid(27288): at 
Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.Type 
callingType) [0x0000f] in 
C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\XamlLoader.cs:67 
10-15 10:13:46.781 I/MonoDroid(27288): at 
Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.Type 
callingType) [0x00000] in 
C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Xaml\ViewExtensions.cs:36 
10-15 10:13:46.781 I/MonoDroid(27288): at Ap.SrchPage.InitializeComponent 
() [0x00001] in Z:\mem\Ap\Ap\Ap\obj\Debug\Ap.Klasy.SrchPage.xaml.g.cs:22 
10-15 10:13:46.781 I/MonoDroid(27288): at Ap.SrchPage..ctor() [0x00008] in 
Z:\mem\Ap\Ap\Ap\Klasy\SrchPage.xaml.cs:19 
10-15 10:13:46.781 I/MonoDroid(27288): at Ap.MainPage+ 
<Button_Clicked_1>d__6.MoveNext() [0x0000f] in 
Z:\mem\Ap\Ap\Ap\MainPage.xaml.cs:110 
10-15 10:13:46.781 I/MonoDroid(27288): --- End of stack trace from previous 
location where exception was thrown --- 
10-15 10:13:46.781 I/MonoDroid(27288): at 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in 
<183b200ee49746d48fc781625979428e>:0 
10-15 10:13:46.781 I/MonoDroid(27288): at 
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c. 
<ThrowAsync>b__6_0 (System.Object state) [0x00000] in 
<183b200ee49746d48fc781625979428e>:0 
10-15 10:13:46.781 I/MonoDroid(27288): at Android.App.SyncContext+ 
<>c__DisplayClass2_0.<Post>b__0() [0x00000] in 
<71828dd8fb5f4508815e23d6996c45c2>:0 
10-15 10:13:46.781 I/MonoDroid(27288): at 
Java.Lang.Thread+RunnableImplementor.Run() [0x00008] in 
<71828dd8fb5f4508815e23d6996c45c2>:0 
10-15 10:13:46.781 I/MonoDroid(27288): at Java.Lang.IRunnableInvoker.n_Run 
(System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in 
<71828dd8fb5f4508815e23d6996c45c2>:0 
10-15 10:13:46.781 I/MonoDroid(27288): at (wrapper dynamic-method) 
System.Object:a8baa1c1-4db1-4761-95e4-cc368e19ffe1 (intptr,intptr) 
10-15 10:13:46.801 W/art  (27288): JNI RegisterNativeMethods: attempt to 
register 0 native methods for android.runtime.JavaProxyThrowable 

页与清单:

public SrchPage() 
{ 
    InitializeComponent(); 
    Task.Factory.StartNew(() => Zrob());  
} 

    private void Zrob() 
    { 
     Task.Factory.StartNew(() => 
     { 
     ListaNazw.ItemsSource = new List<Listyy> 
      { 
      new Listyy { nazwa = "tekst", opis="tekst" , ema = 1 }, 
      new Listyy { nazwa = "tekst", opis = "tekst", ema = 2 }, 
      new Listyy { nazwa = "tekst", opis = "tekst", ema = 3 }, 
      new Listyy { nazwa = "tekst", opis = "tekst", ema = 4 }, 
      }; 
     }); 
    } 

async private void ListaNazw_ItemSelected(object sender, SelectedItemChangedEventArgs e) 
{ 
    if (e.SelectedItem == null) 
       return; 

    var klik = e.SelectedItem as Listyy; 
    await Navigation.PushAsync(new AfterSearch(klik)); 
    ListaNazw.SelectedItem = null; 
} 

按钮:

async private void Button_Clicked_1(object sender, EventArgs e) 
{ 
    await Navigation.PushAsync(new SrchPage()); 
} 

XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="Ap.SrchPage " 
     BackgroundImage="@drawable/main2_rc3.png" 
     NavigationPage.HasNavigationBar="False"> 


<RelativeLayout> 
    <ListView x:Name="ListaNazw" SeparatorColor="#3d122c" HasUnevenRows="True" 
       RelativeLayout.HeightConstraint="{ConstraintExpression Property=Height,Factor=1,Type=RelativeToParent}" 
       RelativeLayout.WidthConstraint="{ConstraintExpression Property=Width,Factor=1,Type=RelativeToParent}" ItemSelected="ListaNazw_ItemSelected" > 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <StackLayout Orientation="Horizontal" Padding="5" BackgroundColor="#90FFFFFF"> 
         <StackLayout HorizontalOptions="StartAndExpand"> 
          <Label Text="{Binding nazwa}" TextColor="#680345" FontSize="17"/> 
          <Label Text="{Binding opis}" TextColor="#30032a" /> 
         </StackLayout> 
        </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
</RelativeLayout> 
</ContentPage> 
+0

请参阅我的博客诊断此一般警告消息:https://blog.xamarin.com/tips-for-creating-a-smooth-and-fluid-android-ui/ –

回答

1

在您的Xaml x:class有更多的空间。

x:Class="Ap.SrchPage "

删除多余的空间,清理生成,删除所有bin和obj文件夹。然后重新重建。

+0

谢谢!我没看见 –

0

使用此,你的代码将正常工作。

await Navigation.PushModalAsync(new SrchPage()); 
+0

仍然不工作 –

相关问题