ANDROID - 无法启动活动(尝试了不同的解决方案,但没有运气)

时间:2014-06-25 09:35:09

标签: android exception

我收到此异常启动此活动:

06-25 11:25:05.111      991-991/com.armadillo.sh5 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.armadillo.sh5/com.armadillo.sh5.NoAccountPage}: java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
            at android.app.ActivityThread.access$600(ActivityThread.java:122)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4340)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.
            at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
            at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5297)
            at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5418)
            at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1776)
            at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1700)
            at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:56)
            at android.view.LayoutInflater.parseInclude(LayoutInflater.java:815)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
            at android.app.Activity.setContentView(Activity.java:1835)
            at com.armadillo.sh5.NoAccountPage.onCreate(NoAccountPage.java:30)
            at android.app.Activity.performCreate(Activity.java:4465)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
            at android.app.ActivityThread.access$600(ActivityThread.java:122)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4340)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)

我已尝试(如其他解决方案中所述)清除项目但没有任何反应。页面的代码非常简单:

public class NoAccountPage extends Activity {

    private boolean doubleBackToExitPressedOnce;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Rimuovo la barra del titolo
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        // Impedisco al layout di girarsi se giro il device
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        // Carico il layout
        setContentView(R.layout.no_account_page);

        // ##########################
        // ##  Gestione dei Fonts  ##
        // ##########################

        TextView textSlab = (TextView) findViewById(R.id.SlabText);
        Typeface fontSlab = Typeface.createFromAsset(getAssets(), "fonts/RobotoSlab-Regular.ttf");
        textSlab.setTypeface(fontSlab);
        TextView textCondensed = (TextView) findViewById(R.id.CondensedText);
        Typeface fontCondensed = Typeface.createFromAsset(getAssets(), "fonts/RobotoCondensed-Regular.ttf");
        textCondensed.setTypeface(fontCondensed);
    }

    // Abilito l'uscita dall'app in caso di DOUBLE-BACK

    @Override
    public void onBackPressed() {
        if(doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }

        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this, getString(R.string.pressTwiceToExit), Toast.LENGTH_SHORT).show();
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                doubleBackToExitPressedOnce = false;
            }
        }, 2000);

    }
}

该文件的声明出现在MANIFEST中。 布局是现有和工作布局的重复。 可能是什么问题?

谢谢!

2 个答案:

答案 0 :(得分:0)

显示此错误是因为您错过了布局no_account_page.xml上的set layout_width。

android:layout_width="match_parent"

android:layout_width="wrap_content"

答案 1 :(得分:0)

我已经尝试了所有给出的解决方案,是的,einschnaehkeee我不仅阅读了第一行。谢谢GULU。我已经解决了添加MANIFEST的INTENT-FILTER。我不知道为什么,但在那之后软件现在很好......谢谢你们!