我正在使用Jdeveloper 11.1.2.4.0来创建splashscreen ..我已经按照http://www.androidaspect.com/2012/12/android-splash-screen-tutorial.html中所述的每个步骤进行了
但我仍然无法解决问题。
这是我的splash.java(主要活动)
package mobile;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class Splash extends Activity {
private long ms=0;
private long splashTime=2000;
private boolean splashActive = true;
private boolean paused=false;
/**
* @param savedInstanceState
*/
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Hides the titlebar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.Splash);
Thread mythread = new Thread() {
public void run() {
try {
while (splashActive && ms < splashTime) {
if(!paused)
ms=ms+100;
sleep(100);
}
} catch(Exception e) {}
finally {
Intent intent;
intent = new Intent(Splash.this, Home.class);
startActivity(intent);
}
}
};
mythread.start();
}
}
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.splash_screen">
<uses-sdk/>
<application android:icon="@drawable/adfmf_icon"
android:label="@string/app_name" android:name="oracle.adfmf.Application">
<activity android:screenOrientation="fullSensor" android:name=".Splash" android:noHistory="true" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation" android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Home"
android:label="@string/title_activity_home" >
</activity>
<activity android:name="oracle.adfmf.AMXActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="oracle.adfmf.RemoteURLActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="oracle.adfmf.LocalHTMLActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="oracle.adfmf.phonegap.AdfSpringboardPhoneGapActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="oracle.adfmf.SettingsActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="oracle.adfmf.navbar.MoreTabActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<activity android:name="oracle.adfmf.BlankActivity" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="adjustPan"></activity>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.company.splash_screen" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission android:name="com.company.splash_screen.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.splash_screen.permission.C2D_MESSAGE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
在res / layout /文件夹中,我有splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/background" />
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:layout_gravity="center_horizontal" >
</ProgressBar>
</LinearLayout>
和home.xml(第二个活动)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dip"
android:text="HomeScreen"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
在两个.java文件(splash.java&amp; home.java)中,错误显示在setContentView(R.layout.Splash);和setContentView(R.layout.Home); RESP ...
答案 0 :(得分:4)
您的R.java
文件未正确生成。
清理项目并重新构建。
项目 - &gt;清洁强>
如果这不能解决问题,检查XML文件中的错误。 XML文件中的错误会阻止R.java的生成。
一旦确定一切正确,您可以清理项目并重新构建它。
或者您可以手动删除 R.java
,然后 构建 项目,这将再次重新生成R.java
注意:从不使用 import android.r
,即使您看到eclipse提示它。
答案 1 :(得分:0)
你输入它,
将此内容放入导入
import (Your package Name ex:com.android.user).R
并确保你在(Project-&gt; gen&gt; projectname-&gt; R.java)中有R.java文件,如果你不去(右键单击项目 - &gt; android工具 - &gt;修复项目属性。)