Java 从splash到实际应用程序。不幸的是,应用程序已停止
我的第一个android应用程序出现问题。 我不明白为什么在等待5秒钟后,应用程序退出并说“不幸的是,应用程序停止了”。这个应用程序非常简单。只需添加和细分1个数字。但启动时会显示一个图像 MainActivity.javaJava 从splash到实际应用程序。不幸的是,应用程序已停止,java,android,Java,Android,我的第一个android应用程序出现问题。 我不明白为什么在等待5秒钟后,应用程序退出并说“不幸的是,应用程序停止了”。这个应用程序非常简单。只需添加和细分1个数字。但启动时会显示一个图像 MainActivity.java package com.example.helloworld; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view
package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int counter;
Button add, sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
display.setText("Your total is " + counter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
HelloWorldManifest.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
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" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".startingPoint"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.helloworld.STARTINGPOINT"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
LOGCAT
04-25 08:25:33.391: D/AndroidRuntime(1016): Shutting down VM
04-25 08:25:33.391: W/dalvikvm(1016): threadid=1: thread exiting with uncaught exception (group=0x41465700)
04-25 08:25:33.471: E/AndroidRuntime(1016): FATAL EXCEPTION: main
04-25 08:25:33.471: E/AndroidRuntime(1016): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.helloworld/com.example.helloworld.startingPoint}: java.lang.ClassNotFoundException: Didn't find class "com.example.helloworld.startingPoint" on path: DexPathList[[zip file "/data/app/com.example.helloworld-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.helloworld-1, /system/lib]]
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.os.Looper.loop(Looper.java:137)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-25 08:25:33.471: E/AndroidRuntime(1016): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 08:25:33.471: E/AndroidRuntime(1016): at java.lang.reflect.Method.invoke(Method.java:525)
04-25 08:25:33.471: E/AndroidRuntime(1016): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-25 08:25:33.471: E/AndroidRuntime(1016): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-25 08:25:33.471: E/AndroidRuntime(1016): at dalvik.system.NativeStart.main(Native Method)
04-25 08:25:33.471: E/AndroidRuntime(1016): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.helloworld.startingPoint" on path: DexPathList[[zip file "/data/app/com.example.helloworld-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.helloworld-1, /system/lib]]
04-25 08:25:33.471: E/AndroidRuntime(1016): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
04-25 08:25:33.471: E/AndroidRuntime(1016): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-25 08:25:33.471: E/AndroidRuntime(1016): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-25 08:25:33.471: E/AndroidRuntime(1016): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
04-25 08:25:33.471: E/AndroidRuntime(1016): ... 11 more
04-25 08:35:02.411: D/dalvikvm(1066): GC_FOR_ALLOC freed 52K, 7% free 2631K/2800K, paused 42ms, total 44ms
问题是从飞溅到实际应用程序。分开来看,他们都很好。
谢谢
编辑:在清单更改时
action android:name=".STARTINGPOINT"
到
因为事情就是这样。我换了衣服,试着让思想发挥作用。抱歉从您发布的代码来看,似乎没有“启动点”,只有Splash和MainActivity,需要在清单中声明 需要将此添加到您的清单中:
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".startingPoint"
android:label="@string/app_name" >
<intent-filter>
<action android:name=".STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
剩下的看起来不错,你有没有什么叫做STARTINGPOINT的活动?或者从清单中删除此项:
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".startingPoint"
android:label="@string/app_name" >
<intent-filter>
<action android:name=".STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
编译器无法识别“STARTINGPOINT”类,这是您的例外。您正在尝试启动名为STARTINGPOINT的活动,但您没有该名称的类 您的Android清单活动Android:name属性应该与活动java文件的包/类名相同。换成
android:name="com.example.helloworld.MainActivity"
此外,您还可以在不使用字符串文字的情况下使用意图:
Intent intent = new Intent(this, MainActivity.class);
在清单中,此
“com.example.helloworld.STARTINGPOINT”
具有不同的名称。使其匹配(即:在您的代码中,使用新意图(“.STARTINGPOINT”)
)非常感谢!!我真的很感激,非常欢迎,很好,这很有帮助。也通过,会有帮助的
Intent intent = new Intent(this, MainActivity.class);