Android 模拟器强制关闭我的应用程序

标签 android

我的应用程序强制在模拟器上关闭。该怎么办? 我的 java 代码正确地基于我的 xml。

Java 代码:-

package com.thenewboston.parin;

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 StartingPoint extends Activity {
    int counter;
    Button add, sub;
    TextView display;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_starting_point);
        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 arg0) {
                counter += 1;
                display.setText("Your total is" + counter);
            }
        });

        sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                counter--;
                display.setText("Your total is" + counter);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // inflate menu
        getMenuInflater().inflate(R.menu.starting_point, menu);
        return true;
    }
}

和错误消息:-

 07-23 12:43:33.375: D/AndroidRuntime(395): Shutting down VM 07-23 12:43:33.375: W/dalvikvm(395): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-23 12:43:33.375: E/AndroidRuntime(395): FATAL EXCEPTION: main 07-23 12:43:33.375: E/AndroidRuntime(395): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thenewboston.parin/com.thenewboston.parin.Startingpoint}: java.lang.ClassNotFoundException: com.thenewboston.parin.Startingpoint in loader dalvik.system.PathClassLoader[/data/app/com.thenewboston.parin-2.apk] 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.os.Handler.dispatchMessage(Handler.java:99) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.os.Looper.loop(Looper.java:123) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-23 12:43:33.375: E/AndroidRuntime(395): at java.lang.reflect.Method.invokeNative(Native Method) 07-23 12:43:33.375: E/AndroidRuntime(395): at java.lang.reflect.Method.invoke(Method.java:521) 07-23 12:43:33.375: E/AndroidRuntime(395): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-23 12:43:33.375: E/AndroidRuntime(395): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-23 12:43:33.375: E/AndroidRuntime(395): at dalvik.system.NativeStart.main(Native Method) 07-23 12:43:33.375: E/AndroidRuntime(395): Caused by: java.lang.ClassNotFoundException: com.thenewboston.parin.Startingpoint in loader dalvik.system.PathClassLoader[/data/app/com.thenewboston.parin-2.apk] 07-23 12:43:33.375: E/AndroidRuntime(395): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 07-23 12:43:33.375: E/AndroidRuntime(395): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 07-23 12:43:33.375: E/AndroidRuntime(395): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-23 12:43:33.375: E/AndroidRuntime(395): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) 07-23 12:43:33.375: E/AndroidRuntime(395): ... 11 more 07-23 12:45:27.575: I/Process(395): Sending signal. PID: 395 SIG: 9

最佳答案

在您的 list 更改中

<activity android:name="com.thenewboston.parin.Startingpoint" android:label="@string/app_name" >

<activity android:name="com.thenewboston.parin.StartingPoint" android:label="@string/app_name" >

你打错了,大写字母很重要。

关于Android 模拟器强制关闭我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17803565/

相关文章:

Android 文本转语音初始化速度很慢

android - 文档模板生成 kotlin

android - 如何在 Android 原生 C 代码的系统函数中使用 cp(复制)命令

android - ImageView 不显示捕获的照片 android

android - NestedScrollView 内的 ViewPager 内的 NestedScrollView : Innermost NestedScrollView not scrolling

javascript - Phonegap 2.0.0 keyup 事件

java - SQLite 一列到数组

android - PagerAdapter 的页面更改回调

java - 无法通过 Android M 代码设置铃声

android - 在带有 ListFragment 的 Android FragmentActivity 中找不到 id 的 View