我刚刚在线观看教程后完成了一个Android应用程序。我导出它并使用BlueStacks进行测试,它运行正常。问题是,当我尝试在我的平板电脑上运行它时,我得到一个(应用程序已关闭)错误,但应用程序仍然启动。我可以听到介绍声音,但我的布局的背景不显示。请帮忙!
这是最简单的代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thebasics"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/app_name" >
<!-- .Splash = locatia si numele -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.thebasics.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialOne"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.thebasics.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
这是SPLASH.java代码:
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer muzica;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
MediaPlayer muzica = MediaPlayer.create(Splash.this, R.raw.sfx_die);
muzica.start();
Thread logoTimer = new Thread(){
public void run(){
try{
sleep(2000); //2000 = 2 sec
Intent splashIntent = new Intent("com.example.thebasics.MAINACTIVITY");
startActivity(splashIntent); //porneste activitatea
}
catch (InterruptedException e) {
e.printStackTrace();
}
finally{
finish(); //termina activitatea
}
}
};
logoTimer.start(); //porneste THREADUL
}
protected void onPause() {
super.onPause();
muzica.release(); //pune suntetul pe pauza
}
}
This is the code fore the 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"
android:background="@drawable/background" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/tutorial1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/tutorial2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
这是菜单代码:
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu extends Activity {
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
//Button Sound
final MediaPlayer sunetButton = MediaPlayer.create(Menu.this,
R.raw.button_click);
//BUTTON1
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
sunetButton.start();
startActivity(new Intent("com.example.thebasics.TUTORIALONE"));
}
});
//BUTTON2
Button tut2 = (Button) findViewById(R.id.tutorial2);
tut2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
sunetButton.start();
startActivity(new Intent("com.example.thebasics.TUTORIALONE"));
}
});
}
protected void onPause(){
super.onPause();
}
}
logcat的:
build.board: grouper
build.bootloader: 4.23
build.brand: google
build.cpu_abi: armeabi-v7a
build.cpu_abi2: armeabi
build.device: grouper
build.display: KOT49H
build.fingerprint: google/nakasi/grouper:4.4.2/KOT49H/937116:user/release-keys
build.hardware: grouper
build.host: kpfi7.cbf.corp.google.com
build.id: KOT49H
build.manufacturer: asus
build.model: Nexus 7
build.product: nakasi
build.radio: unknown
build.serial: 015d46d970580011
build.tags: release-keys
build.time: 1386200268000
build.type: user
build.user: android-build
version.codename: REL
version.incremental: 937116
version.release: 4.4.2
version.sdk_int: 19
--------- beginning of /dev/log/main
03-05 01:46:20.770 I/dalvikvm(27811): Enabling JNI app bug workarounds for target SDK version 10...
03-05 01:46:21.160 D/dalvikvm(27811): GC_CONCURRENT freed 123K, 2% free 7973K/8132K, paused 4ms+3ms, total 31ms
03-05 01:46:21.230 W/ProcessManager(27811): waitpid on failed exec failed: No child processes
03-05 01:46:21.230 W/m (27811): Cannot obtain root
03-05 01:46:21.230 W/m (27811): java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: null
03-05 01:46:21.230 W/m (27811): at java.lang.ProcessManager.exec(ProcessManager.java:211)
03-05 01:46:21.230 W/m (27811): at java.lang.Runtime.exec(Runtime.java:173)
03-05 01:46:21.230 W/m (27811): at java.lang.Runtime.exec(Runtime.java:246)
03-05 01:46:21.230 W/m (27811): at java.lang.Runtime.exec(Runtime.java:189)
03-05 01:46:21.230 W/m (27811): at com.nolanlawson.logcat.b.m.a(Unknown Source)
03-05 01:46:21.230 W/m (27811): at com.nolanlawson.logcat.b.w.a(Unknown Source)
03-05 01:46:21.230 W/m (27811): at com.nolanlawson.logcat.b.p.b(Unknown Source)
03-05 01:46:21.230 W/m (27811): at com.nolanlawson.logcat.d.doInBackground(Unknown Source)
03-05 01:46:21.230 W/m (27811): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-05 01:46:21.230 W/m (27811): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-05 01:46:21.230 W/m (27811): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-05 01:46:21.230 W/m (27811): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-05 01:46:21.230 W/m (27811): at java.lang.Thread.run(Thread.java:841)
03-05 01:46:21.230 W/m (27811): Caused by: java.io.IOException: Permission denied
03-05 01:46:21.230 W/m (27811): at java.lang.ProcessManager.exec(Native Method)
03-05 01:46:21.230 W/m (27811): at java.lang.ProcessManager.exec(ProcessManager.java:209)
03-05 01:46:21.230 W/m (27811): ... 12 more
03-05 01:46:21.860 D/dalvikvm(27811): GC_CONCURRENT freed 131K, 2% free 8353K/8520K, paused 3ms+2ms, total 24ms
03-05 01:46:21.860 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 5ms
03-05 01:46:21.860 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 5ms
03-05 01:46:21.890 I/Choreographer(27811): Skipped 37 frames! The application may be doing too much work on its main thread.
03-05 01:46:22.410 D/dalvikvm(27811): GC_CONCURRENT freed 62K, 2% free 8699K/8796K, paused 3ms+5ms, total 29ms
03-05 01:46:35.990 D/dalvikvm(27811): GC_CONCURRENT freed 137K, 3% free 9018K/9204K, paused 3ms+3ms, total 20ms
03-05 01:46:35.990 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 16ms
03-05 01:46:36.020 D/dalvikvm(27811): GC_FOR_ALLOC freed 446K, 7% free 8898K/9540K, paused 16ms, total 16ms
03-05 01:46:36.030 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 8980K/9540K, paused 15ms, total 15ms
03-05 01:46:36.030 I/dalvikvm-heap(27811): Grow heap (frag case) to 8.881MB for 83216-byte allocation
03-05 01:46:36.050 D/dalvikvm(27811): GC_FOR_ALLOC freed 0K, 6% free 9061K/9624K, paused 15ms, total 15ms
03-05 01:46:36.060 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9062K/9624K, paused 15ms, total 15ms
03-05 01:46:36.060 I/dalvikvm-heap(27811): Grow heap (frag case) to 8.961MB for 83216-byte allocation
03-05 01:46:36.080 D/dalvikvm(27811): GC_FOR_ALLOC freed 0K, 6% free 9143K/9708K, paused 15ms, total 15ms
03-05 01:46:36.090 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9145K/9708K, paused 14ms, total 14ms
03-05 01:46:36.100 I/dalvikvm-heap(27811): Grow heap (frag case) to 9.042MB for 83216-byte allocation
03-05 01:46:36.110 D/dalvikvm(27811): GC_FOR_ALLOC freed 0K, 6% free 9226K/9792K, paused 16ms, total 16ms
03-05 01:46:36.130 D/dalvikvm(27811): GC_FOR_ALLOC freed 1K, 6% free 9228K/9792K, paused 17ms, total 18ms
03-05 01:46:36.130 I/dalvikvm-heap(27811): Grow heap (frag case) to 9.124MB for 83216-byte allocation
03-05 01:46:36.150 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9309K/9876K, paused 18ms, total 18ms
03-05 01:46:36.170 D/dalvikvm(27811): GC_FOR_ALLOC freed 1K, 6% free 9310K/9876K, paused 17ms, total 17ms
03-05 01:46:36.170 I/dalvikvm-heap(27811): Grow heap (frag case) to 9.204MB for 83216-byte allocation
03-05 01:46:36.190 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9391K/9960K, paused 18ms, total 18ms
03-05 01:46:36.200 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9392K/9960K, paused 15ms, total 15ms
03-05 01:46:36.200 I/dalvikvm-heap(27811): Grow heap (frag case) to 9.284MB for 83216-byte allocation
03-05 01:46:36.220 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9473K/10044K, paused 15ms, total 15ms
03-05 01:46:36.240 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9476K/10044K, paused 16ms, total 16ms
03-05 01:46:36.240 I/dalvikvm-heap(27811): Grow heap (frag case) to 9.366MB for 83216-byte allocation
03-05 01:46:36.250 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9557K/10128K, paused 16ms, total 16ms
03-05 01:46:36.270 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9638K/10212K, paused 16ms, total 16ms
03-05 01:46:36.290 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9719K/10296K, paused 15ms, total 15ms
03-05 01:46:36.310 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 9803K/10380K, paused 15ms, total 15ms
03-05 01:46:36.320 D/dalvikvm(27811): GC_FOR_ALLOC freed 1K, 6% free 9967K/10548K, paused 15ms, total 15ms
03-05 01:46:36.340 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 10130K/10716K, paused 15ms, total 15ms
03-05 01:46:36.360 D/dalvikvm(27811): GC_FOR_ALLOC freed <1K, 6% free 10374K/10968K, paused 15ms, total 15ms
03-05 01:46:37.660 D/dalvikvm(27811): GC_FOR_ALLOC freed 118K, 3% free 10997K/11304K, paused 17ms, total 17ms
03-05 01:46:37.680 D/dalvikvm(27811): GC_FOR_ALLOC freed 39K, 4% free 11760K/12128K, paused 17ms, total 17ms
03-05 01:46:56.920 D/dalvikvm(27811): GC_FOR_ALLOC freed 609K, 6% free 12313K/13084K, paused 18ms, total 18ms
03-05 01:46:56.950 D/dalvikvm(27811): GC_FOR_ALLOC freed 363K, 8% free 12729K/13720K, paused 16ms, total 16ms
03-05 01:46:56.980 D/dalvikvm(27811): GC_FOR_ALLOC freed 488K, 7% free 13380K/14356K, paused 17ms, total 17ms
03-05 01:46:57.080 D/dalvikvm(27811): GC_FOR_ALLOC freed 574K, 8% free 14084K/15204K, paused 17ms, total 17ms
03-05 01:46:57.480 D/dalvikvm(27811): GC_FOR_ALLOC freed 1199K, 11% free 14352K/16084K, paused 18ms, total 18ms
03-05 01:46:58.720 D/dalvikvm(27811): GC_FOR_ALLOC freed 679K, 8% free 15203K/16448K, paused 18ms, total 18ms
03-05 01:47:00.580 D/dalvikvm(27811): GC_FOR_ALLOC freed 679K, 10% free 16055K/17752K, paused 17ms, total 17ms
03-05 01:47:00.800 D/dalvikvm(27811): GC_FOR_ALLOC freed 1276K, 13% free 16464K/18752K, paused 17ms, total 17ms
03-05 01:47:12.220 D/dalvikvm(27811): GC_FOR_ALLOC freed 1972K, 17% free 16287K/19420K, paused 20ms, total 20ms
03-05 01:47:12.870 D/dalvikvm(27811): GC_FOR_ALLOC freed 1505K, 15% free 16525K/19420K, paused 19ms, total 19ms
03-05 01:47:20.890 D/dalvikvm(27811): GC_FOR_ALLOC freed 4341K, 28% free 14128K/19420K, paused 20ms, total 21ms
03-05 01:47:20.930 D/dalvikvm(27811): GC_CONCURRENT freed 27K, 17% free 16229K/19420K, paused 2ms+2ms, total 24ms
03-05 01:47:20.930 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 15ms
03-05 01:47:23.820 D/dalvikvm(27811): GC_CONCURRENT freed 3543K, 21% free 15505K/19420K, paused 2ms+3ms, total 25ms
03-05 01:47:23.820 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 21ms
03-05 01:47:25.540 D/dalvikvm(27811): GC_CONCURRENT freed 5621K, 37% free 12390K/19420K, paused 2ms+4ms, total 29ms
03-05 01:47:49.080 D/dalvikvm(27811): GC_CONCURRENT freed 3709K, 43% free 10216K/17620K, paused 2ms+4ms, total 35ms
03-05 01:47:49.080 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 28ms
03-05 01:47:49.120 D/dalvikvm(27811): GC_CONCURRENT freed 51K, 38% free 10981K/17620K, paused 4ms+4ms, total 32ms
03-05 01:47:49.120 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 25ms
03-05 01:47:49.170 D/dalvikvm(27811): GC_CONCURRENT freed <1K, 32% free 12040K/17620K, paused 3ms+2ms, total 26ms
03-05 01:47:49.170 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 21ms
03-05 01:48:21.010 D/dalvikvm(27811): GC_CONCURRENT freed 3552K, 44% free 9877K/17460K, paused 2ms+3ms, total 24ms
03-05 01:48:21.010 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 21ms
03-05 01:48:21.050 D/dalvikvm(27811): GC_CONCURRENT freed 18K, 40% free 10593K/17460K, paused 2ms+3ms, total 24ms
03-05 01:48:21.050 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 19ms
03-05 01:48:21.090 D/dalvikvm(27811): GC_CONCURRENT freed <1K, 34% free 11570K/17460K, paused 3ms+3ms, total 26ms
03-05 01:48:21.090 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 20ms
03-05 01:48:24.540 D/dalvikvm(27811): GC_CONCURRENT freed 60K, 28% free 12728K/17460K, paused 3ms+5ms, total 38ms
03-05 01:48:58.820 D/dalvikvm(27811): GC_CONCURRENT freed 3631K, 39% free 10711K/17380K, paused 3ms+3ms, total 29ms
03-05 01:48:58.820 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 20ms
03-05 01:48:58.860 D/dalvikvm(27811): GC_CONCURRENT freed 36K, 33% free 11652K/17380K, paused 6ms+4ms, total 29ms
03-05 01:48:58.860 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 23ms
03-05 01:48:58.900 D/dalvikvm(27811): GC_CONCURRENT freed <1K, 26% free 12954K/17380K, paused 5ms+5ms, total 28ms
03-05 01:48:58.900 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 23ms
03-05 01:49:07.380 D/dalvikvm(27811): GC_CONCURRENT freed 159K, 12% free 14554K/16404K, paused 3ms+4ms, total 28ms
03-05 01:49:07.380 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 22ms
03-05 01:50:25.970 W/IInputConnectionWrapper(27811): showStatusIcon on inactive InputConnection
03-05 01:50:33.470 D/dalvikvm(27811): GC_FOR_ALLOC freed 4015K, 25% free 12699K/16824K, paused 24ms, total 24ms
03-05 01:50:33.520 D/dalvikvm(27811): GC_CONCURRENT freed 149K, 16% free 14179K/16824K, paused 4ms+3ms, total 26ms
03-05 01:50:33.520 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 18ms
03-05 01:50:40.530 W/IInputConnectionWrapper(27811): showStatusIcon on inactive InputConnection
03-05 01:50:50.550 D/dalvikvm(27811): GC_FOR_ALLOC freed 3602K, 26% free 12582K/16808K, paused 21ms, total 22ms
03-05 01:50:50.600 D/dalvikvm(27811): GC_CONCURRENT freed 31K, 16% free 14179K/16808K, paused 2ms+3ms, total 24ms
03-05 01:50:50.600 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 20ms
03-05 01:51:16.350 W/IInputConnectionWrapper(27811): showStatusIcon on inactive InputConnection
03-05 01:51:25.320 D/dalvikvm(27811): GC_FOR_ALLOC freed 3628K, 26% free 12509K/16740K, paused 23ms, total 23ms
03-05 01:51:25.360 D/dalvikvm(27811): GC_CONCURRENT freed 38K, 17% free 14018K/16740K, paused 2ms+3ms, total 25ms
03-05 01:51:25.360 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 22ms
03-05 01:51:30.360 W/IInputConnectionWrapper(27811): showStatusIcon on inactive InputConnection
03-05 01:51:39.970 D/dalvikvm(27811): GC_CONCURRENT freed 3606K, 26% free 12503K/16728K, paused 2ms+4ms, total 28ms
03-05 01:51:39.970 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 11ms
03-05 01:51:40.010 D/dalvikvm(27811): GC_CONCURRENT freed 32K, 17% free 14019K/16728K, paused 3ms+3ms, total 25ms
03-05 01:51:40.010 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 18ms
03-05 01:51:51.000 I/Choreographer(27811): Skipped 68 frames! The application may be doing too much work on its main thread.
03-05 01:51:51.010 D/dalvikvm(27811): GC_CONCURRENT freed 3609K, 25% free 12430K/16404K, paused 6ms+4ms, total 36ms
03-05 01:51:51.460 D/dalvikvm(27811): GC_CONCURRENT freed 1227K, 23% free 12783K/16404K, paused 2ms+5ms, total 38ms
03-05 01:51:51.460 D/dalvikvm(27811): WAIT_FOR_CONCURRENT_GC blocked 31ms
TUTORIALONE CODE:
package com.example.thebasics;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class TutorialOne extends Activity implements OnCheckedChangeListener{
TextView textOut;
EditText textIn;
RadioGroup gravityG, styleG;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorialone);
textOut = (TextView) findViewById(R.id.tvChange);
textIn = (EditText) findViewById(R.id.editText1);
gravityG = (RadioGroup) findViewById(R.id.rgGravity);
styleG = (RadioGroup) findViewById(R.id.rgStyle);
//RADIO GROUPS
gravityG.setOnCheckedChangeListener(this);
styleG.setOnCheckedChangeListener(this);
//BUTTON
Button genereaza = (Button) findViewById(R.id.bGenerate);
genereaza.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
textOut.setText(textIn.getText());
}
});
}
protected void onPause() {
super.onPause();
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.rbLeft:
textOut.setGravity(Gravity.LEFT);
break;
case R.id.rbCenter:
textOut.setGravity(Gravity.CENTER);
break;
case R.id.rbRight:
textOut.setGravity(Gravity.RIGHT);
break;
case R.id.rbNormal:
textOut.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
break;
case R.id.rbItalic:
textOut.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC);
break;
case R.id.rbBold:
textOut.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);
break;
}
}
}
答案 0 :(得分:0)
我测试了你的代码。它的工作原理。
只需将您的班级名称(Menu)更改为MainActivity即可。快速修复将编译单元重命名为MainActivity。
在此处,将菜单更改为MainActivity。
(最终MediaPlayer sunetButton = MediaPlayer.create(Menu.this,R.raw.button_click);)
需要修复2个地方! 然后检查onClick()!因为我点击时出错了!
祝你好运!
答案 1 :(得分:0)
我解决了这个问题。当我使用此How do I make a splash screen?
更改了splash.java中的所有内容时,错误停止了在我用其他图像更改后,背景图像开始工作了!