(android)Cant start activity => java.lang.RuntimeException:无法启动活动ComponentInfo

时间:2016-10-24 13:21:11

标签: android android-activity

我正在开发一个Android应用程序。但是,我有一个问题.. 每当我通过Bluestacks或Android模拟器运行我的应用程序时,我都会遇到这样的错误。它适用于我的实际手机。

java.lang.RuntimeException: Unable to start activity ComponentInfo{semo.msoft.yusearch/semo.msoft.yusearch.LoginActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>

它出现在这一行

setContentView(R.layout.activity_login);

我对此没有任何想法.. 请帮忙

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="semo.msoft.yusearch">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".LoginActivity"
        android:theme="@style/Theme.Transparent">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:theme="@style/Theme.Transparent" />
    <activity
        android:name=".FindActivity"
        android:theme="@style/Theme.YU" />
    <activity
        android:name=".TimeActivity"
        android:theme="@style/Theme.YU" />
    <activity
        android:name=".LectureActivity"
        android:theme="@style/Theme.YU" />
    <activity
        android:name=".SplashActivity"
        android:noHistory="true"
        android:theme="@style/Theme.Transparent" />
    <activity
        android:name=".ScoreActivity"
        android:theme="@style/Theme.YU" />
    <activity android:name=".MapActivity"
        android:theme="@style/Theme.YU"></activity>
</application>

</manifest>


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/login_background"
android:orientation="vertical"
tools:context="semo.msoft.yusearch.LoginActivity">


<TextView
    android:layout_marginTop="210dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:text="Member Login"
    android:textColor="#579ce1"/>

<LinearLayout
    android:layout_marginTop="8dp"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:background="@drawable/round_background"
    android:layout_gravity="center"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/icon_id"/>


    <EditText
    android:layout_width="200dp"
    android:layout_height="40dp"
    android:inputType="number"
    android:ems="10"
    android:id="@+id/id"
        android:paddingLeft="10dp"
    android:hint="학번을 입력하세요."
    android:textColorHint="#b6b1b1"
        android:background="#ffffff"
    android:textSize="15sp"
    android:textColor="@android:color/black"
    android:layout_gravity="center_horizontal" />

</LinearLayout>



<LinearLayout
    android:layout_marginTop="8dp"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:background="@drawable/round_background"
    android:layout_gravity="center"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/pw"/>


    <EditText
        android:layout_width="200dp"
        android:layout_height="40dp"
        android:inputType="textPassword"
        android:ems="20"

        android:id="@+id/pw"
        android:paddingLeft="10dp"
        android:hint="비밀번호를 입력하세요."
        android:textColorHint="#b6b1b1"
        android:textSize="15sp"
        android:textColor="@android:color/black"
        android:background="#ffffff"
        android:layout_gravity="center_horizontal" />

</LinearLayout>

<Button
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:id="@+id/login"
    android:textColor="#ffffff"
    android:textStyle="bold"
    android:text="로그인"
    android:background="@drawable/rounc_login"
    android:layout_marginTop="8dp"
    android:layout_gravity="center_horizontal"/>

</LinearLayout>

2 个答案:

答案 0 :(得分:0)

如果布局存在,那只是因为你没有将它声明到manifest.xml文件中

答案 1 :(得分:0)

我解决了。如果可绘制资源位于V21文件夹中,则在某些特定版本的设备下无法生成错误。只需将Drawable资源放入Drawable文件夹即可。