有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在安卓中添加启动屏幕时出现java错误

我是安卓开发新手,我正在尝试在我的应用程序中添加一个启动屏幕。 我找到了这个tutorial:

我已经添加了教程中提到的文件,但似乎不起作用,我的Splashscreen.java文件中有一个错误

它给我的错误是无法解析符号安卓mkab

谢谢你提前帮忙

飞溅屏幕。java

package com.myapplication;

import 安卓.os.Bundle;
import 安卓.app.Activity;
import 安卓.content.Intent;
import 安卓.widget.ImageView;

import com.安卓mkab.randomsplash.MainActivity;

import java.util.Random;


public class Splashscreen extends Activity {

    Thread splashTread;
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);
        imageView = (ImageView)findViewById(R.id.imageView2);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        int[] ids = new int[]{R.drawable.s_img,R.drawable.s_image_black, R.drawable.s_image_black2};
        Random randomGenerator = new Random();
        int r= randomGenerator.nextInt(ids.length);
        this.imageView.setImageDrawable(getResources().getDrawable(ids[r]));

        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    // Splash screen pause time
                    while (waited < 3500) {
                        sleep(100);
                        waited += 100;
                    }
                    Intent intent = new Intent(Splashscreen.this,
                            MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(intent);
                    Splashscreen.this.finish();
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    Splashscreen.this.finish();
                }

            }
        };
        splashTread.start();
    }

}

活动\u飞溅。xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="fill_parent"
    安卓:layout_height="fill_parent"
    安卓:background="#ffffff"
    安卓:layout_gravity="center"
    安卓:id="@+id/lin_lay"
    安卓:gravity="center"
    安卓:orientation="vertical" >

    <ImageView
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:id="@+id/splash"
        安卓:background="@drawable/logo" />

</LinearLayout>

AndroidManifest。xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    package="com.myapplication">

    <application
        安卓:allowBackup="true"
        安卓:icon="@mipmap/ic_launcher"
        安卓:label="@string/app_name"
        安卓:roundIcon="@mipmap/ic_launcher_round"
        安卓:supportsRtl="true"
        安卓:theme="@style/AppTheme">
        <activity 安卓:name=".Splashscreen"
            安卓:label="@string/app_name">
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            安卓:name=".MainActivity"
            安卓:label="@string/app_name"
            安卓:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

共 (3) 个答案

  1. # 1 楼答案

    问题似乎是您正在尝试调用项目中不存在的包androidmkab.randomsplash.MainActivity应替换为您的项目包。例如com.myApplication.MainActivity

  2. # 2 楼答案

    删除行com.androidmkab.randomsplash.MainActivity;并写入com.myapplication.MainActivity;

  3. # 3 楼答案

    import com.androidmkab.randomsplash.MainActivity;top中删除此行。这不是你的包裹。。。改为import com.myapplication.MainActivity