0

在过去的几天里,我刚刚开始尝试学习 Java。我一直在教程等之间跳跃,以尝试学习一些基础知识。

目前它在启动屏幕上启动 5 秒,然后转到另一个操作(这是正确的术语吗?),这是主页(称为起始点)。然而,它在这 2 页之间跳转时崩溃。所以基本上,我的问题是为什么要这样做,我该如何解决?

我首先创建了主页,它本身就可以正常工作。只是在尝试在这两页之间跳转时。

清单 - 修改:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jonysapp.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<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>
</application>

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.jonysapp.test.StartingPoint"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.jonysapp.test.StartingPoint" />

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

飞溅.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/mirley"
>


</LinearLayout>

Splash.Java:我感觉这里某处的代码有问题。也许与 Try Catch Final 一起?

package com.jonysapp.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Splash extends Activity{

@Override
protected void onCreate(Bundle MirleysVariable) {
    // TODO Auto-generated method stub
    super.onCreate(MirleysVariable);
    setContentView(R.layout.splash);
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);

            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoint = new Intent(Splash.this, StartingPoint.class);
                Splash.this.startActivity(openStartingPoint);
            }
        }
    };
    timer.start();

}

}

起点.Java

package com.jonysapp.test;

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
protected 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 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.starting_point, menu);
    return true;
}

}

日志猫:

04-21 12:48:08.004: D/dalvikvm(31290): GC_FOR_ALLOC freed 66K, 3% free 8887K/9091K, paused 16ms

04-21 12:48:08.014: I/dalvikvm-heap(31290): Grow heap (frag case) to 10.280MB for 1639696-byte allocation

04-21 12:48:08.044: D/dalvikvm(31290): GC_CONCURRENT freed 1K, 3% free 10487K/10759K, paused 2ms+2ms

04-21 12:48:08.084: D/TextLayoutCache(31290): Using debug level: 0 - Debug Enabled: 0

04-21 12:48:08.134: D/libEGL(31290): loaded /system/lib/egl/libGLES_android.so

04-21 12:48:08.134: D/libEGL(31290): loaded /system/lib/egl/libEGL_adreno200.so

04-21 12:48:08.144: D/libEGL(31290): loaded /system/lib/egl/libGLESv1_CM_adreno200.so

04-21 12:48:08.144: D/libEGL(31290): loaded /system/lib/egl/libGLESv2_adreno200.so

04-21 12:48:08.174: D/OpenGLRenderer(31290): Enabling debug mode 0

04-21 12:48:13.094: W/dalvikvm(31290): threadid=11: thread exiting with uncaught exception (group=0x2b542210)

04-21 12:48:13.094: E/AndroidRuntime(31290): FATAL EXCEPTION: Thread-2196

04-21 12:48:13.094: E/AndroidRuntime(31290): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jonysapp.test/com.jonysapp.test.StartingPoint}; have you declared this activity in your AndroidManifest.xml?

04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)

04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)

04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Activity.startActivityForResult(Activity.java:3190)

04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Activity.startActivity(Activity.java:3297)

04-21 12:48:13.094: E/AndroidRuntime(31290): at com.jonysapp.test.Splash$1.run(Splash.java:23)

04-21 12:48:13.364: D/OpenGLRenderer(31290): Flushing caches (mode 0)

04-21 12:48:13.404: D/OpenGLRenderer(31290): Flushing caches (mode 1)

很可能我为这个问题发布了太多代码,所以如果我用太多内容轰炸了这个页面,我深表歉意。虽然如果我错过了任何重要的帮助,请告诉我!

作为旁注,如果您有任何提示可以阻止我到目前为止在编码方面养成任何不良习惯,那将不胜感激(但不是必需的)

再次感谢任何帮助!

4

2 回答 2

1

这是你的问题:

04-21 12:48:13.094: E/AndroidRuntime(31290): android.content.ActivityNotFoundException: 找不到明确的活动类 {com.jonysapp.test/ com.jonysapp.test.StartingPoint }; 您是否在AndroidManifest.xml中声明了此活动?

您必须在清单中声明活动,即

<activity
    android:name="com.example.project.StartingPoint"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

psintent-filter为应用启动器活动添加。

希望这会有所帮助......干杯!

于 2013-04-21T12:12:48.790 回答
0

看到这个消息:

04-21 12:48:13.094: E/AndroidRuntime(31290): android.content.ActivityNotFoundException: 找不到明确的活动类 {com.jonysapp.test/com.jonysapp.test.StartingPoint}; 您是否在 AndroidManifest.xml 中声明了此活动

这意味着您有一些未在清单文件中声明的活动。您在这里使用了所有大写字母:

com.jonysapp.test.STARTINGPOINT

尝试制作它:

com.jonysapp.test.StartingPoint. 

我猜类名区分大小写。@Trinimon 是对的。

于 2013-04-21T12:16:03.807 回答