4

我已经为启动演示制作了一个简单的 android,其中有两个活动,但是在启动屏幕程序停止运行后...请帮帮我..

我的代码:

飞溅.java

package com.esp.therisemethod.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.esp.therisemethod.R;
import com.esp.therisemethod.util.Log;

public class SplashActivity extends Activity {

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

        Thread splashThread = new Thread() {
            public void run() {
                try {
                    sleep(2000);
                } catch (InterruptedException e) {
                    Log.error(this.getClass() + "::: OnCreate Thread :::", e);
                }

                Intent intent = null;
                intent = new Intent(SplashActivity.this, Registration.class);
                startActivity(intent);
                finish();
            }
        };
        splashThread.start();

    }

}

注册.java

package com.esp.therisemethod.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.esp.therisemethod.R;
import com.esp.therisemethod.uc.Header;

public class Registration extends Activity implements OnClickListener{
    Button bt_login,bt_Reg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_registration);
        bt_login =(Button)findViewById(R.id.bt_login);
        bt_Reg=(Button)findViewById(R.id.bt_reg);


    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.bt_login:

            break;

        case R.id.bt_reg:

            break;
        }
    }

}

日志猫

06-26 06:09:22.635: E/Trace(2371): error opening trace file: No such file or directory (2)
06-26 06:09:23.055: D/dalvikvm(2371): GC_FOR_ALLOC freed 34K, 7% free 2408K/2588K, paused 45ms, total 51ms
06-26 06:09:23.096: I/dalvikvm-heap(2371): Grow heap (frag case) to 5.264MB for 2908176-byte allocation
06-26 06:09:23.155: D/dalvikvm(2371): GC_FOR_ALLOC freed 1K, 4% free 5247K/5432K, paused 50ms, total 50ms
06-26 06:09:23.225: D/dalvikvm(2371): GC_CONCURRENT freed <1K, 4% free 5246K/5432K, paused 9ms+15ms, total 74ms
06-26 06:09:23.597: D/dalvikvm(2371): GC_FOR_ALLOC freed <1K, 4% free 5246K/5432K, paused 30ms, total 30ms
06-26 06:09:23.615: I/dalvikvm-heap(2371): Grow heap (frag case) to 6.497MB for 1292972-byte allocation
06-26 06:09:23.755: D/dalvikvm(2371): GC_CONCURRENT freed 0K, 3% free 6509K/6696K, paused 74ms+15ms, total 142ms
06-26 06:09:24.025: D/gralloc_goldfish(2371): Emulator without GPU emulation detected.
06-26 06:09:26.375: D/AndroidRuntime(2371): Shutting down VM
06-26 06:09:26.395: W/dalvikvm(2371): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-26 06:09:26.905: E/AndroidRuntime(2371): FATAL EXCEPTION: main
06-26 06:09:26.905: E/AndroidRuntime(2371): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.esp.therisemethod/com.esp.therisemethod.ui.Registration}: android.view.InflateException: Binary XML file line #7: Error inflating class com.esp.therisemethod.uc.Header
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.os.Looper.loop(Looper.java:137)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at java.lang.reflect.Method.invokeNative(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at java.lang.reflect.Method.invoke(Method.java:511)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at dalvik.system.NativeStart.main(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.esp.therisemethod.uc.Header
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.Activity.setContentView(Activity.java:1881)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.esp.therisemethod.ui.Registration.onCreate(Registration.java:19)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.Activity.performCreate(Activity.java:5104)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-26 06:09:26.905: E/AndroidRuntime(2371):     ... 11 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: java.lang.reflect.InvocationTargetException
06-26 06:09:26.905: E/AndroidRuntime(2371):     at java.lang.reflect.Constructor.constructNative(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-26 06:09:26.905: E/AndroidRuntime(2371):     ... 22 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class com.esp.therisemethod.uc.EspTextView
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.esp.therisemethod.uc.Header.<init>(Header.java:21)
06-26 06:09:26.905: E/AndroidRuntime(2371):     ... 25 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: java.lang.reflect.InvocationTargetException
06-26 06:09:26.905: E/AndroidRuntime(2371):     at java.lang.reflect.Constructor.constructNative(Native Method)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-26 06:09:26.905: E/AndroidRuntime(2371):     ... 31 more
06-26 06:09:26.905: E/AndroidRuntime(2371): Caused by: java.lang.RuntimeException: native typeface cannot be made
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.graphics.Typeface.<init>(Typeface.java:175)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.graphics.Typeface.createFromAsset(Typeface.java:149)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.esp.therisemethod.util.Utils.getFont(Utils.java:389)
06-26 06:09:26.905: E/AndroidRuntime(2371):     at com.esp.therisemethod.uc.EspTextView.<init>(EspTextView.java:23)
06-26 06:09:26.905: E/AndroidRuntime(2371):     ... 34 more

请帮助我...谢谢提前

4

8 回答 8

5

使用它作为你的 SplashActivity ......它适用于我的情况

public class SplashActivity extends Activity {
    Intent intent;

    //Called when activity if first called
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.splash_screen);

         intent = new Intent(this, HomeActivity.class);
        Handler handler = new Handler();

        handler.postDelayed(new Runnable() {
            public void run() {

                startActivity(intent);
                finish();
            }
        }, 2000);

    }
于 2013-06-26T06:15:46.150 回答
3

尽管我非常不鼓励您当前启动屏幕的设置,但要使其在第一个活动中工作,请执行以下操作

new Handler().postDelayed(new Runnable() {
            public void run() {
                Intent  intent = new Intent(SplashActivity.this, Registration.class);
                startActivity(intent);
                finish();
            }
        },2000);
于 2013-06-26T06:13:50.777 回答
3

根据您的 logcat,它说您的 xml 文件中发生了错误.. 只需查看该特定行号上的 xml 文件..

Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.esp.therisemethod.uc.Header
06-26 06:09:26.905: E/AndroidRuntime(2371):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
于 2013-06-26T06:20:41.320 回答
2

将 Intent 置于线程外,如下所示:

 Thread splashThread = new Thread() {
        public void run() {
            try {
                sleep(2000);
            } catch (InterruptedException e) {
                Log.error(this.getClass() + "::: OnCreate Thread :::", e);
            }

        }
    };
    splashThread.start();
     Intent intent = null;
            intent = new Intent(SplashActivity.this, Registration.class);
            startActivity(intent);
            finish();
于 2013-06-26T06:15:30.853 回答
2

您的日志的以下行表明您正在膨胀的 xml 文件中存在一些错误。请调查一下。

06-26 06:09:26.905: E/AndroidRuntime(2371): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.esp.therisemethod/com.esp.therisemethod.ui.Registration}:    
android.view.InflateException: Binary XML file line #7: Error inflating class 
com.esp.therisemethod.uc.Header
于 2013-06-26T06:19:05.527 回答
2

你有没有在android清单文件中添加你的registration.java文件。如果没有,则将此代码添加到清单文件中

<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
    android:name=".SplashActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity> 
<activity
    android:name=".Registration"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar" >

</activity> 
</application>
于 2013-06-26T06:32:45.480 回答
1

你也可以试试这个方法。。

splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    synchronized (this) {
                        // wait 2 sec
                        wait(2000);
                    }
                } catch (InterruptedException e) {
                    // Exception handling
                } finally {
                    finish();
                    // start a new activity
                    Intent i = new Intent(SplashActivity.this, Registration.class);                     
                    startActivity(i);
                    // stop();
                }
            }
        };
于 2013-06-26T06:55:55.320 回答
1

看到这个

Thread mythread = new Thread() {
            public void run() {
                try {

                    sleep(5000);

                } catch (Exception e) {
                } finally {
                    Intent intent = new Intent(Splash.this,
                            next.class);
                    startActivity(intent);
                    finish();
                }
            }
        };
        mythread.start();
于 2013-10-29T10:24:08.103 回答