我的主要课程:
package com.example.hi;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SampleLogin extends Activity {
EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtUserName=(EditText)this.findViewById(R.id.txtUname);
txtPassword=(EditText)this.findViewById(R.id.txtPwd);
btnLogin=(Button)this.findViewById(R.id.btnLogin);
btnLogin=(Button)this.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
Toast.makeText(SampleLogin.this, "Login Successful",Toast.LENGTH_LONG).show();
} else{
Toast.makeText(SampleLogin.this, "Invalid Login",Toast.LENGTH_LONG).show();
}
}
});
}
}
我的 XML 文件...
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/User_Name: "
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:inputType="textPassword|number"
android:text=""
android:id="@+id/txtUname"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow>
<TextView
android:text="@string/Password: "
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:inputType="textPassword|number"
android:text=""
android:id="@+id/txtPwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<Button
android:text="@string/Cancel"
android:id="@+id/btnCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button
android:text="@string/Login"
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</TableRow>
</TableLayout>
所以这是我的代码,由于某种原因,当我打开它时应用程序停止工作,“应用程序()已意外停止。请重试avd ...”我不知道为什么会这样,请帮忙!
我是android新手,谁能告诉我如何获取catlog文件?
关于 xml 文件上的字符串,我还是新手,我收到关于“硬编码字符串”或类似内容的错误,它说我需要将它添加到 res 文件夹中找到的字符串文件中,所以我添加字符串,然后添加@string
猫日志文件:
12-28 17:36:50.883: E/Zygote(33): setreuid() failed. errno: 2
12-28 17:37:00.573: E/Zygote(33): setreuid() failed. errno: 17
12-28 17:37:01.933: E/BatteryService(61): usbOnlinePath not found
12-28 17:37:01.933: E/BatteryService(61): batteryVoltagePath not found
12-28 17:37:01.933: E/BatteryService(61): batteryTemperaturePath not found
12-28 17:37:01.953: E/SurfaceFlinger(61): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
12-28 17:37:02.173: E/SensorService(61): couldn't open device for module sensors (Invalid argument)
12-28 17:37:06.682: E/System(61): Failure starting core service
12-28 17:37:06.682: E/System(61): java.lang.SecurityException
12-28 17:37:06.682: E/System(61): at android.os.BinderProxy.transact(Native Method)
12-28 17:37:06.682: E/System(61): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
12-28 17:37:06.682: E/System(61): at android.os.ServiceManager.addService(ServiceManager.java:72)
12-28 17:37:06.682: E/System(61): at com.android.server.ServerThread.run(SystemServer.java:206)
12-28 17:37:06.712: E/EventHub(61): could not get driver version for /dev/input/mouse0, Not a typewriter
12-28 17:37:06.712: E/EventHub(61): could not get driver version for /dev/input/mice, Not a typewriter
12-28 17:37:07.122: E/SoundPool(61): error loading /system/media/audio/ui/Effect_Tick.ogg
12-28 17:37:07.122: E/SoundPool(61): error loading /system/media/audio/ui/KeypressStandard.ogg
12-28 17:37:07.122: E/SoundPool(61): error loading /system/media/audio/ui/KeypressSpacebar.ogg
12-28 17:37:07.122: E/SoundPool(61): error loading /system/media/audio/ui/KeypressDelete.ogg
12-28 17:37:07.122: E/SoundPool(61): error loading /system/media/audio/ui/KeypressReturn.ogg
12-28 17:37:07.164: E/UsbObserver(61): java.lang.NullPointerException
12-28 17:37:07.164: E/UsbObserver(61): at com.android.server.UsbObserver.init(UsbObserver.java:131)
12-28 17:37:07.164: E/UsbObserver(61): at com.android.server.UsbObserver.<init>(UsbObserver.java:65)
12-28 17:37:07.164: E/UsbObserver(61): at com.android.server.ServerThread.run(SystemServer.java:402)
12-28 17:37:07.673: E/ThrottleService(61): Could not open GPS configuration file /etc/gps.conf
12-28 17:37:08.392: E/logwrapper(135): executing /system/bin/tc failed: No such file or directory
12-28 17:37:08.392: E/logwrapper(136): executing /system/bin/tc failed: No such file or directory
12-28 17:37:08.432: E/logwrapper(138): executing /system/bin/tc failed: No such file or directory
12-28 17:37:35.198: E/AndroidRuntime(335): FATAL EXCEPTION: main
12-28 17:37:35.198: E/AndroidRuntime(335): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.hi/com.example.hi.MainActivity}: java.lang.ClassNotFoundException: com.example.hi.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.hi-1.apk]
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-28 17:37:35.198: E/AndroidRuntime(335): at java.lang.reflect.Method.invokeNative(Native Method)
12-28 17:37:35.198: E/AndroidRuntime(335): at java.lang.reflect.Method.invoke(Method.java:507)
12-28 17:37:35.198: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-28 17:37:35.198: E/AndroidRuntime(335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-28 17:37:35.198: E/AndroidRuntime(335): at dalvik.system.NativeStart.main(Native Method)
12-28 17:37:35.198: E/AndroidRuntime(335): Caused by: java.lang.ClassNotFoundException: com.example.hi.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.hi-1.apk]
12-28 17:37:35.198: E/AndroidRuntime(335): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-28 17:37:35.198: E/AndroidRuntime(335): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-28 17:37:35.198: E/AndroidRuntime(335): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-28 17:37:35.198: E/AndroidRuntime(335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
12-28 17:37:35.198: E/AndroidRuntime(335): ... 11 more
12-28 17:38:05.517: E/AndroidRuntime(344): FATAL EXCEPTION: main
12-28 17:38:05.517: E/AndroidRuntime(344): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.hi/com.example.hi.MainActivity}: java.lang.ClassNotFoundException: com.example.hi.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.hi-1.apk]
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.os.Looper.loop(Looper.java:123)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-28 17:38:05.517: E/AndroidRuntime(344): at java.lang.reflect.Method.invokeNative(Native Method)
12-28 17:38:05.517: E/AndroidRuntime(344): at java.lang.reflect.Method.invoke(Method.java:507)
12-28 17:38:05.517: E/AndroidRuntime(344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-28 17:38:05.517: E/AndroidRuntime(344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-28 17:38:05.517: E/AndroidRuntime(344): at dalvik.system.NativeStart.main(Native Method)
12-28 17:38:05.517: E/AndroidRuntime(344): Caused by: java.lang.ClassNotFoundException: com.example.hi.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.hi-1.apk]
12-28 17:38:05.517: E/AndroidRuntime(344): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-28 17:38:05.517: E/AndroidRuntime(344): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-28 17:38:05.517: E/AndroidRuntime(344): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-28 17:38:05.517: E/AndroidRuntime(344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
12-28 17:38:05.517: E/AndroidRuntime(344): ... 11 more
它不再崩溃,但我无法输入任何内容!我在 xml 文件中更改了一些关于打字的内容,因为它给了我一个问题
android:inputType="textPassword|number"
我认为是这样,但是当我尝试输入某些内容时,它什么也没做!
这应该工作吗?
<EditText
android:inputType="textPassword|number"
android:text=""
android:id="@+id/txtPwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:inputType="textPassword|number"
android:text=""
android:id="@+id/txtUname"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />