【问题标题】:Android app working on AVD but not on the phone?Android 应用程序可以在 AVD 上运行,但不能在手机上运行?
【发布时间】:2014-04-01 11:13:54
【问题描述】:

我创建了一个简单的应用程序,它只包含三个按钮(物理、数学、关于我们)。在物理和数学按钮后面,我插入了许多公式的图像。在 aboutus 按钮中,只有文字。当我在 AVD 2.3.3 上运行我的应用程序时,它运行得非常好。但是当我尝试在各种不同的安卓手机上运行它时,它会启动,但是当我点击任何物理或数学按钮时,应用程序会关闭并显示“不幸的是公式查找器已停止”(其中公式查找器是我的应用程序名称)。我把我的代码放在下面:

  1. 我的 Physics.xml 文件如下所示

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:contentDescription="@string/imageView1"
            android:src="@drawable/one1" />
    
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@+id/imageView1"
            android:contentDescription="@string/imageView2"
            android:src="@drawable/one2" />
    
        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:layout_below="@+id/imageView2"
            android:contentDescription="@string/imageView3"
            android:src="@drawable/one3" />
    
        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:layout_below="@+id/imageView3"
            android:contentDescription="@string/imageView4"
            android:src="@drawable/one4" />
    
        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView4"
            android:contentDescription="@string/imageView5"
            android:src="@drawable/one5" />
    
        <ImageView
            android:id="@+id/imageView6"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@+id/imageView5"
            android:contentDescription="@string/imageView6"
            android:src="@drawable/one6" />
    
        <ImageView
            android:id="@+id/imageView7"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView6"
            android:contentDescription="@string/imageView7"
            android:src="@drawable/one7" />
    
        <ImageView
            android:id="@+id/imageView8"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView7"
            android:contentDescription="@string/imageView8"
            android:src="@drawable/one8" />
    
        <ImageView
            android:id="@+id/imageView9"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_below="@+id/imageView8"
            android:contentDescription="@string/imageView9"
            android:src="@drawable/one9" />
    
        <ImageView
            android:id="@+id/imageView10"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView9"
            android:contentDescription="@string/imageView10"
            android:src="@drawable/one10" />
    
        <ImageView
            android:id="@+id/imageView11"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView10"
            android:contentDescription="@string/imageView11"
            android:src="@drawable/one11" />
    
        <ImageView
            android:id="@+id/imageView12"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView11"
            android:contentDescription="@string/imageView12"
            android:src="@drawable/one12" />
    
        <ImageView
            android:id="@+id/imageView13"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_below="@+id/imageView12"
            android:contentDescription="@string/imageView13"
            android:src="@drawable/one13" />
    </RelativeLayout>
    

  2. 我的 maths.xml 看起来像这样

        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
         <ImageView
            android:id="@+id/imageViewm1"
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:contentDescription="@string/imageViewm1"
            android:src="@drawable/math1" />
    
          <ImageView
            android:id="@+id/imageViewm2"
            android:layout_width="match_parent"
            android:layout_height="290dp"
            android:layout_below="@+id/imageViewm1"
            android:contentDescription="@string/imageViewm2"
            android:src="@drawable/math2" />
    
           <ImageView
            android:id="@+id/imageViewm3"
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:layout_below="@+id/imageViewm2"
            android:contentDescription="@string/imageViewm3"
            android:src="@drawable/math3" />
    
            <ImageView
            android:id="@+id/imageViewm4"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_below="@+id/imageViewm3"
            android:contentDescription="@string/imageViewm4"
            android:src="@drawable/math4" />
    
             <ImageView
            android:id="@+id/imageViewm5"
            android:layout_width="match_parent"
            android:layout_height="220dp"
            android:layout_below="@+id/imageViewm4"
            android:contentDescription="@string/imageViewm5"
            android:src="@drawable/math5" />
    
              <ImageView
            android:id="@+id/imageViewm6"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_below="@+id/imageViewm5"
            android:contentDescription="@string/imageViewm6"
            android:src="@drawable/math6" />
    
    
    
    
    </RelativeLayout>
    

  3. 我的 activity_main.xml 看起来像这样

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/button_physics_text" />
    
    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/button_maths_text" />
    
    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="@string/about_us" />
    

  4. 我的 android_manifest.xml 看起来像这样:

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcherfinal"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test2.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.test2.Physics"
            android:label="@string/title_activity_sub" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.test2.Maths"
            android:label="@string/title_activity_maths" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.test2.Aboutus"
            android:label="@string/title_activity_aboutus" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
    

我忘记提及的另一件事是,当我添加图像时,它给了我一个错误,例如“未处理的事件循环异常”和“头部大小超出”。很抱歉没有早点提及

【问题讨论】:

  • 您已将启动器分配给多个活动。仅将其提供给您要首先启动的人。请参阅下面的答案。
  • 清单中没有定义多个启动器。发布 logcat 将有助于调查问题。
  • 我无法添加 logcat 文件。它说字符大小限制为 30000。当我添加 logcat 时,它超出了限制
  • 尽可能多地粘贴 logcat

标签: java android xml eclipse android-imageview


【解决方案1】:

更改清单文件-

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcherfinal"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test2.MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.test2.Physics"
        android:label="@string/title_activity_sub" >
    </activity>
    <activity
        android:name="com.example.test2.Maths"
        android:label="@string/title_activity_maths" >
    </activity>
    <activity
        android:name="com.example.test2.Aboutus"
        android:label="@string/title_activity_aboutus" >
    </activity>
</application>

希望对您有所帮助。

【讨论】:

  • 我试过这个但没有帮助,同样的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多