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.
Related
I'm trying to develop a simple 2D game using libgdx in Android Studio (0.8.14), but at this point (just with a splash and an empty menu) I'm getting an error, with this LogCat output, when I launch the app (I'm testing on device, Sony Xperia Z1):
12-02 18:01:52.146 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ Late-enabling CheckJNI
12-02 18:01:52.196 24248-24248/com.ak.thesoccerball.android W/ActivityThread﹕ Application com.ak.thesoccerball.android can be debugged on port 8100...
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ Trying to load lib /data/app-lib/com.ak.thesoccerball.android-1/libgdx.so 0x447c06f0
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ Added shared lib /data/app-lib/com.ak.thesoccerball.android-1/libgdx.so 0x447c06f0
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/dalvikvm﹕ No JNI_OnLoad found in /data/app-lib/com.ak.thesoccerball.android-1/libgdx.so 0x447c06f0, skipping init
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android W/dalvikvm﹕ Exception Ljava/lang/NullPointerException; thrown while initializing Lcom/ak/thesoccerball/AKGame;
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android D/AndroidRuntime﹕ Shutting down VM
12-02 18:01:52.246 24248-24248/com.ak.thesoccerball.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41618d88)
12-02 18:01:52.256 24248-24248/com.ak.thesoccerball.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ak.thesoccerball.android, PID: 24248
java.lang.ExceptionInInitializerError
at com.ak.thesoccerball.android.AndroidLauncher.onCreate(AndroidLauncher.java:17)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
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:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.ak.thesoccerball.AKGame.<clinit>(AKGame.java:9)
at com.ak.thesoccerball.android.AndroidLauncher.onCreate(AndroidLauncher.java:17)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
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:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
The classes involved are as follows:
- AndroidLauncher.java
package com.ak.thesoccerball.android;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.ak.thesoccerball.AKGame;
public class AndroidLauncher extends AndroidApplication {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useAccelerometer = false;
config.useCompass = false;
initialize(new AKGame(), config);
}
}
AKGame.java
package com.ak.thesoccerball;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class AKGame extends Game {
public static final int WIDTH = Gdx.graphics.getWidth();
public static final int HEIGHT = Gdx.graphics.getHeight();
public SpriteBatch batch;
#Override
public void create() {
batch = new SpriteBatch();
setScreen(new SplashScreen(this));
}
public void render() {
super.render(); //important!
}
public void dispose() {
batch.dispose();
}
}
And here's the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ak.thesoccerball.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.ak.thesoccerball.android.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What am I missing so hard?
Move this code:
public static final int WIDTH = Gdx.graphics.getWidth();
public static final int HEIGHT = Gdx.graphics.getHeight();
into the create() method, for example:
#Override
public void create() {
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();
//..
}
The thing is that before the create method gets called the Gdx is still null and cannot be used yet.
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.
We are trying to draw something with the scene2D from libGDX. We have our main activity then use the extends Androidapplication to initialize our testgame class. Here we define our screen and then make our stage and actors in the screen class.
Problem is that we are getting the same error over and over:
>
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gamepadTest.app/com.gamepadTest.app.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.gamepadTest.app/com.gamepadTest.app.TestGame}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gamepadTest.app.MainActivity" on path: DexPathList[[zip file "/data/app/com.gamepadTest.app-1.apk"],nativeLibraryDirectories=[/data/app- lib/com.gamepadTest.app-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Have a look:
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class MainActivity extends AndroidApplication {
private TestGame testGame = new TestGame();
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
initialize(testGame, cfg);
}
}
import com.badlogic.gdx.Game;
public class TestGame extends Game
{
TestScreen testScreen;
#Override
public void create() {
testScreen = new TestScreen();
setScreen(testScreen);
}
#Override
public void dispose() {
testScreen.dispose();
}
}
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.Stage;
public class TestScreen implements Screen {
private Stage stage;
private TestActor testActor;
public TestScreen() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
testActor = new TestActor();
stage.addActor(testActor);
}
public void resize(int width, int height) {
stage.setViewport(800, 600, false);
stage.getCamera().translate(-stage.getGutterWidth(), -stage.getGutterHeight(), 0);
}
#Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
#Override public void dispose() {
stage.dispose();
}
#Override public void show() {}
#Override public void hide() {}
#Override public void pause() {}
#Override public void resume() {}
}
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class TestActor extends Actor{
private ShapeRenderer renderer;
#Override
public void act(float delta) {
super.act(delta);
renderer = new ShapeRenderer();
}
#Override
public void draw (SpriteBatch batch, float parentAlpha) {
batch.end();
renderer.setProjectionMatrix(batch.getProjectionMatrix());
renderer.setTransformMatrix(batch.getTransformMatrix());
renderer.translate(getX(), getY(), 0);
renderer.begin(ShapeRenderer.ShapeType.Point);
renderer.rect(0, 0, 100, 100);
renderer.end();
batch.begin();
}
}
UPDATE:
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gamepadTest.app"
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.gamepadTest.app.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>
</application>
</manifest>
You have to declare your activity TestGame inside your AndroidManifest.xml as <activity>
For more info about the manifest: http://developer.android.com/guide/topics/manifest/manifest-intro.html
Should look something like this, and needs to be inside the <application>-tag:
<activity
android:name="com.example.TestGame"
android:label="#string/app_name" >
</activity>
TestGame isn't an Activity:
public class TestGame extends Game{
The Activity you must declare is MainActivity. So its wierd, probably you made another Activity with that same name. But anyway, try setting it with dot notation instead of the whole package:
<activity
android:name=".TestGame"
android:label="#string/app_name" >
</activity>
See this:
Unable to find explicit activity class
I'm new to android development. This is a camera app and it has no compilation errors. But when is run it on the emulator it won't work. It gives "unfortunately preview has stopped". Then I test it on a phone which has "android 2.3.6" os, then also gives an error "The application Preview (process com.example.preview) has stopped unexpectedly. Please try again"
MainActivity.java
package com.rrd.perview;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
//import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
public class MainActivity extends Activity {
private static final String TAG = "CameraDemo";
Camera camera;
Preview preview;
Button buttonClick;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
preview = new Preview(this);
((FrameLayout) findViewById(R.id.preview)).addView(preview);
buttonClick = (Button) findViewById(R.id.buttonClick);
buttonClick.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
});
Log.d(TAG, "onCreate'd");
}
ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() {
// TODO Auto-generated method stub
Log.d(TAG,"onShutter'd");
}
};
PictureCallback rawCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
// TODO Auto-generated method stub
Log.d(TAG, "onPictureTaken - raw");
}
};
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
// TODO Auto-generated method stub
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
}
Log.d(TAG, "onPictureTaken - jpeg");
}
};
}
Preview.java
package com.rrd.perview;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
//import android.R.color;
//import android.R.string;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.CameraInfo;
import android.os.Build;
//import android.os.Environment;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
class Preview extends SurfaceView implements SurfaceHolder.Callback{
private static final String TAG = "Preview";
SurfaceHolder mHolder;
public Camera camera;
//#SuppressWarnings("deprecation")
Preview (Context context){
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
//mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
#TargetApi(Build.VERSION_CODES.GINGERBREAD)
#Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
Camera.open(CameraInfo.CAMERA_FACING_BACK);
try {
camera.setPreviewDisplay(holder);
camera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
// TODO Auto-generated method stub
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg",System.currentTimeMillis()));
outStream.write(data);
outStream.close();
Log.d(TAG,"onPreviewFrame - wrote bytes: "+ data.length);
} catch(FileNotFoundException e){
e.printStackTrace();
} catch(IOException e){
e.printStackTrace();
}finally{
}
Preview.this.invalidate();
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera = null;
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// TODO Auto-generated method stub
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(w, h);
camera.setParameters(parameters);
camera.startPreview();
}
public void drow(Canvas canvas){
super.draw(canvas);
Paint p = new Paint(Color.RED);
Log.d(TAG, "drow");
canvas.drawText("Preview",canvas.getWidth()/2,canvas.getHeight()/2, p);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<FrameLayout android:id="#+id/preview"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonClick"
android:text="Click" android:layout_gravity="center">
</Button>
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rrd.perview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.rrd.perview.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>
</application>
</manifest>
LogCat
11-20 05:02:23.974: D/CameraDemo(1075): onCreate'd
11-20 05:02:24.804: D/AndroidRuntime(1075): Shutting down VM
11-20 05:02:24.804: W/dalvikvm(1075): threadid=1: thread exiting with uncaught exception (group=0xb1b0ab90)
11-20 05:02:24.884: E/AndroidRuntime(1075): FATAL EXCEPTION: main
11-20 05:02:24.884: E/AndroidRuntime(1075): Process: com.rrd.perview, PID: 1075
11-20 05:02:24.884: E/AndroidRuntime(1075): java.lang.NullPointerException
11-20 05:02:24.884: E/AndroidRuntime(1075): at com.rrd.perview.Preview.surfaceCreated(Preview.java:43)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.SurfaceView.updateWindow(SurfaceView.java:572)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.SurfaceView.access$000(SurfaceView.java:86)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1869)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.Choreographer.doFrame(Choreographer.java:532)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.os.Handler.handleCallback(Handler.java:733)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.os.Handler.dispatchMessage(Handler.java:95)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.os.Looper.loop(Looper.java:137)
11-20 05:02:24.884: E/AndroidRuntime(1075): at android.app.ActivityThread.main(ActivityThread.java:4998)
11-20 05:02:24.884: E/AndroidRuntime(1075): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 05:02:24.884: E/AndroidRuntime(1075): at java.lang.reflect.Method.invoke(Method.java:515)
11-20 05:02:24.884: E/AndroidRuntime(1075): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-20 05:02:24.884: E/AndroidRuntime(1075): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-20 05:02:24.884: E/AndroidRuntime(1075): at dalvik.system.NativeStart.main(Native Method)
11-20 05:03:03.864: I/Process(1075): Sending signal. PID: 1075 SIG: 9
What is your question? What have you tried so far?
Couple of points to keep in mind:
when using camera, you need to declare "android.permission.CAMERA" in your manifest - haven't seen that in yours
you have java.lang.NullPointerException, please check which line is causing
in your surfaceCreated(), you are doing this:
Camera.open(CameraInfo.CAMERA_FACING_BACK);
and then you're using camera object, which is not initialised! Change the above to:
camera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
and check for RuntimeException, which you might get if opening camera fails.
Please check Android Training class regarding camera controlling:
http://developer.android.com/training/camera/cameradirect.html
I'm studyng from the book beginning android games opengl es for android.
I recreated an application to test some of the book's notions, based on his previous examples: here is the code
package com.badlogic.androidgames.glbasics;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class OpenGLBasicsStarter extends ListActivity {
String tests[] = { "GLSurfaceViewTest", "GLGameTest" };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, tests));
}
#Override
protected void onListItemClick(ListView list, View view, int position,
long id) {
super.onListItemClick(list, view, position, id);
String testName = tests[position];
try {
Class clazz = Class
.forName("com.badlogic.androidgames.framework.glbasics." + testName);
Intent intent = new Intent(this, clazz);
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
As you could see, it creates a list of others activities with the list of names reported in the tests array. Now: here there are the codes of the 2 activities:
package com.badlogic.androidgames.glbasics;
import java.util.Random;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
public class GLSurfaceViewTest extends Activity {
GLSurfaceView glView;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
glView = new GLSurfaceView(this);
glView.setRenderer(new SimpleRenderer());
setContentView(glView);
}
#Override
public void onResume() {
super.onPause();
glView.onResume();
}
#Override
public void onPause() {
super.onPause();
glView.onPause();
}
static class SimpleRenderer implements Renderer {
Random rand = new Random(); //crea i numeri random
#Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Log.d("GLSurfaceViewTest", "surface created");
}
#Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
Log.d("GLSurfaceViewTest", "surface changed: " + width + "x"
+ "height");
}
#Override
public void onDrawFrame(GL10 gl) {
gl.glClearColor(rand.nextFloat(), rand.nextFloat(),
rand.nextFloat(), 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
}
}
and
package com.badlogic.androidgames.glbasics;
import java.util.Random;
import javax.microedition.khronos.opengles.GL10;
import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Screen;
import com.badlogic.androidgames.framework.impl.GLGame;
import com.badlogic.androidgames.framework.impl.GLGraphics;
public class GLGameTest extends GLGame {
#Override
public Screen getStartScreen() {
return new TestScreen(this);
}
class TestScreen extends Screen {
GLGraphics glGraphics;
Random rand = new Random();
public TestScreen(Game game) {
super(game);
glGraphics = ((GLGame) game).getGLGraphics();
}
#Override
public void present(float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClearColor(rand.nextFloat(), rand.nextFloat(),
rand.nextFloat(), 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
#Override
public void update(float deltaTime) {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
#Override
public void dispose() {
}
}
}
also, there is the XML manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.badlogic.androidgames.glbasics"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="GL"
android:debuggable="true"
android:theme="#style/AppTheme" >
<activity
android:label="GL Surface View Test"
android:name=".GLSurfaceViewTest"
android:configChanges="keyboard|keyboardHidden|orientation" />
<activity
android:label="GL Game Test"
android:name=".GLGameTest"
android:configChanges="keyboard|keyboardHidden|orientation" />
<activity
android:name=".OpenGLBasicsStarter"
android:label="OpenGL Basics Starter"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>
Now: when i start the application, evertyhing seems to be fine: it appaers a list with the 2 activities; but when i try to click one, a message appaers on the logcat:
02-01 16:10:20.540: W/System.err(394): java.lang.ClassNotFoundException: com.badlogic.androidgames.framework.glbasics.GLGameTest
02-01 16:10:20.550: W/System.err(394): at java.lang.Class.classForName(Native Method)
02-01 16:10:20.550: W/System.err(394): at java.lang.Class.forName(Class.java:234)
02-01 16:10:20.550: W/System.err(394): at java.lang.Class.forName(Class.java:181)
02-01 16:10:20.550: W/System.err(394): at com.badlogic.androidgames.glbasics.OpenGLBasicsStarter.onListItemClick(OpenGLBasicsStarter.java:26)
02-01 16:10:20.550: W/System.err(394): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
02-01 16:10:20.550: W/System.err(394): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-01 16:10:20.550: W/System.err(394): at android.widget.ListView.performItemClick(ListView.java:3513)
02-01 16:10:20.550: W/System.err(394): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
02-01 16:10:20.550: W/System.err(394): at android.os.Handler.handleCallback(Handler.java:587)
02-01 16:10:20.550: W/System.err(394): at android.os.Handler.dispatchMessage(Handler.java:92)
02-01 16:10:20.550: W/System.err(394): at android.os.Looper.loop(Looper.java:123)
02-01 16:10:20.550: W/System.err(394): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-01 16:10:20.550: W/System.err(394): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 16:10:20.550: W/System.err(394): at java.lang.reflect.Method.invoke(Method.java:507)
02-01 16:10:20.550: W/System.err(394): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-01 16:10:20.550: W/System.err(394): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-01 16:10:20.550: W/System.err(394): at dalvik.system.NativeStart.main(Native Method)
02-01 16:10:20.560: W/System.err(394): Caused by: java.lang.NoClassDefFoundError: com.badlogic.androidgames.framework.glbasics.GLGameTest
02-01 16:10:20.560: W/System.err(394): ... 17 more
02-01 16:10:20.560: W/System.err(394): Caused by: java.lang.ClassNotFoundException: com.badlogic.androidgames.framework.glbasics.GLGameTest in loader dalvik.system.PathClassLoader[/mnt/asec/com.badlogic.androidgames.glbasics-1/pkg.apk]
02-01 16:10:20.560: W/System.err(394): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-01 16:10:20.560: W/System.err(394): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-01 16:10:20.560: W/System.err(394): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-01 16:10:20.560: W/System.err(394): ... 17 more
There must be an error on the nomenclature of the packages or classes, but i can't see anything. so where is the problem? Sometimes ago I created a similiar (radically identical) application previously to test other things and i never had errors, so...?
Exception states you're searching for com.badlogic.androidgames.framework.glbasics
Note the "framework"
This is how you're defining your class, where the exception originates...
Class clazz = Class.forName("com.badlogic.androidgames.framework.glbasics." + testName);
But all your classes are....
package com.badlogic.androidgames.glbasics;
No "framework"
Check for your package declaration:
In your classes you have:
package com.badlogic.androidgames.glbasics;
While in the error you posted you need something like:
com.badlogic.androidgames.framework.glbasics.GLGameTest