I'm making a simple game that first asks for a difficulty in the main activity. It calls a new activity that asks for a game mode. That calls a new activity for the actual game which just tells the user to tap the screen when the color changes, and measures their reaction time. As soon as I run it, it tells me "Unfortunately, the application has stopped" and there are a lot of errors. I've seen nearly the exact same set of errors in other questions, but none of the answers has applied to me. Any suggestions? I'm sorry if this question seems vague, I have no idea how to handle this. The following is the Android Manifest, the code for the three activities, and the error log:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dabaam.battlereaction"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.dabaam.battlereaction.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.dabaam.battlereaction.GameType">
</activity>
<activity
android:name="com.dabaam.battlereaction.Game">
</activity>
</application>
Activity 1:
package com.dabaam.battlereaction;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
public class MainActivity extends Activity {
Button ezbtn = (Button) findViewById(R.id.ezbtn);
Button medbtn = (Button) findViewById(R.id.medbtn);
Button hardbtn = (Button) findViewById(R.id.hardbtn);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ezbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
askDifficulty("EASY");
}
});
medbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
askDifficulty("MEDIUM");
}
});
hardbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
askDifficulty("HARD");
}
});
}
private void askDifficulty(String whichDiff){
Intent intent = new Intent(MainActivity.this, GameType.class);
intent.putExtra(GameType.difficulty, whichDiff);
startActivity(intent);
}
}
Activity 2:
package com.dabaam.battlereaction;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
public class GameType extends Activity{
public static String difficulty = "difficulty";
public static final String EASY = "EASY";
public static final String MEDIUM = "MEDIUM";
public static final String HARD = "HARD";
Button visbtn = (Button) findViewById(R.id.vis_btn);
Button tactbtn = (Button) findViewById(R.id.tact_btn);
Button audbtn = (Button) findViewById(R.id.aud_btn);
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.type_layout);
Bundle extras = getIntent().getExtras();
//if( extras.getString(difficulty).equals(EASY) ){
// Start EASY game
difficulty = extras.getString(difficulty);
visbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
launchGame(difficulty,"VISUAL");
}
});
tactbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
launchGame(difficulty,"TACTILE");
}
});
audbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
launchGame(difficulty,"AUDITORY");
}
});
}
private void launchGame(String whichDiff, String whichMode){
Intent intent = new Intent(GameType.this, Game.class);
intent.putExtra(Game.difficulty, whichDiff);
intent.putExtra(Game.mode, whichMode);
startActivity(intent);
}
}
Activity 3:
package com.dabaam.battlereaction;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Game extends Activity implements OnTouchListener{
LinearLayout glayout = (LinearLayout) findViewById(R.id.gameLayout);
public static final String difficulty = "difficulty";
public static final String mode = "mode";
public Random r = new Random();
int after = r.nextInt(10000 - 2000) + 2000;
public long time1 = 0;
public long time2 = 0;
public long elapsed = 1212121; //1212121 by default for debugging
public String ms_score = "1212121"; //1212121 by default
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.game_layout);
new Timer().schedule(change(), after);
}
public boolean onTouch(View v, MotionEvent event) {
time2= System.nanoTime();
elapsed = (time2-time1)/1000000;
TextView score = new TextView(getApplicationContext());
ms_score = getString(R.string.score, elapsed);
score.setText(ms_score);
glayout.addView(score);
return false;
}
#SuppressLint("ResourceAsColor") public TimerTask change() {
glayout.setBackgroundColor(R.color.Blue);
time1= System.nanoTime();
return null;
}
}
Error log:
07-01 17:01:43.490: E/AndroidRuntime(20563): FATAL EXCEPTION: main
07-01 17:01:43.490: E/AndroidRuntime(20563): Process: com.dabaam.battlereaction, PID: 20563
07-01 17:01:43.490: E/AndroidRuntime(20563): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dabaam.battlereaction/com.dabaam.battlereaction.MainActivity}: java.lang.NullPointerException
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2514)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.ActivityThread.access$800(ActivityThread.java:156)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.os.Handler.dispatchMessage(Handler.java:102)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.os.Looper.loop(Looper.java:157)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.ActivityThread.main(ActivityThread.java:5872)
07-01 17:01:43.490: E/AndroidRuntime(20563): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 17:01:43.490: E/AndroidRuntime(20563): at java.lang.reflect.Method.invoke(Method.java:515)
07-01 17:01:43.490: E/AndroidRuntime(20563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
07-01 17:01:43.490: E/AndroidRuntime(20563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
07-01 17:01:43.490: E/AndroidRuntime(20563): at dalvik.system.NativeStart.main(Native Method)
07-01 17:01:43.490: E/AndroidRuntime(20563): Caused by: java.lang.NullPointerException
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.Activity.findViewById(Activity.java:1952)
07-01 17:01:43.490: E/AndroidRuntime(20563): at com.dabaam.battlereaction.MainActivity.<init>(MainActivity.java:11)
07-01 17:01:43.490: E/AndroidRuntime(20563): at java.lang.Class.newInstanceImpl(Native Method)
07-01 17:01:43.490: E/AndroidRuntime(20563): at java.lang.Class.newInstance(Class.java:1208)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
07-01 17:01:43.490: E/AndroidRuntime(20563): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
07-01 17:01:43.490: E/AndroidRuntime(20563): ... 11 more
07-01 17:01:47.684: D/Process(20563): killProcess, pid=20563
07-01 17:01:47.684: D/Process(20563): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:131 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690
Move
Button ezbtn = (Button) findViewById(R.id.ezbtn);
Button medbtn = (Button) findViewById(R.id.medbtn);
Button hardbtn = (Button) findViewById(R.id.hardbtn);
under
setContentView(R.layout.type_layout);
Your buttons are not created when you try to find them using findViewById(), therefore you get a NullPointerException.
After declaring your layout, they are created.
Your application crashes because of this line:
LinearLayout glayout = (LinearLayout) findViewById(R.id.gameLayout);
The crash occurs because you cannot find a View before the contentView has been set, which happens in the onCreate(...) method of your Activity.
Move the initialization of "glayout" below the setContentView(...) call.
In addition to that, i'd go with yygyt's suggestion.
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I learn android studio programing and I have problem in my programs,
when I want to go to new activity using intent statement my app crashed,
this is my main activity;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
}
public void onStart(){
super.onStart();
FirebaseUser CurrentUser = mAuth.getCurrentUser();
if(CurrentUser == null){
Intent StartIntent = new Intent(MainActivity.this,
StartActivity.class);
startActivity(StartIntent);
finish();
}
}
}
and this is manifest :
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StartActivity"
android:label="#string/app_name">
</activity>
there is no error message
but thit is what i have into android monitor :
08-23 21:50:33.507 11264-11264/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ruse.ayse.areyousmartenough, PID: 11264
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ruse.ayse.areyousmartenough/com.ruse.ayse.areyousmartenough.StartActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2378)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.ruse.ayse.areyousmartenough.StartActivity.onCreate(StartActivity.java:31)
at android.app.Activity.performCreate(Activity.java:5301)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2291)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2378)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
I solved this problem into another project by adding "intent-filter" into manifest file but it does not work with this project,
this is StartActivity :
public class StartActivity extends AppCompatActivity {
private Button mRegBtn ;
private Button mLoginBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
mRegBtn = (Button) findViewById(R.id.RegBtn);
mLoginBtn = (Button) findViewById(R.id.LoginBtn);
mRegBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent createAccount = new Intent(StartActivity.this, RegisterActivity.class);
startActivity(createAccount);
}
});
mLoginBtn.setOnClickListener(new View.OnClickListener(){ /////this is line 31
#Override
public void onClick(View view) {
Intent loginAccount = new Intent(StartActivity.this, LoginActivity.class);
startActivity(loginAccount);
}
});
}}
Your problem is at StartActivity.java:31 you are trying to read from a null reference.
By your comment, you look to miss getting the mLoginBtn from your Layout=
mLoginBtn = (Button) findViewById(R.id.btn_login);
I wanted to make an app where you can make pictures and save them, but when I test it I got this error in my logcat: "java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.random/com.example.random.FotoMaker}: java.lang.NullPointerException". I think the problem has something to do with the intent, but im not sure what I need to add/change in my FotoMaker.java.
MenuScreen.java:
package com.example.random;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
public class MenuScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("DEBUG", "test");
Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
startActivityForResult(intent, 0);
}
});
findViewById(R.test1).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Log.d("DEBUG", "test1");
Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
}
});
findViewById(R.test2).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Log.d("DEBUG", "test2");
Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
}
});
findViewById(R.id.verlaat_app).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Log.d("DEBUG", "test3");
MenuScreen.this.finish();
}
});
}
}
MenuScreen.java:
package com.example.random;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class FotoMaker extends Activity
{
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.testpic);
iv = (ImageView) findViewById(R.id.imageView);
Button btn = (Button) findViewById(R.id.testpic);
btn.setOnClickListener(new OnClickListener()
{
#Override
public void onClick (View v){
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 0)
{
Bitmap theImage = (Bitmap) data.getExtras().get("data");
iv.setImageBitmap(theImage);
}
}
}
LogCat:
11-16 18:30:14.366: E/AndroidRuntime(1522): FATAL EXCEPTION: main
11-16 18:30:14.366: E/AndroidRuntime(1522): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.random/com.example.random.FotoMaker}: java.lang.NullPointerException
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1996)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2023)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.ActivityThread.access$600(ActivityThread.java:127)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1174)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.os.Looper.loop(Looper.java:137)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.ActivityThread.main(ActivityThread.java:4503)
11-16 18:30:14.366: E/AndroidRuntime(1522): at java.lang.reflect.Method.invokeNative(Native Method)
11-16 18:30:14.366: E/AndroidRuntime(1522): at java.lang.reflect.Method.invoke(Method.java:511)
11-16 18:30:14.366: E/AndroidRuntime(1522): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
11-16 18:30:14.366: E/AndroidRuntime(1522): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
11-16 18:30:14.366: E/AndroidRuntime(1522): at dalvik.system.NativeStart.main(Native Method)
11-16 18:30:14.366: E/AndroidRuntime(1522): Caused by: java.lang.NullPointerException
11-16 18:30:14.366: E/AndroidRuntime(1522): at com.example.random.FotoMaker.onCreate(FotoMaker.java:27)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.Activity.performCreate(Activity.java:4479)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
11-16 18:30:14.366: E/AndroidRuntime(1522): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960)
11-16 18:30:14.366: E/AndroidRuntime(1522): ... 11 more
testpic.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
It seems that you forget to add testpic button id in your xml layout,Therefore in FotoMaker activity your button btn is null.
Button btn = (Button) findViewById(R.id.testpic); <-- null here
So add button view with id testpic in your testpic.xml layout file.
Button btn = (Button) findViewById(R.id.testpic);
there is no Button called testpic in the layout "testpic"
you need to add a button testpic indide your layout file , otherwise it will return null.
I know that this question is asked a lot of time but the answer is always for a specific code.
So, i am creating a game in which i need to switch between activities and i have tried everything but always my logcat give me that error and emulator says that "Application have Stopped Working ". So please help me to find out the bug.
My code is:
MainActivity.java
package com.example.experiment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView playG=(TextView)findViewById(R.id.playGame);
playG.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
Intent i=new Intent(MainActivity.this,GameActivity.class);
startActivity(i);
}
});
}
}
GameActivity.java
package com.example.experiment;
import android.app.Activity;
import android.os.Bundle;
public class GameActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new Game(this));
}
}
Game.java
package com.example.experiment;
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
public class Game extends View
{
int i=0,j=0;
int hei=0,wid=0,div=0;
int MoUp=0,MoUpDo=0,Rd;
float TouchXU=0,TouchYU=0,TouchXD=0,TouchYD=0;
float CirX,CirY;
int Score=0;
boolean MoveUp=false,Move=false,NextObs=false;
Path Rpath=new Path();
Paint paint=new Paint();
String ScoreStr="";
Random Rand=new Random();
Activity act=new Activity();
GamEnd g=new GamEnd(getContext());
Context context1=act.getApplicationContext();
Intent intent=new Intent();
public Game(Context context)
{
super(context);
}
#Override
public void onDraw(Canvas canvas)
{
Rd=Rand.nextInt(10);
super.onDraw(canvas);
paint.setAntiAlias(true);
setBackgroundColor(Color.parseColor("#3E8E21"));
MainPath(canvas);
Obstacle1(canvas);
Ball(canvas);
Scores(canvas);
}
public void Ball(Canvas canvas)
{
CirX=getWidth()/2;
CirY=(getHeight()/2+getHeight()/4);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.FILL);
if(i<9)
{
postInvalidateDelayed(40);
canvas.drawCircle(CirX, CirY+i, 30, paint);
i+=3;
Score+=10;
}
else if(MoveUp==true)
{
if(MoUp<200)
{
postInvalidateDelayed(30);
canvas.drawCircle(CirX, CirY+i-MoUp, 30, paint);
MoUp+=40;
Score+=10;
}
else
{
postInvalidateDelayed(25);
canvas.drawCircle(CirX, CirY+i-j+MoUpDo-MoUp, 30, paint);
MoUpDo+=40;
Score+=10;
if(MoUpDo==200)
{
MoUp=0;
MoUpDo=0;
MoveUp=false;
}
}
}
else
{
postInvalidateDelayed(40);
canvas.drawCircle(CirX, CirY+i-j, 30, paint);
j+=3;
Score+=10;
if(j==9)
{
i=0;
j=0;
}
}
if(hei>=CirY-15 && hei<=CirY+10 && MoveUp==false)
{
Toast.makeText(getContext(), "You Are Out", Toast.LENGTH_LONG).show();
Intent in=new Intent(getContext(),MainActivity.class);
act.startActivity(in);
}
}
public void MainPath(Canvas canvas)
{
paint.setColor(Color.parseColor("#EE874B"));
paint.setStyle(Paint.Style.FILL);
Rpath.moveTo(getWidth()/2-getWidth()/6,0);
Rpath.lineTo(getWidth()/2+getWidth()/6,0);
Rpath.lineTo(getWidth()/2+getWidth()/3,getHeight());
Rpath.lineTo(getWidth()/2-getWidth()/3,getHeight());
Rpath.lineTo(getWidth()/2-getWidth()/6,0);
canvas.drawPath(Rpath, paint);
Rpath.reset();
}
#Override
public boolean onTouchEvent(MotionEvent event)
{
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
TouchXD=(float)event.getRawX();
TouchYD=(float)event.getRawY();
break;
case MotionEvent.ACTION_UP:
TouchXU=(float)event.getRawX();
TouchYU=(float)event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
Move=true;
break;
}
if(TouchYD>TouchYU && Move==true)
{
MoveUp=true;
Move=false;
}
return true;
}
public void Scores(Canvas canvas)
{
paint.setColor(Color.parseColor("#4CB028"));
paint.setTextSize(20);
paint.setTextSkewX((float) 0.1);
paint.setFakeBoldText(true);
ScoreStr=String.valueOf(Score);
canvas.drawText(ScoreStr, 10, 30, paint);
}
public void Obstacle1(Canvas canvas)
{
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(20);
canvas.drawLine(getWidth()/2-getWidth()/6-wid, hei, getWidth()/2+getWidth()/6+wid, hei, paint);
float heiDiv=getHeight()/40;
float widDiv=(getWidth()/3-getWidth()/6)/40;
wid+=widDiv;
hei+=heiDiv;
if(hei>=getHeight())
{
NextObs=true;
hei=0;
wid=0;
Obstacle1(canvas);
}
}
public void ShowEnd(Canvas canvas)
{
setBackgroundColor(Color.parseColor("#003366"));
canvas.drawColor(Color.BLACK);
}
}
My logcat
08-21 08:57:09.647: E/AndroidRuntime(1253): FATAL EXCEPTION: main
08-21 08:57:09.647: E/AndroidRuntime(1253): Process: com.example.experiment, PID: 1253
08-21 08:57:09.647: E/AndroidRuntime(1253): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.experiment/com.example.experiment.GameActivity}: java.lang.NullPointerException
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.os.Handler.dispatchMessage(Handler.java:102)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.os.Looper.loop(Looper.java:136)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.ActivityThread.main(ActivityThread.java:5017)
08-21 08:57:09.647: E/AndroidRuntime(1253): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 08:57:09.647: E/AndroidRuntime(1253): at java.lang.reflect.Method.invoke(Method.java:515)
08-21 08:57:09.647: E/AndroidRuntime(1253): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-21 08:57:09.647: E/AndroidRuntime(1253): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-21 08:57:09.647: E/AndroidRuntime(1253): at dalvik.system.NativeStart.main(Native Method)
08-21 08:57:09.647: E/AndroidRuntime(1253): Caused by: java.lang.NullPointerException
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
08-21 08:57:09.647: E/AndroidRuntime(1253): at com.example.experiment.Game.<init>(Game.java:31)
08-21 08:57:09.647: E/AndroidRuntime(1253): at com.example.experiment.GameActivity.onCreate(GameActivity.java:12)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.Activity.performCreate(Activity.java:5231)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 08:57:09.647: E/AndroidRuntime(1253): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
08-21 08:57:09.647: E/AndroidRuntime(1253): ... 11 more
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.experiment"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.experiment.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.experiment.GameActivity"
android:label="#string/title_activity_game" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.experiment.GameActivity"/>
</activity>
</application>
</manifest>
Please friends help.
Thanks in advance.
Intent i = new Intent(MainActivity.this, GameActivity.class);
Should be declared after
super.onCreate();
Activity act=new Activity();
Never do this. An activity you instantiate yourself won't be good for anything, including a call to getApplicationContext(). Hence you get the NPE there.
Instead, pass a Context as a parameter to objects and methods that require it, such as your Game class constructor.
I'm trying to run a simple app using volley and a custom header, it builds with no error, I'm running it directly in my smartphone, but when the app start I get the following log:
06-24 16:35:35.653 1380-1380/com.rep E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.rep, PID: 1380
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.rep/com.rep.app.principal.InicioActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getCacheDir(ContextWrapper.java:230)
at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:43)
at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:78)
at com.representemais.app.principal.InicioActivity.<init>(InicioActivity.java:86)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2126)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
that's the InicioActivity:
package com.rep.app.principal;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.rep.R;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class InicioActivity extends SherlockFragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AutenticacaoLocalTask mAutenticacaoLocalTask = new AutenticacaoLocalTask();
mAutenticacaoLocalTask.execute((Void) null);
}
private TextView txtDisplay;
RequestQueue queue = Volley.newRequestQueue(this);
public class AutenticacaoLocalTask extends AsyncTask<Void, Void, Boolean> {
#Override
protected Boolean doInBackground(Void... params) {
try {
txtDisplay = (TextView) findViewById(R.id.txtDisplay);
String url = "http://192.168.1.15/rep-api/api/clients";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
txtDisplay.setText("Response => "+response.toString());
findViewById(R.id.progressBar1).setVisibility(View.GONE);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Error: " + error.getMessage());
}
})
{
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-API-TOKEN", "99KI9Gj68CgCf70deM22Ka64chef2C40Gm2lFJ2J0G9JkD0bDAcbFfd19MfacGf3FFm8CM1hG0eDiIk8");
return headers;
}
};
queue.add(jsonObjReq);
return true;
} catch (Exception e) {
Log.e("RM", e.getMessage());
return false;
}
}
#Override
protected void onPostExecute(final Boolean success) {
}
#Override
protected void onCancelled() {
}
}
}
and the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rep"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".app.principal.InicioActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".app.login.LoginActivity"
android:configChanges="keyboardHidden"
android:label="#string/app_name">
</activity>
<activity
android:name=".app.principal.MainActivity"
android:label="#string/app_name"></activity>
<activity android:name=".app.cliente.ClienteDetalheActivity"
android:label="#string/app_name"></activity>
<activity android:name=".app.login.LoginTelaBloqueada"
android:label="#string/app_name"></activity>
</application>
</manifest>
Initialize your RequestQueue, using Volley.newRequestQueue(this);, in onCreate() after the super.onCreate() call. You are trying to use your Activity from an initializer, which frequently causes problems like this.
Step #1: Replace:
RequestQueue queue = Volley.newRequestQueue(this);
with:
RequestQueue queue = null;
Step #2: Change your onCreate() to be:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
queue=Volley.newRequestQueue(this);
AutenticacaoLocalTask mAutenticacaoLocalTask = new AutenticacaoLocalTask();
mAutenticacaoLocalTask.execute((Void) null);
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I know I have already asked this question but no one answered after the first answer which I changed what he told me and still no result
HOME.java
package com.example.decrypter;
import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;
public class Home extends Activity implements OnItemSelectedListener {
Button btn_start,btn_about,btn_exit;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
btn_start = (Button) findViewById(R.id.btn_start);
btn_about = (Button) findViewById(R.id.btn_about);
btn_exit = (Button) findViewById(R.id.btn_exit);
btn_start.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
Intent start = new Intent(Home.this, MainPage.class);
Home.this.startActivity(start);
}
});
btn_about.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
Intent about = new Intent(Home.this, about.class);
Home.this.startActivity(about);
}
});
btn_exit.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.home, menu);
return true;
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
MainPage.java
package com.example.decrypter;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
public class MainPage extends Activity implements OnItemSelectedListener {
double random1,random2,random3,random4,random5;
int check1,check2,check3,check4,check5;
EditText textbox;
int guess;
String s1,s2,s3,s4,s5;
Spinner spinner1,spinner2,spinner3,spinner4,spinner5;
TextView display1,display2,display3,display4,display5;
Integer[] numbers = {1,2,3,4,5,6,7,8,9};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter <Integer> adapter1 = new ArrayAdapter <Integer>(this,
android.R.layout.simple_spinner_item, numbers);
setContentView(R.layout.activity_main_page);
spinner1 =(Spinner) findViewById(R.id.spinner01);
spinner2= (Spinner) findViewById(R.id.spinner02);
spinner3= (Spinner) findViewById(R.id.spinner03);
spinner4= (Spinner) findViewById(R.id.spinner04);
spinner5= (Spinner) findViewById(R.id.spinner05);
display1 = (TextView) findViewById(R.id.txtdisplay1);
display2 = (TextView) findViewById(R.id.txtdisplay2);
display3 = (TextView) findViewById(R.id.txtdisplay3);
display4 = (TextView) findViewById(R.id.txtdisplay4);
display5 = (TextView) findViewById(R.id.txtdisplay5);
Button btnrandom = (Button) findViewById(R.id.btnrandom);
Button btn1 = (Button) findViewById(R.id.btn1);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(this);
spinner2.setAdapter(adapter1);
spinner2.setOnItemSelectedListener(this);
spinner3.setAdapter(adapter1);
spinner3.setOnItemSelectedListener(this);
spinner4.setAdapter(adapter1);
spinner4.setOnItemSelectedListener(this);
spinner5.setAdapter(adapter1);
spinner5.setOnItemSelectedListener(this);
btnrandom.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
random1 = Math.floor(Math.random()*10);
random2 = Math.floor(Math.random()*10);
random3 = Math.floor(Math.random()*10);
random4 = Math.floor(Math.random()*10);
random5 = Math.floor(Math.random()*10);
//display.setText("random:" + random1);
/*check1 = Integer.parseInt(spinner1.getSelectedItem().toString()) ;
*/
}
});
btn1.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
if(check1==random1){
display1.setTextColor(Color.GREEN);
s1= Integer.toString(check1);
display1.setText(s1);
}
else{
display1.setTextColor(Color.RED);
s1= Integer.toString(check1);
display1.setText(s1);
}
if(check2==random2){
display2.setTextColor(Color.GREEN);
s2= Integer.toString(check2);
display2.setText(s2);
}
else{
display2.setTextColor(Color.RED);
s2= Integer.toString(check2);
display2.setText(s2);
}
if(check3==random3){
display3.setTextColor(Color.GREEN);
s3= Integer.toString(check3);
display3.setText(s3);
}
else{
display3.setTextColor(Color.RED);
s3= Integer.toString(check3);
display3.setText(s3);
}
if(check4==random4){
display4.setTextColor(Color.GREEN);
s4= Integer.toString(check4);
display4.setText(s4);
}
else{
display4.setTextColor(Color.RED);
s4= Integer.toString(check4);
display4.setText(s4);
}
if(check5==random5){
display5.setTextColor(Color.GREEN);
s5= Integer.toString(check5);
display5.setText(s5);
}
else{
display5.setTextColor(Color.RED);
s5= Integer.toString(check5);
display5.setText(s5);
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.activity_main_page, menu);
return true;
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
check1 = Integer.parseInt(spinner1.getSelectedItem().toString());
check2 = Integer.parseInt(spinner2.getSelectedItem().toString()) ;
check3 = Integer.parseInt(spinner3.getSelectedItem().toString()) ;
check4 = Integer.parseInt(spinner4.getSelectedItem().toString()) ;
check5 = Integer.parseInt(spinner5.getSelectedItem().toString()) ;
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Splash.java
package com.example.decrypter;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer splashSong;
#Override
protected void onCreate(Bundle splashpage) {
// TODO Auto-generated method stub
super.onCreate(splashpage);
setContentView(R.layout.splash);
splashSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
splashSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openHome = new Intent
("com.example.decrypter.HOME");
startActivity(openHome);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
//splashSong.release();
finish();
}
}
Android Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.decrypter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Home"
android:label="#string/title_activity_home" >
<intent-filter>
<action android:name="com.example.decrypter.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".about"
android:label="about" >
<intent-filter>
<action android:name="com.example.decrypter.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainPage"
android:label="MainPage" >
<intent-filter>
<action android:name="com.example.decrypter.MAINPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
LOGCAT ERROR
12-11 11:36:27.182: D/dalvikvm(336): GC_EXTERNAL_ALLOC freed 55K, 53% free 2570K/5379K, external 2131K/2137K, paused 53ms
12-11 11:36:27.271: D/AndroidRuntime(336): Shutting down VM
12-11 11:36:27.271: W/dalvikvm(336): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-11 11:36:27.291: E/AndroidRuntime(336): FATAL EXCEPTION: main
12-11 11:36:27.291: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.decrypter/com.example.decrypter.Home}: java.lang.ClassCastException: android.widget.RelativeLayout
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.os.Looper.loop(Looper.java:123)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-11 11:36:27.291: E/AndroidRuntime(336): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 11:36:27.291: E/AndroidRuntime(336): at java.lang.reflect.Method.invoke(Method.java:507)
12-11 11:36:27.291: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-11 11:36:27.291: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-11 11:36:27.291: E/AndroidRuntime(336): at dalvik.system.NativeStart.main(Native Method)
12-11 11:36:27.291: E/AndroidRuntime(336): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
12-11 11:36:27.291: E/AndroidRuntime(336): at com.example.decrypter.Home.onCreate(Home.java:23)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-11 11:36:27.291: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-11 11:36:27.291: E/AndroidRuntime(336): ... 11 more
First, try cleaning your project (e.g., Project > Clean from the Eclipse main menu). If that does not help, you have a RelativeLayout in activity_main_page.xml that has the wrong android:id value, apparently. Which ID it is using would be based on line 23 of your Home.java class, whichever line that is.
you don't deserve but:
12-11 11:36:27.291: E/AndroidRuntime(336): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
12-11 11:36:27.291: E/AndroidRuntime(336): at com.example.decrypter.Home.onCreate(Home.java:23)
that means... on com.example.decrypter.Home.OnCreate, on line 23 you're casting something to RelativeLayout, and it's NOT a relative layout!
learn to read, you must, young padwan!