Исключение смертельной ошибки в android

Я пытаюсь написать планировщик диеты для Android. после того, как я отлаживаю его, я нахожу, когда моя первая страница исчезает, и активность хочет перейти на вторую страницу, тогда возникает фатальная ошибка, но я не могу найти, где проблема? Может кто-нибудь мне помочь?

ОШИБКИ

10-24 06:35:46.622: E/AndroidRuntime(1102): FATAL EXCEPTION: main
10-24 06:35:46.622: E/AndroidRuntime(1102): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dietplanneraplication/com.example.dietplanneraplication.FeatureList}: java.lang.NullPointerException
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.os.Looper.loop(Looper.java:137)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-24 06:35:46.622: E/AndroidRuntime(1102): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 06:35:46.622: E/AndroidRuntime(1102): at java.lang.reflect.Method.invoke(Method.java:511)
10-24 06:35:46.622: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-24 06:35:46.622: E/AndroidRuntime(1102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-24 06:35:46.622: E/AndroidRuntime(1102): at dalvik.system.NativeStart.main(Native Method)
10-24 06:35:46.622: E/AndroidRuntime(1102): Caused by: java.lang.NullPointerException
10-24 06:35:46.622: E/AndroidRuntime(1102): at com.example.dietplanneraplication.FeatureList.onCreate(FeatureList.java:26)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.Activity.performCreate(Activity.java:5008)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-24 06:35:46.622: E/AndroidRuntime(1102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-24 06:35:46.622: E/AndroidRuntime(1102): ... 11 more

XML-коды

MAINACTIVITY.XML

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/firstpage" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#eee" android:orientation="vertical">
 <linearlayout android:id="@+id/logoid" android:layout_width="200dip" android:layout_height="200dip" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:background="@drawable/logo_shadow4" android:orientation="vertical">

 </linearlayout>
</relativelayout>

FEATURELIST.XML

BMICALCULATER> XML

JAVA CODES

MAINACTIVITY.JAVA

package com.example.dietplanneraplication;

public class MainActivity extends ActionBarActivity implements AnimationListener{
 RelativeLayout screen;
 int i;
 Intent intent;
 Animation animFadeout;

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 screen=(RelativeLayout) findViewById(R.id.firstpage);
 animFadeout=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_out );
 animFadeout.setAnimationListener(MainActivity.this);

 screen.post(new Runnable() {

 @Override
 public void run() {
 screen.startAnimation(animFadeout); 
 animFadeout.setFillAfter(true);
 }
 }); 


}


@Override
public void onAnimationEnd(Animation anim) {
 startActivity(new Intent(getApplicationContext(),FeatureList.class)); 
 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
 finish();

}

@Override
public void onAnimationRepeat(Animation arg0) {
 // TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation arg0) {
 // TODO Auto-generated method stub

}

}

FEATURELIST.JAVa

package com.example.dietplanneraplication;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.os.Build;

public class FeatureList extends ActionBarActivity {
Button bmiinformation;

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_feature_list);
 bmiinformation = (Button) findViewById(R.id.bmiinformation);
 bmiinformation.setOnClickListener(new View.OnClickListener() {

 @Override
 public void onClick(View v) {
 Intent intent =new Intent(getApplicationContext(),BmiCalculaterPage.class);
 startActivity(intent);
 finish();

 }
 });
 }

BMICALCULATER.JAVA

public class BmiCalculaterPage extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_bmi_calculater_page);


}

}

1 ответ

У вас нет идентификатора с именем bmiinformation в вашем activity_feature_list layout.xml.

bmiinformation = (Button) findViewById(R.id.bmiinformation); // bmiinformation is null as a result

То, где проблема, на мой взгляд. Попробуйте добавить кнопку с идентификационной bmiinformation.

licensed under cc by-sa 3.0 with attribution.