【问题标题】:Android App won't launchAndroid 应用程序无法启动
【发布时间】:2014-07-03 21:48:21
【问题描述】:

我正在 Eclipse 中制作一个 android 应用程序,这是我在运行该应用程序时遇到的以下错误:

[2014-07-03 17:39:30 - LeapMotionApp] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.leapmotionapp/.MainActivity }

这是 MainActivity.java 代码:

package com.example.leapmotionapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.leapmotion.leap.*;
import com.leapmotion.leap.Gesture.State;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.println("launched");
    }
}

这里是activity_main.xml代码:

<RelativeLayout 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"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

仅提供一点背景知识,这是我第一次尝试制作 Android 应用程序,该应用程序旨在与 Leap Motion 传感器通信,当一切都说完后。如果您有任何问题,请告诉我,我们将不胜感激。

编辑: 现在收到这些错误:

[2014-07-03 18:05:02 - LeapMotionApp] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.leapmotionapp/.MainActivity }
[2014-07-03 18:05:02 - LeapMotionApp] ActivityManager: Warning: Activity not started, its current task has been brought to the front

这里也是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.leapmotionapp"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • 发布整个堆栈跟踪。
  • 它位于哪个视图下??

标签: java android eclipse


【解决方案1】:

你不应该在那里声明你的活动(在你的activity_main.xml上),如果它还没有在你的清单上声明它,应该看起来像这样

<activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

“android.intent.action.MAIN”这行表示启动你的应用时会启动这个activity,请分享你的manifest或者检查一下并寻找这行。

【讨论】:

  • 清单文件是你声明你的活动和你的整个应用程序可能使用的其他东西的地方,例如
  • 这使我的所有活动都可以使用互联网,并在某些情况下将设备从关机状态唤醒。您必须在此处声明您的所有活动。 developer.android.com/guide/topics/manifest/manifest-intro.html
  • 你能看看我上面的后续回答吗??
  • "Activity 未启动,它的当前任务已被带到最前面" 表示您尝试启动新版本时旧版本的应用仍在运行,因此没有重新安装,刚刚被带到了前面。
  • 您是否已经从布局中删除了这个? &lt;activity android:name="com.example.leapmotionapp.MainActivity" android:label="@string/app_name" &gt; &lt;/activity&gt;
【解决方案2】:

运行应用程序而不在清单中声明活动通常会导致 Eclipse 准确地告诉您。清单名为 AndroidManifest.xml,您应该可以从项目资源管理器中看到它。

【讨论】:

    【解决方案3】:

    删除这部分:

    <activity
            android:name="com.example.leapmotionapp.MainActivity"
            android:label="@string/app_name" >
    </activity> 
    

    这里是正确的:

    <RelativeLayout 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"
        tools:context=".MainActivity" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    
    </RelativeLayout>
    

    我在this issue回复了这个问题

    看看这对你有没有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 1970-01-01
      • 2016-04-21
      • 2020-12-01
      • 1970-01-01
      相关资源
      最近更新 更多