Adding Model Class to Generic List throws error - java

I'm new to Android development and cant work out the issue here. I create a blank class called video with two properties name and url:
public class Video {
public String _name;
public String _Url;
public Video(String name, String Url)
{
_name = name;
_Url = Url;
}
public String getName()
{
return _name;
}
public String getUrl()
{
return _Url;
}
}
I then have a generic list for adding videos to in an activity calls VideosListActivity, the error is being thrown when i add the video to the list:
public List<Video> ListResult;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Update view
setContentView(R.layout.videos);
setTitle("VIDEOS");
//--videos created here
Video NewVideo = new Video("video one","http://www.youtube.com/watch?v=cxLG2wtE7TM");
ListResult.add(NewVideo);
Log.v("VideoList", "Opened list");
this error is what is thrown:
02-06 13:10:05.660: E/AndroidRuntime(23432): FATAL EXCEPTION: main
02-06 13:10:05.660: E/AndroidRuntime(23432): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.mosquitodigital.panic/uk.co.mosquitodigital.panic.VideoListActivity}: java.lang.NullPointerException
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2260)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.ActivityThread.access$600(ActivityThread.java:139)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.os.Looper.loop(Looper.java:156)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.ActivityThread.main(ActivityThread.java:5045)
02-06 13:10:05.660: E/AndroidRuntime(23432): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 13:10:05.660: E/AndroidRuntime(23432): at java.lang.reflect.Method.invoke(Method.java:511)
02-06 13:10:05.660: E/AndroidRuntime(23432): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-06 13:10:05.660: E/AndroidRuntime(23432): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-06 13:10:05.660: E/AndroidRuntime(23432): at dalvik.system.NativeStart.main(Native Method)
02-06 13:10:05.660: E/AndroidRuntime(23432): Caused by: java.lang.NullPointerException
02-06 13:10:05.660: E/AndroidRuntime(23432): at uk.co.mosquitodigital.panic.VideoListActivity.onCreate(VideoListActivity.java:31)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.Activity.performCreate(Activity.java:4543)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
02-06 13:10:05.660: E/AndroidRuntime(23432): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
02-06 13:10:05.660: E/AndroidRuntime(23432): ... 11 more

you will need to initialize ListResult List before adding elements to it as :
public List<Video> ListResult;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Update view
setContentView(R.layout.videos);
ListResult= new ArrayList<Video>(); //<< initialize List here

Related

Null Pointer Exception while setting value of TextView in an Array Adapter class - Android

I'm getting a NullPointerException while trying to start an Activity which contains a ListView .
In the getView method of the adapter class, the exception happens when the setText function of a textView is being called .
The code bellow is my adapter class:
public class QuestionsListAdapter extends ArrayAdapter<Question> {
Context context;
List<Question> questions;
public QuestionsListAdapter(Context context, List<Question> questions){
super(context, R.layout.list_item_question, questions);
this.context = context;
this.questions = questions;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = vi.inflate(R.layout.list_item_question, null);
Question question = questions.get(position);
TextView tv = (TextView) view.findViewById(R.id.question_list_item_string);
Log.i(TableCreator.LOG_TAG, question.toString()); //this works fine and the string is not null .
tv.setText(question.toString()+""); //NULL POINTER EXCEPTION .
return view;
}
}
As you see, I've logged the string in the logcat and it works just fine, but the next line makes the mistake .
And this is the logcat output:
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist I/Operation Checklist﹕ |-Question-> id:1 summary:mySummary comment:myComment solution:mySolution ownerList:dummyOwner
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist D/AndroidRuntime﹕ Shutting down VM
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0f5f648)
05-27 13:24:02.979 5325-5325/org.kabiri.operationcheklist E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at org.kabiri.operationchecklist.adapter.QuestionsListAdapter.getView(QuestionsListAdapter.java:43)
at android.widget.AbsListView.obtainView(AbsListView.java:2177)
at android.widget.ListView.makeAndAddView(ListView.java:1840)
at android.widget.ListView.fillDown(ListView.java:675)
at android.widget.ListView.fillFromTop(ListView.java:736)
at android.widget.ListView.layoutChildren(ListView.java:1655)
at android.widget.AbsListView.onLayout(AbsListView.java:2012)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:14289)
at android.view.ViewGroup.layout(ViewGroup.java:4562)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
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)
The logcat shows that the error happens on this line of my adapter class:
tv.setText(question.toString()+"");
I really appreciate your help .
You already know where the problem is!
tv.setText(question.toString()+"");
is causing the NPE that means the TextView tv is null. And that means that the line
TextView tv = (TextView) view.findViewById(R.id.question_list_item_string);
is not able to find the TextView. Check the question_list_item_string id and make sure it matches the id in your list_item_question.xml file

