java - Android 应用程序无法在设备上启动

标签 java android eclipse android-intent emulation

我是一名初学者 Android 开发人员,我编写了一个基本 Activity,用于加载图像、等待 5 秒并打开包含 TextView 的主 Activity。没有错误并且编译得很好。但当我在我的设备上启动时,它无法打开。 (也无法在模拟器上打开)。 我不知道这是为什么。

这是 list :

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

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

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

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.gui.Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.SPLASH" />

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

</manifest>

这是我打算首先加载的 Splash Activity 。

package com.example.gui;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class Splash extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread splash_thread = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch(InterruptedException e)
            { e.printStackTrace();
        }finally{ Intent splash_intent = new      Intent("android.intent.action.MAIN");
            startActivity(splash_intent);
    }
}
};
splash_thread.start(); 

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

}

这是我打算运行的其他 Activity :

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }


}

我正在遵循互联网上的教程,但由于某种原因它仍然无法运行。我的布局也非常标准。帮助将不胜感激。

最佳答案

您可以在manifest.xml文件中设置错误的路径。

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

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name="com.example.gui.MainActivity"
    android:label="@string/app_name" >

试试这个,现在你的闪屏首先启动,主要 Activity 将启动... 如果它不起作用,那么仅当您的 Activity 没有响应时才尝试此代码。

  public class Splash_screen extends Activity {
 private static String TAG = Splash_screen.class.getName();
 private static long SLEEP_TIME = 3;    // Sleep for some time
  @Override
   protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
  this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
  this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,       WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar
  setContentView(R.layout.splash_screen);
  IntentLauncher launcher = new IntentLauncher();
  launcher.start();
}
private class IntentLauncher extends Thread{
  @Override
  /**
   * Sleep for some time and than start new activity.
   */
  public void run() {
     try {
        // Sleeping
        Thread.sleep(SLEEP_TIME*1000);
     } catch (Exception e) {
        Log.e(TAG, e.getMessage());
     }

     // Start main activity
     Intent intent = new Intent(Splash_screen.this,Login_screen.class);
     startActivity(intent);
     finish();
  }
}

关于java - Android 应用程序无法在设备上启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902981/

相关文章:

java - 关于spring容器热切单例设计模式

java - 仅当外部类参数化时内部接口(interface)才会生成错误?为什么?

java - JDOM 解析模式

java - 从数字列表中生成所有唯一对,n 选择 2

java - 如何正确地将 jars 组织到 Eclipse 中的一个文件夹中?

javascript - 使用 React-Native 推送通知

android - 使用 NDK 构建时在 OpenCV/nonfree/features2d 中未定义

android - 通知的振动和声音默认设置

eclipse - Spring STS 找不到 META-INF/spring.schemas

c# - Eclipse IDE - 支持 Microsoft .NET Framework 的 C# 插件