我是Android开发的新手,我正在制作简单的应用程序来计算体脂百分比,因为它运行良好但在我传递新的MainActivity并重写MainActivity.java的代码后,每次用户按下时都会出现错误和应用程序崩溃按钮,
MainActivity .java
package com.tech.syborg.bodyfat;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import static com.tech.syborg.bodyfat.R.id.button3;
public class MainActivity extends AppCompatActivity {
private static Button button_cal;
private static Button button_how;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickButtonListener();
}
private void OnClickButtonListener() {
button_cal = (Button)findViewById(R.id.button2);
button_how = (Button)findViewById(R.id.button3);
button_cal.setOnClickListener(
new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent("com.tech.syborg.bodyfat.GenderSelectActivity");
startActivity(intent);
}
}
);
button_how.setOnClickListener(
new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent = new Intent("com.tech.syborg.bodyfat.HowToCalculateActivity");
startActivity(intent);
}
}
);
}
}
的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tech.syborg.bodyfat">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".GenderSelectActivity">
<intent-filter>
<action android:name="com.tech.syborg.bodyfat.GenderSelectActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".MaleCalculateActivity">
<intent-filter>
<action android:name="com.tech.syborg.bodyfat.MaleCalculateActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".FemaleCalculateActivity">
<intent-filter>
<action android:name="com.tech.syborg.bodyfat.FemaleCalculateActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".HowToCalculateActivity">
<intent-filter>
<action android:name="com.tech.syborg.bodyfat.HowToCalculateActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ResultActivity">
<intent-filter>
<action android:name="com.tech.syborg.bodyfat.ResultActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</activity>
</application>
xml for buttons
<Button
android:text="How To Take Measurements "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="?attr/colorPrimary"
android:textColor="@android:color/white"
android:layout_below="@+id/discription"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="26dp" />
<Button
android:text=" Calculate Body Fat %"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="?attr/colorPrimary"
android:textColor="@android:color/white"
android:layout_below="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="36dp" />
logcat的
02-12 19:52:14.536 5976-5976/? I/art: Late-enabling -Xcheck:jni
02-12 19:52:14.600 5976-5976/com.tech.syborg.bodyfat W/System: ClassLoader referenced unknown path: /data/app/com.tech.syborg.bodyfat-1/lib/arm
02-12 19:52:14.611 5976-5976/com.tech.syborg.bodyfat I/InstantRun: Instant Run Runtime started. Android package is com.tech.syborg.bodyfat, real application class is null.
02-12 19:52:15.313 5976-5976/com.tech.syborg.bodyfat W/System: ClassLoader referenced unknown path: /data/app/com.tech.syborg.bodyfat-1/lib/arm
02-12 19:52:15.507 5976-5976/com.tech.syborg.bodyfat W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
02-12 19:52:15.907 5976-6242/com.tech.syborg.bodyfat I/Adreno: QUALCOMM build : 7d18700, I8ee426a9a2
Build Date : 10/07/16
OpenGL ES Shader Compiler Version: XE031.09.00.03
Local Branch : mybranch22308589
Remote Branch : quic/LA.BR.1.3.6_rb1.6
Remote Branch : NONE
Reconstruct Branch : NOTHING
02-12 19:52:15.915 5976-6242/com.tech.syborg.bodyfat I/OpenGLRenderer: Initialized EGL, version 1.4
02-12 19:52:15.915 5976-6242/com.tech.syborg.bodyfat D/OpenGLRenderer: Swap behavior 1
02-12 19:52:18.524 5976-5976/com.tech.syborg.bodyfat D/AndroidRuntime: Shutting down VM
02-12 19:52:18.525 5976-5976/com.tech.syborg.bodyfat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tech.syborg.bodyfat, PID: 5976
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.tech.syborg.bodyfat.GenderSelectActivity }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1899)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1589)
at android.app.Activity.startActivityForResult(Activity.java:4228)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4187)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4515)
at android.app.Activity.startActivity(Activity.java:4483)
at com.tech.syborg.bodyfat.MainActivity$1.onClick(MainActivity.java:35)
at android.view.View.performClick(View.java:5612)
at android.view.View$PerformClick.run(View.java:22285)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)