我正在开发一个开发登录屏幕的应用程序。
我无法运行该应用。
我的xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Login"
android:background="@drawable/msngr">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:text="LoginID"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/etName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="20dp"
android:ems="10"
android:background="@android:drawable/editbox_background"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etName"
android:layout_below="@+id/etName"
android:layout_marginTop="41dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/etPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_centerVertical="true"
android:ems="10"
android:background="@android:drawable/editbox_background"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etPassword"
android:layout_below="@+id/etPassword"
android:layout_marginTop="33dp"
android:text=""
android:background="@drawable/login" />
</RelativeLayout>
的.java:
package com.example.message_reader_dcall;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final EditText etName=(EditText)findViewById(R.id.etName);
final EditText etPassword=(EditText)findViewById(R.id.etPassword);
final Button btnLogin =(Button)findViewById(R.id.btnLogin);
final gaRemoteConnection objConnect=new gaRemoteConnection();
btnLogin.setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
objConnect.setConnection("AndroidDB", "sa", "ok");
if(objConnect.checkUser(etName.getText().toString(),etPassword.getText().toString()))
{
//Intent i= new Intent(getApplicationContext(),Messages.class);
//startActivity(i);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
}
logcat的:
09-10 17:22:39.968: E/AndroidRuntime(1472): FATAL EXCEPTION: main
09-10 17:22:39.968: E/AndroidRuntime(1472): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.message_reader_dcall/com.example.message_reader_dcall.MainActivity}: java.lang.ClassNotFoundException: com.example.message_reader_dcall.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.message_reader_dcall-1.apk]
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.os.Looper.loop(Looper.java:123)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-10 17:22:39.968: E/AndroidRuntime(1472): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 17:22:39.968: E/AndroidRuntime(1472): at java.lang.reflect.Method.invoke(Method.java:507)
09-10 17:22:39.968: E/AndroidRuntime(1472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-10 17:22:39.968: E/AndroidRuntime(1472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-10 17:22:39.968: E/AndroidRuntime(1472): at dalvik.system.NativeStart.main(Native Method)
09-10 17:22:39.968: E/AndroidRuntime(1472): Caused by: java.lang.ClassNotFoundException: com.example.message_reader_dcall.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.message_reader_dcall-1.apk]
09-10 17:22:39.968: E/AndroidRuntime(1472): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-10 17:22:39.968: E/AndroidRuntime(1472): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-10 17:22:39.968: E/AndroidRuntime(1472): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-10 17:22:39.968: E/AndroidRuntime(1472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
答案 0 :(得分:3)
尽管您的代码显示MainActivity
Login
,但您仍尝试启动Activity
。
确保您在Activity
中使用与代码中相同的AndroidManifest.xml
名称
还要确保您的IDE想要启动正确的Activty
。
答案 1 :(得分:2)
根据您的日志
尝试此操作更改
public class Login extends Activity
{
}
到
public class MainActivity extends Activity
{}