所以我在http://www.androidhive.info/2011/10/android-login-and-registration-screen-design/关注用户登录和注册演练(在我们真正启动数据库之前)我已经准备好了一切,在 Eclipse 中没有错误。有人可以看看我的代码并告诉我是什么导致应用程序意外停止吗?提前致谢!登录活动.java
package com.example.loginactivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting default screen to login.xml
setContentView(com.example.loginactivity.R.layout.login);
TextView registerScreen = (TextView) findViewById(com.example.loginactivity.R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
注册.java
package com.example.loginactivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class RegisterActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set View to register.xml
setContentView(com.example.loginactivity.R.layout.register);
TextView loginScreen = (TextView) findViewById(com.example.loginactivity.R.id.link_to_login);
// Listening to Login Screen link
loginScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Closing registration screen
// Switching to Login Screen/closing register screen
finish();
}
});
}
}
登录.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#ffffff">
<!-- Header Starts-->
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<!-- Logo Start-->
<ImageView android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"/>
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="@layout/footer_repeat"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
</LinearLayout>
<!-- Footer Ends -->
<!-- Login Form -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/header">
<!-- Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Email"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="20dip"
android:singleLine="true"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Password"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:password="true"/>
<!-- Login button -->
<Button android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Login"/>
<!-- Link to Registration Screen -->
<TextView android:id="@+id/link_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="New to Twitter? Register here"
android:gravity="center"
android:textSize="20dip"
android:textColor="#0b84aa"/>
</LinearLayout>
<!-- Login Form Ends -->
</RelativeLayout>
</ScrollView>
注册.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#fff">
<!-- Header Starts-->
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<!-- Logo Start-->
<ImageView android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"/>
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="@layout/footer_repeat"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
</LinearLayout>
<!-- Footer Ends -->
<!-- Registration Form -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/header">
<!-- Full Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Full Name"/>
<EditText android:id="@+id/reg_fullname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<!-- Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Email"/>
<EditText android:id="@+id/reg_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:layout_marginBottom="20dip"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Password"/>
<EditText android:id="@+id/reg_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true"
android:layout_marginTop="5dip"/>
<!-- Register Button -->
<Button android:id="@+id/btnRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Register New Account"/>
<!-- Link to Login Screen -->
<TextView android:id="@+id/link_to_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="Already has account! Login here"
android:gravity="center"
android:textSize="20dip"
android:textColor="#025f7c"/>
</LinearLayout>
<!-- Registration Form Ends -->
</RelativeLayout>
</ScrollView>
这是日志猫:
08-26 17:21:14.818: D/AndroidRuntime(17713): Shutting down VM
08-26 17:21:14.818: W/dalvikvm(17713): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
08-26 17:21:14.818: E/AndroidRuntime(17713): FATAL EXCEPTION: main
08-26 17:21:14.818: E/AndroidRuntime(17713): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.loginactivity/com.example.loginactivity.MainActivity}: java.lang.ClassNotFoundException: com.example.loginactivity.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.loginactivity-2.apk]
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1746)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1854)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1041)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.os.Looper.loop(Looper.java:150)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.ActivityThread.main(ActivityThread.java:4333)
08-26 17:21:14.818: E/AndroidRuntime(17713): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 17:21:14.818: E/AndroidRuntime(17713): at java.lang.reflect.Method.invoke(Method.java:507)
08-26 17:21:14.818: E/AndroidRuntime(17713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-26 17:21:14.818: E/AndroidRuntime(17713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-26 17:21:14.818: E/AndroidRuntime(17713): at dalvik.system.NativeStart.main(Native Method)
08-26 17:21:14.818: E/AndroidRuntime(17713): Caused by: java.lang.ClassNotFoundException: com.example.loginactivity.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.loginactivity-2.apk]
08-26 17:21:14.818: E/AndroidRuntime(17713): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-26 17:21:14.818: E/AndroidRuntime(17713): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-26 17:21:14.818: E/AndroidRuntime(17713): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
08-26 17:21:14.818: E/AndroidRuntime(17713): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1738)
08-26 17:21:14.818: E/AndroidRuntime(17713): ... 11 more
这是 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.loginactivity.MainActivity"
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:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".LoginActivity"
android:label="Login to your Account">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Entry for RegisterActivity.class -->
<activity android:name=".RegisterActivity"
android:label="Register New Account"></activity>
</application>
</manifest>