添加布局后的CSipSimple运行时异常

时间:2014-11-21 06:14:39

标签: java android android-layout layout

我正在尝试添加一个新的活动,一旦你启动CSipSimple就会执行,但是一旦我添加了布局,应用程序就会停止工作。

我设法成功下载并构建CSipSimple,但现在只要我添加新布局(即使根本没有代码更改),应用程序会抛出以下异常:

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.csipsimple/com.csipsimple.ui.SipHome}: java.lang.NullPointerException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
    at android.app.ActivityThread.access$1500(ActivityThread.java:122)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4025)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NullPointerException
    at com.csipsimple.ui.SipHome$TabsAdapter.<init>(SipHome.java:303)
    at com.csipsimple.ui.SipHome.onCreate(SipHome.java:239)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
    ... 11 more

引发异常的代码是:

public TabsAdapter(FragmentActivity activity, ActionBar actionBar, ViewPager pager) 
{
    super(activity.getSupportFragmentManager());
    mContext = activity;
    mActionBar = actionBar;
    mViewPager = pager;
    mViewPager.setAdapter(this);  // Exception thrown in this line
    mViewPager.setOnPageChangeListener(this);
}

并且该函数的调用者是:

mTabsAdapter = new TabsAdapter(this, getSupportActionBar(), mViewPager);

请注意,只要我删除布局xml,此代码就可以正常工作

一旦我删除布局xml,应用程序运行正常。我手动添加布局可能我错过了什么?我应该用新布局的名称修改任何其他android xml吗?

新布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Enter your account number"
    android:id="@+id/lbl1"
    android:textSize="@dimen/abs__action_bar_default_height" />

    <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="10"
    android:id="@+id/account_id"
    android:layout_gravity="center_horizontal"
    android:textSize="@dimen/abs__action_bar_default_height" />

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Create Account"
    android:id="@+id/button"
    android:layout_gravity="center_horizontal"
    android:textSize="@dimen/abs__action_bar_default_height"
    android:onClick="createAccount" />
</LinearLayout>

任何帮助将不胜感激......

0 个答案:

没有答案