NullPointerException on MrNom

I was trying to execute Mr Nom(from the book Begining Android Games by Mario Zechner). but it doesn't work. My first atemp was create 2 different projects, one called framework where are com.badlogic.androidgames.framework and com.badlogic.androidgames.framework files and other project called mrnom (com.badlogic.androidgames.mrnom)with the rest of files. the framework project was added mrnom project/java build path/project/add and the result was this:
logcat
11-07 15:21:55.573: W/dalvikvm(641): Unable to resolve superclass of Lcom/badlogic/androidgames/mrnom/MrNom; (445)
11-07 15:21:55.573: W/dalvikvm(641): Link of class 'Lcom/badlogic/androidgames/mrnom/MrNom;' failed
11-07 15:21:55.573: D/AndroidRuntime(641): Shutting down VM
11-07 15:21:55.573: W/dalvikvm(641): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-07 15:21:55.583: E/AndroidRuntime(641): FATAL EXCEPTION: main
11-07 15:21:55.583: E/AndroidRuntime(641): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.badlogic.androidgames.mrnom/com.badlogic.androidgames.mrnom.MrNom}: java.lang.ClassNotFoundException: com.badlogic.androidgames.mrnom.MrNom
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.os.Looper.loop(Looper.java:137)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-07 15:21:55.583: E/AndroidRuntime(641): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 15:21:55.583: E/AndroidRuntime(641): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 15:21:55.583: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-07 15:21:55.583: E/AndroidRuntime(641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-07 15:21:55.583: E/AndroidRuntime(641): at dalvik.system.NativeStart.main(Native Method)
11-07 15:21:55.583: E/AndroidRuntime(641): Caused by: java.lang.ClassNotFoundException: com.badlogic.androidgames.mrnom.MrNom
11-07 15:21:55.583: E/AndroidRuntime(641): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-07 15:21:55.583: E/AndroidRuntime(641): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-07 15:21:55.583: E/AndroidRuntime(641): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
11-07 15:21:55.583: E/AndroidRuntime(641): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
11-07 15:21:55.583: E/AndroidRuntime(641): ... 11 more
11-07 15:24:06.602: E/Trace(662): error opening trace file: No such file or directory (2)
11-07 15:24:06.902: W/dalvikvm(662): Unable to resolve superclass of Lcom/badlogic/androidgames/mrnom/MrNom; (445)
11-07 15:24:06.902: W/dalvikvm(662): Link of class 'Lcom/badlogic/androidgames/mrnom/MrNom;' failed
11-07 15:24:06.902: D/AndroidRuntime(662): Shutting down VM
11-07 15:24:06.932: W/dalvikvm(662): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-07 15:24:06.952: E/AndroidRuntime(662): FATAL EXCEPTION: main
11-07 15:24:06.952: E/AndroidRuntime(662): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.badlogic.androidgames.mrnom/com.badlogic.androidgames.mrnom.MrNom}: java.lang.ClassNotFoundException: com.badlogic.androidgames.mrnom.MrNom
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.os.Looper.loop(Looper.java:137)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-07 15:24:06.952: E/AndroidRuntime(662): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 15:24:06.952: E/AndroidRuntime(662): at java.lang.reflect.Method.invoke(Method.java:511)
11-07 15:24:06.952: E/AndroidRuntime(662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-07 15:24:06.952: E/AndroidRuntime(662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-07 15:24:06.952: E/AndroidRuntime(662): at dalvik.system.NativeStart.main(Native Method)
11-07 15:24:06.952: E/AndroidRuntime(662): Caused by: java.lang.ClassNotFoundException: com.badlogic.androidgames.mrnom.MrNom
11-07 15:24:06.952: E/AndroidRuntime(662): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-07 15:24:06.952: E/AndroidRuntime(662): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-07 15:24:06.952: E/AndroidRuntime(662): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
11-07 15:24:06.952: E/AndroidRuntime(662): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
11-07 15:24:06.952: E/AndroidRuntime(662): ... 11 more
later I removed the framework from mrnom and added it using a jar file, the result was the same
Now, I copy the com.badlogic.androidgames.framework and com.badlogic.androidgames.framework files into mr project then I have com.badlogic.androidgames.mrnom, com.badlogic.androidgames.framework and com.badlogic.androidgames.framework in the same project but now the error is
logcat
12-05 15:42:43.510: D/dalvikvm(582): GC_EXTERNAL_ALLOC freed 57K, 53% free 2569K/5379K, external 1925K/2137K, paused 239ms
12-05 15:42:43.860: D/dalvikvm(582): GC_EXTERNAL_ALLOC freed 3K, 53% free 2569K/5379K, external 2515K/2701K, paused 36ms
12-05 15:42:44.100: W/dalvikvm(582): threadid=11: thread exiting with uncaught exception (group=0x40015560)
12-05 15:42:44.100: E/AndroidRuntime(582): FATAL EXCEPTION: Thread-12
12-05 15:42:44.100: E/AndroidRuntime(582): java.lang.NullPointerException
12-05 15:42:44.100: E/AndroidRuntime(582): at com.badlogic.androidgames.mrnom.Settings.load(Settings.java:18)
12-05 15:42:44.100: E/AndroidRuntime(582): at com.badlogic.androidgames.mrnom.LoadingScreen.update(LoadingScreen.java:41)
12-05 15:42:44.100: E/AndroidRuntime(582): at com.badlogic.androidgames.framework.impl.AndroidFastRenderView.run(AndroidFastRenderView.java:36)
12-05 15:42:44.100: E/AndroidRuntime(582): at java.lang.Thread.run(Thread.java:1019)
Settings
package com.badlogic.androidgames.mrnom;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import com.balogic.androidgames.framework.FileIO;
public class Settings {
public static boolean soundEnable=true;
public static int[] highscores=new int[]{100,80,50,30,10};
public static void load(FileIO files){
BufferedReader in=null;
try{
in=new BufferedReader(new InputStreamReader(files.readFile(".mrnom")));// line 18 error here
soundEnable=Boolean.parseBoolean(in.readLine());
for(int i=0; i<5;i++){
highscores[i]=Integer.parseInt(in.readLine());
}
}catch(IOException e){
// :( vale,trabajamos con valores predeterminados
}catch(NumberFormatException e){
// :/ vale, estos valores nos han salvado el día
}finally{
try{
if(in!=null)
in.close();
}catch(IOException e){
//nada
}
}
}
public static void save(FileIO files){
BufferedWriter out=null;
try{
out=new BufferedWriter(new OutputStreamWriter(files.writeFile(".mrnom")));
out.write(Boolean.toString(soundEnable));
for(int i=0; i<5; i++){
out.write(Integer.toString(highscores[i]));
}
}catch(IOException e){
//nada
}finally{
try{
if(out!=null)
out.close();
}catch(IOException e){
//nada
}
}
}
public static void addScore(int score){
for(int i=0;i<5;i++){
if(highscores[i]<score){
for(int j=4;j>i;j--)
highscores[j]=highscores[j-1];
highscores[i]=score;
break;
}
}
}
}
Loadingsceen
package com.badlogic.androidgames.mrnom;
import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Graphics;
import com.badlogic.androidgames.framework.Graphics.PixmapFormat;
import com.badlogic.androidgames.framework.Screen;
public class LoadingScreen extends Screen{
public LoadingScreen(Game game){
super(game);
}
#Override
public void update(float deltaTime){
Graphics g=game.getGraphics();
Assets.background = g.newPixmap("background.png", PixmapFormat.RGB565);
Assets.logo = g.newPixmap("logo.png", PixmapFormat.ARGB4444);
Assets.mainMenu = g.newPixmap("mainmenu.png", PixmapFormat.ARGB4444);
Assets.buttons = g.newPixmap("buttons.png", PixmapFormat.ARGB4444);
Assets.help1 = g.newPixmap("help1.png", PixmapFormat.ARGB4444);
Assets.help2 = g.newPixmap("help2.png", PixmapFormat.ARGB4444);
Assets.help3 = g.newPixmap("help3.png", PixmapFormat.ARGB4444);
Assets.numbers = g.newPixmap("numbers.png", PixmapFormat.ARGB4444);
Assets.ready = g.newPixmap("ready.png", PixmapFormat.ARGB4444);
Assets.pause = g.newPixmap("pausemenu.png", PixmapFormat.ARGB4444);
Assets.gameOver = g.newPixmap("gameover.png", PixmapFormat.ARGB4444);
Assets.headUp = g.newPixmap("headup.png", PixmapFormat.ARGB4444);
Assets.headLeft = g.newPixmap("headleft.png", PixmapFormat.ARGB4444);
Assets.headDown = g.newPixmap("headdown.png", PixmapFormat.ARGB4444);
Assets.headRight = g.newPixmap("headright.png", PixmapFormat.ARGB4444);
Assets.tail = g.newPixmap("tail.png", PixmapFormat.ARGB4444);
Assets.stain1 = g.newPixmap("stain.png", PixmapFormat.ARGB4444);
Assets.stain2 = g.newPixmap("stain2.png", PixmapFormat.ARGB4444);
Assets.stain3 = g.newPixmap("stain3.png", PixmapFormat.ARGB4444);
Assets.click = game.getAudio().newSound("click.ogg");
Assets.eat = game.getAudio().newSound("eat.ogg");
Assets.bitten = game.getAudio().newSound("bitten.ogg");
Settings.load(game.getFileIO()); //line 41 error here
game.setScreen(new MainMenuScreen(game));
}
#Override
public void present(float deltaTime) {
// TODO Auto-generated method stub
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void resume() {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
// TODO Auto-generated method stub
}
}
AndroidFastRenderView
package com.badlogic.androidgames.framework.impl;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class AndroidFastRenderView extends SurfaceView implements Runnable{
AndroidGame game;
Bitmap framebuffer;
Thread renderThread=null;
SurfaceHolder holder;
volatile boolean running=false;
public AndroidFastRenderView(AndroidGame game,Bitmap framebuffer){
super(game);
this.game=game;
this.framebuffer=framebuffer;
this.holder=getHolder();
}
public void resume(){
running=true;
renderThread=new Thread(this);
renderThread.start();
}
public void run(){
Rect dstRect=new Rect();
long startTime=System.nanoTime();
while(running){
if(!holder.getSurface().isValid())
continue;
float deltaTime=(System.nanoTime()-startTime)/1000000000.0f;
startTime=System.nanoTime();
game.getCurrentScreen().update(deltaTime);//line 36 error here
game.getCurrentScreen().present(deltaTime);
Canvas canvas=holder.lockCanvas();
canvas.getClipBounds(dstRect);
canvas.drawBitmap(framebuffer, null, dstRect,null);
holder.unlockCanvasAndPost(canvas);
}
}
public void pause(){
running=false;
while(true){
try{
renderThread.join();
break;
}catch(InterruptedException e){
//vuelve a intentarlo
}
}
}
}
Eclipse doesn't showme any mistake on code but on the emulator just say "Sorry! the application mrnom (process com.badlogic.androidgames.mrnom) has stopped unexpectedly. Please try again"
Can you help me with this? No idea what's happening :( Thank you so much.

Failed to pass value to Method retrieve from another method error : java.util.HashSet cannot be cast to java.lang.String

Here is the code mentioned i am trying to insert values in ArrayList and saving arrayList in Session Storage while key is different everytime.Now my target is to get selected value by passing "position" onclick of Spinner.Here are two mthods that are used to save values in SharePreferences i am getting error while trying to retrieve value from getSpinnerSelectedValue method.
public static void setValuesInSession(Context c,String key,List<String> myArrayList)
{
SharedPreferences sPrefs=PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor sEdit=sPrefs.edit();
Set<String> set = new HashSet<String>();
Log.i("myArrayList SharePrefereces",""+myArrayList +"::key::"+key);
set.addAll(myArrayList);
sEdit.putStringSet(key,set);
sEdit.commit();
}
public static List<String> getValuesOfSession(Context c,String key)
{
SharedPreferences sPrefs=PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor sEdit=sPrefs.edit();
Set<String> set = new HashSet<String>();
set = sPrefs.getStringSet(key,null);
List<String> setList=new ArrayList<String>(set);
return setList;
}
public static void setSpinnerSelectedValue(Context c,String key,String value)
{SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(c);
SharedPreferences.Editor editor=pref.edit();
editor.putString(key,value);
}
public static String getSpinnerSelectedValue(Context c,String key)
{
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(c);
String val = sharedPrefs.getString(key,null);
return val;
}
how i am using this code in Activity:
SessionManager.setValuesInSession(getActivity().getApplicationContext(),menuFieldInstance.getFieldLabel().toString(),[0100,0200,0300,0400,0500]);
siteSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
Log.i("Spinner Selected Value", "" + position);
List<String> arrayList = new ArrayList<String>();
arrayList = SessionManager.getValuesOfSession(getActivity().getApplicationContext(),menuFieldInstance.getFieldLabel());
Log.i("arrayList Values",""+arrayList);
Log.i("arrayList ",""+arrayList.get(position).toString());
SessionManager.setSpinnerSelectedValue(getActivity().getApplicationContext(),menuFieldInstance.getFieldLabel(),arrayList.get(position).toString());
}
getting Error when trying to retrieve values from "getSpinnerSelectedValue" mthod ?
here is the error List:
02-11 02:23:05.455: E/AndroidRuntime(23432): FATAL EXCEPTION: main
02-11 02:23:05.455: E/AndroidRuntime(23432): java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:205)
02-11 02:23:05.455: E/AndroidRuntime(23432): at com.mrfs.android.surveyapp.util.SessionManager.getSpinnerSelectedValue(SessionManager.java:85)
02-11 02:23:05.455: E/AndroidRuntime(23432): at com.mrfs.android.surveyapp.activities.fragments.SiteFragmentActivity$3.onClick(SiteFragmentActivity.java:513)
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.view.View.performClick(View.java:4211)
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.view.View$PerformClick.run(View.java:17267)
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.os.Handler.handleCallback(Handler.java:615)
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.os.Handler.dispatchMessage(Handler.java:92)
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.os.Looper.loop(Looper.java:137)
02-11 02:23:05.455: E/AndroidRuntime(23432): at android.app.ActivityThread.main(ActivityThread.java:4898)
02-11 02:23:05.455: E/AndroidRuntime(23432): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 02:23:05.455: E/AndroidRuntime(23432): at java.lang.reflect.Method.invoke(Method.java:511)
02-11 02:23:05.455: E/AndroidRuntime(23432): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
02-11 02:23:05.455: E/AndroidRuntime(23432): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
02-11 02:23:05.455: E/AndroidRuntime(23432): at dalvik.system.NativeStart.main(Native Method)
onClick of Button i am calling method :
siteSaveButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Log.i("Session Values",SessionManager.getSpinnerSelectedValue(getActivity().getApplicationContext(),"Police Authority"));
}

