【问题标题】:ANDROID - Unable to start activity (tried different solutions but no luck)ANDROID - 无法开始活动(尝试了不同的解决方案但没有运气)
【发布时间】:2014-06-25 09:35:08
【问题描述】:

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

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 中。 布局是现有和工作布局的副本。 可能是什么问题?

谢谢!!

【问题讨论】:

  • Binary XML file line #2: You must supply a layout_width attribute. 你在 xml 文件上有一个错误,修复它,你已经删除了 xml 文件上的 layout_width,将 android:layout_width="match_parent" 添加到 xml 文件的第 2 行
  • 尝试完整阅读日志跟踪,而不仅仅是第一行。

标签: android exception


【解决方案1】:

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

android:layout_width="match_parent"

android:layout_width="wrap_content"

【讨论】:

    【解决方案2】:

    我已经尝试了所有给出的解决方案,是的 einschnaehkeee 我不仅阅读了第一行。谢谢咕噜。我已经解决了在 MANIFEST 中添加 INTENT-FILTER 的问题。我不知道为什么,但在那之后软件现在运行良好......无论如何,谢谢大家!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 2018-03-31
      • 2012-06-06
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多