Есть код:
using Android.App;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V4.App;
using Android.Support.V4.View;
using Android.Support.V7.App;
using Java.Lang;
using uSteam.Fragments;
using Fragment = Android.Support.V4.App.Fragment;
using FragmentManager = Android.Support.V4.App.FragmentManager;
namespace uSteam
{
[Activity(Label = "uSteam", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
this.SetSupportActionBar(toolbar);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
var tabs = FindViewById<TabLayout>(Resource.Id.tabs);
var viewpager = FindViewById<ViewPager>(Resource.Id.viewpager);
viewpager.Adapter = new ViewPagerAdapter(SupportFragmentManager);
tabs.SetupWithViewPager(viewpager);
}
class ViewPagerAdapter : FragmentPagerAdapter
{
private readonly (string Name, Fragment Fragment)[] fragments = {
("Home", new MenuFragment()),
("Store", new MenuFragment()),
("Chat", new MenuFragment()),
};
public ViewPagerAdapter(FragmentManager manager) : base(manager)
{
}
public override int Count => fragments.Length;
public override Fragment GetItem(int position) => fragments[position].Fragment;
public override ICharSequence GetPageTitleFormatted(int position) => new String(fragments[position].Name);
}
}
}
и AXML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
На 21 строке (
SetContentView(Resource.Layout.Main);
) возникает исключение
Java.Lang.NullPointerException: <Timeout exceeded getting exception details>
Upd:
Если добавить try/catch, то у исключения появляется StackTrace:
Java.Lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <657aa8fea4454dc898a9e5f379c58734>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <54816278eed9488eb28d3597fecd78f8>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <54816278eed9488eb28d3597fecd78f8>:0
at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <28e323a707a2414f8b493f6d4bb27c8d>:0
at uSteam.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0000a] in E:\Projects\uSteam\uSteam\MainActivity.cs:24
--- End of managed Java.Lang.NullPointerException stack trace ---
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setId(int)' on a null object reference
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:502)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at md50813b0b565de9342220184bf4ab3bda4.MainActivity.n_onCreate(Native Method)
at md50813b0b565de9342220184bf4ab3bda4.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:6675)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2732)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2844)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6361)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)