我的应用程序上的主页面上已经有按钮,但我正在尝试制作,所以我可以在多个页面上设置按钮。我尝试制作一个新的.java文件,就像原始文件一样并进行编辑,我也尝试在第二页添加原始代码,但都不起作用。继承我的代码:
package com.dogger20011.app;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class beforemain extends MainActivity implements OnClickListener {
private AutoUpdateApk aua;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
aua = new AutoUpdateApk(getApplicationContext());
Button mBtn1 = (Button) findViewById(R.id.button1);
Button mBtn2 = (Button) findViewById(R.id.button2);
Button mBtn3 = (Button) findViewById(R.id.button3);
Button mBtn4 = (Button) findViewById(R.id.button4);
Button mBtn5 = (Button) findViewById(R.id.button5);
mBtn1.setOnClickListener(this);
mBtn2.setOnClickListener(this);
mBtn3.setOnClickListener(this);
mBtn4.setOnClickListener(this);
mBtn5.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) { //Get the id of the button that was clicked
case R.id.button1:
Intent i = new Intent(beforemain.this, Activity2.class);
startActivity(i);
break;
case R.id.button2:
Intent i1 = new Intent(beforemain.this, Activity3.class);
startActivity(i1);
break;
case R.id.button3:
Intent i2 = new Intent(beforemain.this, Activity4.class);
startActivity(i2);
break;
case R.id.button4:
Intent i3 = new Intent(beforemain.this, Activity5.class);
startActivity(i3);
break;
case R.id.button5:
Intent i5 = new Intent(Intent.ACTION_MAIN);
i5.setComponent(new ComponentName("com.mojang.minecraftpe",
"com.mojang.minecraftpe.MainActivity"));
i5.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i5);
}
}
}
继续我的下载XML(第二页)(由于规则而删除了所有链接):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/Downloads"
android:background="@drawable/black_background">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="101dp"
android:autoLink="web"
android:linksClickable="true"
android:text="MCPE 0.9.0 Build 5:
[Link Removed]"
android:textSize="22dp"
android:color="#008000" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="101dp"
android:autoLink="web"
android:linksClickable="true"
android:color="#008000"
android:text="MCPE 0.8.1:
[Link Removed]"
android:textSize="22dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="102dp"
android:autoLink="web"
android:linksClickable="true"
android:text="BlockLauncher Pro 1.6.10:
[Link Removed]"
android:textSize="22dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:autoLink="web"
android:linksClickable="true"
android:text="PocketInvEditor Pro 1.11:
[Link Removed]"
android:textSize="22dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Mods for PE2 (Play Store Link):
[Link Removed]"
android:autoLink="web"
android:linksClickable="true"
android:textSize="22dp"/>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="Minecraft Skin Studio:
[Link Removed]"
android:autoLink="web"
android:linksClickable="true"
android:textSize="22dp"/>
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Open MCPE!"
android:autoLink="web"
android:linksClickable="true"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
这是我的logcat:
06-18 14:51:31.200: E/AndroidRuntime(913): FATAL EXCEPTION: main
06-18 14:51:31.200: E/AndroidRuntime(913): Process: com.dogger20011.app, PID: 913
06-18 14:51:31.200: E/AndroidRuntime(913): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dogger20011.app/com.dogger20011.app.beforemain}: java.lang.NullPointerException
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.os.Handler.dispatchMessage(Handler.java:102)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.os.Looper.loop(Looper.java:136)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-18 14:51:31.200: E/AndroidRuntime(913): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 14:51:31.200: E/AndroidRuntime(913): at java.lang.reflect.Method.invoke(Method.java:515)
06-18 14:51:31.200: E/AndroidRuntime(913): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-18 14:51:31.200: E/AndroidRuntime(913): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-18 14:51:31.200: E/AndroidRuntime(913): at dalvik.system.NativeStart.main(Native Method)
06-18 14:51:31.200: E/AndroidRuntime(913): Caused by: java.lang.NullPointerException
06-18 14:51:31.200: E/AndroidRuntime(913): at com.dogger20011.app.beforemain.onCreate(beforemain.java:29)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.Activity.performCreate(Activity.java:5231)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-18 14:51:31.200: E/AndroidRuntime(913): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-18 14:51:31.200: E/AndroidRuntime(913): ... 11 more