09-30 02:32:31.474: D/ddm-heap(214): Got feature list request
09-30 02:32:31.634: D/AndroidRuntime(214): Shutting down VM
09-30 02:32:31.634: W/dalvikvm(214): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
09-30 02:32:31.634: E/AndroidRuntime(214): Uncaught handler: thread main exiting due to uncaught exception
09-30 02:32:31.654: E/AndroidRuntime(214): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mjcet.mjcet/com.mjcet.mjcet.MJCET}: java.lang.ClassNotFoundException: com.mjcet.mjcet.MJCET in loader dalvik.system.PathClassLoader@44e8c820
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.os.Handler.dispatchMessage(Handler.java:99)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.os.Looper.loop(Looper.java:123)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.ActivityThread.main(ActivityThread.java:4363)
09-30 02:32:31.654: E/AndroidRuntime(214): at java.lang.reflect.Method.invokeNative(Native Method)
09-30 02:32:31.654: E/AndroidRuntime(214): at java.lang.reflect.Method.invoke(Method.java:521)
09-30 02:32:31.654: E/AndroidRuntime(214): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-30 02:32:31.654: E/AndroidRuntime(214): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-30 02:32:31.654: E/AndroidRuntime(214): at dalvik.system.NativeStart.main(Native Method)
09-30 02:32:31.654: E/AndroidRuntime(214): Caused by: java.lang.ClassNotFoundException: com.mjcet.mjcet.MJCET in loader dalvik.system.PathClassLoader@44e8c820
09-30 02:32:31.654: E/AndroidRuntime(214): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
09-30 02:32:31.654: E/AndroidRuntime(214): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
09-30 02:32:31.654: E/AndroidRuntime(214): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-30 02:32:31.654: E/AndroidRuntime(214): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
09-30 02:32:31.654: E/AndroidRuntime(214): ... 11 more
09-30 02:32:31.684: I/dalvikvm(214): threadid=7: reacting to signal 3
09-30 02:32:31.684: E/dalvikvm(214): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
以上是我对以下活动LOGINACTIVITY.java的调试输出
package com.agrim.mjcet;
import com.agrim.mjcet.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
//import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
public class LoginActivity extends Activity {
EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting default screen to login.xml
setContentView(R.layout.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()
{
public void onClick(View v) {
// Switching to Register screen
if((txtUserName.getText().toString()).equals(txtPassword.getText().toString()))
{
Intent myIntent = new Intent(getApplicationContext(),SampleActivity.class);
startActivityForResult(myIntent, 0);
}
}
}
);
}
}
示例活动.java
package com.agrim.mjcet;
import com.agrim.mjcet.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class SampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set View to register.xml
setContentView(R.layout.lol);
TextView HomeScreen = (TextView) findViewById(R.id.back);
HomeScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// Closing registration screen
// Switching to Login Screen/closing register screen
finish();
}
});
}
}
这是我的 2 个布局
主文件
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/user_name"
android:textColor="#347235"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_marginLeft="25dip"
android:layout_height="wrap_content">
</TextView>
<EditText
android:text=""
android:inputType="text"
android:id="@+id/txtUname"
android:layout_weight="0.75"
android:layout_width="wrap_content"
android:layout_marginRight="10dip"
android:layout_marginBottom="5dip"
android:background="#FFFFFF"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow>
<TextView
android:text="@string/password"
android:textColor="#347235"
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dip">
</TextView>
<EditText
android:text=""
android:inputType="textPassword"
android:id="@+id/txtPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:layout_weight="1"
android:background="#FFFFFF"
android:gravity="center">
</EditText>
</TableRow>
<TableRow>
<Button
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_marginTop="25dip"
android:layout_marginLeft="50dip"
android:onClick="onClickMyButton"
android:text="@string/login" />
<Button
android:id="@+id/btnCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_marginTop="25dip"
android:layout_marginLeft="100dip"
android:layout_marginRight="50dip"
android:text="@string/cancel" />
</TableRow>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/logo_invert"
android:contentDescription="@drawable/logo_invert"/>
</FrameLayout>
</TableLayout>
最后是 LOL.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#000000"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:id="@+id/back"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/lol"
android:contentDescription="@drawable/lol">
</ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="138dp"
android:orientation="vertical"
android:gravity="bottom" >
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/coming_soon"
android:textColor="#347235" />
</RelativeLayout>
</FrameLayout>
这是我的 Android Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mjcet.mjcet"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission
android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="15"
android:maxSdkVersion="16" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity
android:name="MJCET"
android:label="welcome to MJCET" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SampleActivity"></activity>
</application>
</manifest>
我在初始化时强制关闭.. 是的,这是我的第一个 android 应用程序 :)