Android SQLite Database Version, changed structure now cannot view DB

My SQLite database appears to be entering entries fine however I cannot pull them back to view them, everytime I load the activity my app crashes, Changing the database version throws a SQL exception and force closes the app also.
Below is the class where the SQL is handled:
package com.uhi.fatfighter;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Stats {
public static final String KEY_ROWID = "_id";
public static final String KEY_WEIGHT = "weight";
public static final String KEY_WAIST = "waist";
public static final String KEY_CHEST = "chest";
public static final String KEY_LEGS = "legs";
public static final String KEY_ARMS = "arms";
private static final String DATABASE_NAME = "statsDB";
private static final String DATABASE_TABLE = "personalStats";
private static final int DATABASE_VERSION = 3;
private DbHelper ffHelper;
private final Context ffContext;
private SQLiteDatabase ffDatabase;
private static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_WEIGHT
+ " TEXT NOT NULL, " + KEY_WAIST + " TEXT NOT NULL, "
+ KEY_CHEST + " TEXT NOT NULL, " + KEY_LEGS
+ " TEXT NOT NULL, " + KEY_ARMS + " TEXT NOT NULL);");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST " + DATABASE_TABLE);
onCreate(db);
}
}
public Stats(Context c) {
ffContext = c;
}
public Stats open() throws SQLException {
ffHelper = new DbHelper(ffContext);
ffDatabase = ffHelper.getWritableDatabase();
return this;
}
public void close() {
ffHelper.close();
}
public long createEntry(String weight, String waist, String chest, String legs, String arms) {
ContentValues cv = new ContentValues();
cv.put(KEY_WEIGHT, weight);
cv.put(KEY_WAIST, waist);
cv.put(KEY_CHEST, chest);
cv.put(KEY_LEGS, legs);
cv.put(KEY_ARMS, arms);
return ffDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
String[] columns = new String[] { KEY_ROWID, KEY_WEIGHT, KEY_WAIST, KEY_CHEST, KEY_LEGS, KEY_ARMS };
Cursor c = ffDatabase.query(DATABASE_TABLE, columns, null, null, null,
null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iWeight = c.getColumnIndex(KEY_WEIGHT);
int iWaist = c.getColumnIndex(KEY_WAIST);
int iChest = c.getColumnIndex(KEY_CHEST);
int iLegs = c.getColumnIndex(KEY_LEGS);
int iArms = c.getColumnIndex(KEY_ARMS);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result + c.getString(iRow) + " " + c.getString(iWeight)
+ " " + c.getString(iWaist)
+ " " + c.getString(iChest)
+ " " + c.getString(iLegs)
+ " " + c.getString(iArms) + "\n";
}
return result;
}
}
and below is the Activity that calls the SQL handling class:
package com.uhi.fatfighter;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
public class DBView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.view_stats);
TextView tv = (TextView) findViewById(R.id.tvDBInfo);
Stats dbInfo = new Stats(this);
dbInfo.open();
String data = dbInfo.getData();
dbInfo.close();
if (!TextUtils.isEmpty(data)) {
tv.setText(data);
}
}
}
as i said this was working fine until I added some extra fields
Logcat:
05-09 13:44:32.761: E/Trace(7576): error opening trace file: No such file or directory (2)
05-09 13:44:32.894: E/InputDispatcher(1294): channel '415d5068 com.uhi.fatfighter/com.uhi.fatfighter.Splash (server)' ~ Channel is unrecoverably broken and will be disposed!
05-09 13:44:34.964: E/Trace(7593): error opening trace file: No such file or directory (2)
05-09 13:44:34.988: E/Trace(7598): error opening trace file: No such file or directory (2)
05-09 13:44:54.250: E/AndroidRuntime(7598): FATAL EXCEPTION: main
05-09 13:44:54.250: E/AndroidRuntime(7598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uhi.fatfighter/com.uhi.fatfighter.DBView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.os.Looper.loop(Looper.java:137)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.main(ActivityThread.java:4928)
05-09 13:44:54.250: E/AndroidRuntime(7598): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:44:54.250: E/AndroidRuntime(7598): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-09 13:44:54.250: E/AndroidRuntime(7598): at dalvik.system.NativeStart.main(Native Method)
05-09 13:44:54.250: E/AndroidRuntime(7598): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.Activity.setContentView(Activity.java:1867)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.uhi.fatfighter.DBView.onCreate(DBView.java:16)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-09 13:44:54.250: E/AndroidRuntime(7598): ... 11 more
05-09 13:44:56.765: E/Trace(7630): error opening trace file: No such file or directory (2)
05-09 13:45:10.125: E/Trace(7649): error opening trace file: No such file or directory (2)
05-09 13:45:10.433: E/Trace(7664): error opening trace file: No such file or directory (2)
05-09 13:45:11.183: E/Trace(7678): error opening trace file: No such file or directory (2)
05-09 13:45:12.203: E/Trace(7695): error opening trace file: No such file or directory (2)
05-09 13:45:14.187: E/AndroidRuntime(7630): FATAL EXCEPTION: main
05-09 13:45:14.187: E/AndroidRuntime(7630): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uhi.fatfighter/com.uhi.fatfighter.DBView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.os.Looper.loop(Looper.java:137)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.main(ActivityThread.java:4928)
05-09 13:45:14.187: E/AndroidRuntime(7630): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:45:14.187: E/AndroidRuntime(7630): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-09 13:45:14.187: E/AndroidRuntime(7630): at dalvik.system.NativeStart.main(Native Method)
05-09 13:45:14.187: E/AndroidRuntime(7630): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.Activity.setContentView(Activity.java:1867)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.uhi.fatfighter.DBView.onCreate(DBView.java:16)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-09 13:45:14.187: E/AndroidRuntime(7630): ... 11 more
05-09 13:45:18.433: E/Trace(7722): error opening trace file: No such file or directory (2)
05-09 13:52:02.109: E/Trace(7767): error opening trace file: No such file or directory (2)
05-09 13:52:03.554: E/Trace(7781): error opening trace file: No such file or directory (2)
05-09 13:55:06.617: E/Trace(7807): error opening trace file: No such file or directory (2)
05-09 13:55:26.808: E/AndroidRuntime(7807): FATAL EXCEPTION: main
05-09 13:55:26.808: E/AndroidRuntime(7807): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uhi.fatfighter/com.uhi.fatfighter.DBView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.os.Looper.loop(Looper.java:137)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.main(ActivityThread.java:4928)
05-09 13:55:26.808: E/AndroidRuntime(7807): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:55:26.808: E/AndroidRuntime(7807): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-09 13:55:26.808: E/AndroidRuntime(7807): at dalvik.system.NativeStart.main(Native Method)
05-09 13:55:26.808: E/AndroidRuntime(7807): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.Activity.setContentView(Activity.java:1867)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.uhi.fatfighter.DBView.onCreate(DBView.java:16)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-09 13:55:26.808: E/AndroidRuntime(7807): ... 11 more
05-09 13:58:40.242: E/Trace(7828): error opening trace file: No such file or directory (2)
05-09 13:58:40.500: E/Trace(7841): error opening trace file: No such file or directory (2)
05-09 13:58:40.937: E/PhotoDatabaseHelper(7828): query fail: empty cursor: android.database.sqlite.SQLiteCursor#415ae7e8
05-09 13:58:40.937: E/WidgetProvider(7828): cannot load widget: 5
I can see the class is having trouble casting TextView
DROP TABLE IF EXISTS
is the correct syntax.
Your drop query is wrong. EXIST is a wrong keyword.
It should be :
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
The problem lies in the XML file for the SQLITE view, I checked all my TextView fields were set up correctly, they weren't. This fixed the issue.

Unfortunately <appname> has stopped

I have seen many similar questions to this one posted on SO but none seem to answer my question. Quite simply, every time I try and run my app on the emulator, it quits back to the main menu and displays a dialog saying "Unfortunatley, Scribble Runner has stopped". Here is my BaseActivity class and my AndroidManifest.xml file.
BaseActivity:
import java.io.IOException;
import java.io.InputStream;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.adt.io.in.IInputStreamOpener;
import org.andengine.util.debug.Debug;
import android.util.Log;
public class BaseActivity extends SimpleBaseGameActivity {
//CONSTANTS AND FIELDS
public static int CAMERA_WIDTH = 720;
public static int CAMERA_HEIGHT = 480;
public Font mFont;
public Camera mCamera;
private ITextureRegion mBackgroundTextureRegion, mEnemyTextureRegion;
private BitmapTextureAtlas mAutoParallaxBackgroundTexture;
private TextureRegion mParallaxLayerFront;
private TextureRegion mParallaxLayerMid;
private TextureRegion mParallaxLayerBack;
public Scene mCurrentScene;
public static BaseActivity instance;
#Override
public EngineOptions onCreateEngineOptions() {
instance = this;
mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
System.out.println("Engine Created");
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new
RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}
#Override
protected void onCreateResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
try{
this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1024);
this.mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_front.png", 0, 0);
this.mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_back.png", 0, 188);
this.mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_mid.png", 0, 669);
this.mAutoParallaxBackgroundTexture.load();
System.out.println("Resources Created");
}catch(Exception e){
Debug.e(e);
}
}
#Override
protected Scene onCreateScene() {
mEngine.registerUpdateHandler(new FPSLogger());
mCurrentScene = new Scene();
Sprite backgroundSprite1 = new Sprite(0, 0, this.mParallaxLayerBack, getVertexBufferObjectManager());
Sprite backgroundSprite2 = new Sprite(0, 0, this.mParallaxLayerMid, getVertexBufferObjectManager());
Sprite backgroundSprite3 = new Sprite(0, 0, this.mParallaxLayerFront, getVertexBufferObjectManager());
mCurrentScene.attachChild(backgroundSprite1);
mCurrentScene.attachChild(backgroundSprite2);
mCurrentScene.attachChild(backgroundSprite3);
System.out.println("Scene Created");
return mCurrentScene;
}
public static BaseActivity getSharedInstance(){
return instance;
}
//change the current main scene
public void setCurrentScene(Scene scene){
mCurrentScene = scene;
getEngine().setScene(mCurrentScene);
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.provisionalsolutions.scribblerunner"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.provisionalsolutions.scribblerunner.BaseActivity"
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>
And here is the LogCat:
02-06 13:41:21.664: W/ActivityManager(275): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
02-06 13:41:21.674: W/Trace(589): Unexpected value from nativeGetEnabledTags: 0
02-06 13:41:21.697: E/ActivityThread(589): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40cf2458 that was originally bound here
02-06 13:41:21.697: E/ActivityThread(589): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40cf2458 that was originally bound here
02-06 13:41:21.697: E/ActivityThread(589): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
02-06 13:41:21.697: E/ActivityThread(589): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
02-06 13:41:21.697: E/ActivityThread(589): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
02-06 13:41:21.697: E/ActivityThread(589): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
02-06 13:41:21.697: E/ActivityThread(589): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
02-06 13:41:21.697: E/ActivityThread(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
02-06 13:41:21.697: E/ActivityThread(589): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-06 13:41:21.697: E/ActivityThread(589): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-06 13:41:21.697: E/ActivityThread(589): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-06 13:41:21.697: E/ActivityThread(589): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-06 13:41:21.697: E/ActivityThread(589): at java.lang.Thread.run(Thread.java:856)
02-06 13:41:21.714: E/StrictMode(589): null
02-06 13:41:21.714: E/StrictMode(589): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40cf2458 that was originally bound here
02-06 13:41:21.714: E/StrictMode(589): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
02-06 13:41:21.714: E/StrictMode(589): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
02-06 13:41:21.714: E/StrictMode(589): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
02-06 13:41:21.714: E/StrictMode(589): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
02-06 13:41:21.714: E/StrictMode(589): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
02-06 13:41:21.714: E/StrictMode(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
02-06 13:41:21.714: E/StrictMode(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
02-06 13:41:21.714: E/StrictMode(589): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
02-06 13:41:21.714: E/StrictMode(589): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
02-06 13:41:21.714: E/StrictMode(589): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
02-06 13:41:21.714: E/StrictMode(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
02-06 13:41:21.714: E/StrictMode(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
02-06 13:41:21.714: E/StrictMode(589): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-06 13:41:21.714: E/StrictMode(589): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-06 13:41:21.714: E/StrictMode(589): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-06 13:41:21.714: E/StrictMode(589): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-06 13:41:21.714: E/StrictMode(589): at java.lang.Thread.run(Thread.java:856)
02-06 13:41:21.714: W/ActivityManager(275): Unbind failed: could not find connection for android.os.BinderProxy#40e80c68
02-06 13:41:21.724: E/ActivityThread(589): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40d19e88 that was originally bound here
02-06 13:41:21.724: E/ActivityThread(589): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40d19e88 that was originally bound here
02-06 13:41:21.724: E/ActivityThread(589): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
02-06 13:41:21.724: E/ActivityThread(589): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
02-06 13:41:21.724: E/ActivityThread(589): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
02-06 13:41:21.724: E/ActivityThread(589): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
02-06 13:41:21.724: E/ActivityThread(589): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
02-06 13:41:21.724: E/ActivityThread(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
02-06 13:41:21.724: E/ActivityThread(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
02-06 13:41:21.724: E/ActivityThread(589): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
02-06 13:41:21.724: E/ActivityThread(589): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
02-06 13:41:21.724: E/ActivityThread(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
02-06 13:41:21.724: E/ActivityThread(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
02-06 13:41:21.724: E/ActivityThread(589): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-06 13:41:21.724: E/ActivityThread(589): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-06 13:41:21.724: E/ActivityThread(589): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-06 13:41:21.724: E/ActivityThread(589): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-06 13:41:21.724: E/ActivityThread(589): at java.lang.Thread.run(Thread.java:856)
02-06 13:41:21.734: E/StrictMode(589): null
02-06 13:41:21.734: E/StrictMode(589): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40d19e88 that was originally bound here
02-06 13:41:21.734: E/StrictMode(589): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
02-06 13:41:21.734: E/StrictMode(589): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
02-06 13:41:21.734: E/StrictMode(589): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
02-06 13:41:21.734: E/StrictMode(589): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
02-06 13:41:21.734: E/StrictMode(589): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
02-06 13:41:21.734: E/StrictMode(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
02-06 13:41:21.734: E/StrictMode(589): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
02-06 13:41:21.734: E/StrictMode(589): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
02-06 13:41:21.734: E/StrictMode(589): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
02-06 13:41:21.734: E/StrictMode(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
02-06 13:41:21.734: E/StrictMode(589): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
02-06 13:41:21.734: E/StrictMode(589): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-06 13:41:21.734: E/StrictMode(589): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-06 13:41:21.734: E/StrictMode(589): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-06 13:41:21.734: E/StrictMode(589): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-06 13:41:21.734: E/StrictMode(589): at java.lang.Thread.run(Thread.java:856)
here is another part of the stack trace showing errors:
02-06 13:45:37.300: E/AndroidRuntime(815): FATAL EXCEPTION: main
02-06 13:45:37.300: E/AndroidRuntime(815): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.provisionalsolutions.scribblerunner/com.provisionalsolutions.scribblerunner.BaseActivity}: java.lang.ClassNotFoundException: Didn't find class "com.provisionalsolutions.scribblerunner.BaseActivity" on path: /data/app/com.provisionalsolutions.scribblerunner-2.apk
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.os.Looper.loop(Looper.java:137)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-06 13:45:37.300: E/AndroidRuntime(815): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 13:45:37.300: E/AndroidRuntime(815): at java.lang.reflect.Method.invoke(Method.java:511)
02-06 13:45:37.300: E/AndroidRuntime(815): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-06 13:45:37.300: E/AndroidRuntime(815): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-06 13:45:37.300: E/AndroidRuntime(815): at dalvik.system.NativeStart.main(Native Method)
02-06 13:45:37.300: E/AndroidRuntime(815): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.provisionalsolutions.scribblerunner.BaseActivity" on path: /data/app/com.provisionalsolutions.scribblerunner-2.apk
02-06 13:45:37.300: E/AndroidRuntime(815): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-06 13:45:37.300: E/AndroidRuntime(815): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-06 13:45:37.300: E/AndroidRuntime(815): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
02-06 13:45:37.300: E/AndroidRuntime(815): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
02-06 13:45:37.300: E/AndroidRuntime(815): ... 11 more
02-06 13:41:21.664: W/ActivityManager(275): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
02-06 13:41:21.674: W/Trace(589): Unexpected value from nativeGetEnabledTags: 0
this tells you, you have a problem with an intent... in your posted code is no intent, so i think the problem belongs to another part of your program ^^

Categories