when Im trying to add the Google play service to my Libgdx game that errors shows to me, I have no Idea from where to start.
any help?
06-08 00:04:29.626: I/System.out(3668): debugger has settled (1381)
06-08 00:04:29.774: D/dalvikvm(3668): Trying to load lib /data/app-lib/com.alnassre.ffeather.android-1/libgdx.so 0x41ef5348
06-08 00:04:29.782: D/dalvikvm(3668): Added shared lib /data/app-lib/com.alnassre.ffeather.android-1/libgdx.so 0x41ef5348
06-08 00:04:29.782: D/dalvikvm(3668): No JNI_OnLoad found in /data/app-lib/com.alnassre.ffeather.android-1/libgdx.so 0x41ef5348, skipping init
06-08 00:04:30.962: D/dalvikvm(3668): threadid=1: still suspended after undo (sc=1 dc=1)
06-08 00:04:31.532: D/GameHelper(3668): GameHelper: Debug log enabled.
06-08 00:04:32.227: D/GameHelper(3668): GameHelper: Setup: requested clients: 1
06-08 00:04:32.306: W/PopupManager(3668): You have not specified a View to use as content view for popups. Falling back to the Activity content view. Note that this may not work as expected in multi-screen environments
06-08 00:04:36.837: D/AndroidRuntime(3668): Shutting down VM
06-08 00:04:36.837: W/dalvikvm(3668): threadid=1: thread exiting with uncaught exception (group=0x41646700)
06-08 00:04:36.868: E/AndroidRuntime(3668): FATAL EXCEPTION: main
06-08 00:04:36.868: E/AndroidRuntime(3668): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alnassre.ffeather.android/com.alnassre.ffeather.android.AndroidLauncher}: java.lang.NullPointerException
when I remove this.googleServices.signIn(); the game start normally.
public class FFeather extends Game {
public IGoogleServices googleServices;
public FFeather(IGoogleServices googleServices)
{
super();
this.googleServices = googleServices;.
this.googleServices.signIn();
}
....
the main android launcher:
public class AndroidLauncher extends AndroidApplication implements GameHelperListener,IGoogleServices {
private GameHelper _gameHelper;
private final static int REQUEST_CODE_UNUSED = 9202;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the GameHelper.
_gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
_gameHelper.enableDebugLog(true);
GameHelperListener gameHelperListener = new GameHelper.GameHelperListener() {
#Override
public void onSignInSucceeded() {
Gdx.app.log("AndroidLauncher", "start: onSignInSucceeded()");
}
#Override
public void onSignInFailed() {
Gdx.app.log("AndroidLauncher", "start: onSignInFailed()");
}
};
_gameHelper.setup(gameHelperListener);
// main code
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new FFeather(this), config);
}
#Override
public void signIn() {
Gdx.app.log("AndroidLauncher", "start: signIn()");
}
....
The interface IGoogleServices which I think the error related to.
public interface IGoogleServices {
public void signIn();
public void signOut();
public void rateGame();
public void submitScore(long score);
public void showScores();
public boolean isSignedIn();
}
Related
This question already has answers here:
android.content.res.Resources$NotFoundException: String resource ID #0x0
(8 answers)
Closed 6 years ago.
I need a thread that waits some time then changes a text in a TextView.
My search found how to use runOnUiThread
I understood the first answer and tried to use it in my code but I get an error when calling setText in the thread.
Here is my code
(start is the onClick function of a button):
public class MainActivity extends AppCompatActivity {
public int i = 0;
private TextView mText;
private Thread thread;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText = (TextView)findViewById(R.id.text);
}
public void start (View v) {
runThread();
}
private void runThread() {
new Thread() {
public void run() {
while (true) {
try {
runOnUiThread(new Runnable() {
#Override
public void run() {
i++;
mText.setText((i));
}
});
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
}
Here is my error
09-26 20:26:34.054 22254-22254/com.horizon.testtimerthread E/AndroidRuntime: FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.Resources.getText(Resources.java:1058)
at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
at android.widget.TextView.setText(TextView.java:3866)
at com.horizon.testtimerthread.MainActivity$1$1.run(MainActivity.java:39)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4947)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Thank you in advance for your help.
mText.setText((i)) is the problem.
Android thinks that you are referencing a String ID and is crashing because it cannot find a String with an ID of 1. If you meant to set the text to "1", "2" ect... then write mText.setText((Integer.toString(i)))
Since i has type int, you are calling setText(int resourceId) variant of function, what is obvious not you want. setText(String.valueOf(i)) should work.
I need to set Listener for Activity Class from BroadcastReceiver Class But here in my below code I am getting null pointer exception in BroadcastReceiver class..
Here is my code
Activity Class
public class MainActivity extends ActionBarActivity implements TheListener
{
Message_Incomingsms jv_class_Message_Incomingsms;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
jv_class_Message_Incomingsms = new Message_Incomingsms();
jv_class_Message_Incomingsms.setSmsReceivedistener(this);
}
#Override
public void onSmsReceived(String jv_string_address, String jv_string_MessageText)
{
Toast.makeText(getApplicationContext(),"This Message is from Lister number is "+jv_string_address +" Message is "+jv_string_MessageText,Toast.LENGTH_LONG).show();
//Doing some Activity.....
}
}
Interface
public void setSmsReceivedistener(Context context)
{
this.jv_TheListener = (TheListener)context;
}
BroadCastReceiver Class
public class Message_Incomingsms extends BroadcastReceiver
{
String jv_string_phone_received_Number;
String jv_string_phone_received_messageText;
public TheListener jv_TheListener;
#Override
public void onReceive(Context context, Intent intent)
{
Log.d("Received","OnReceive method is called");
jv_smsmanager_incoming_sms = SmsManager.getDefault();
jv_bundle_incoming_sms = intent.getExtras();
if(jv_bundle_incoming_sms!=null)
{
Object[] jv_pdusObj_incoming_sms = (Object[]) jv_bundle_incoming_sms.get("pdus");
for(int jv_i = 0; jv_i < jv_pdusObj_incoming_sms.length ;jv_i++)
{
SmsMessage jv_current_message = SmsMessage.createFromPdu((byte[]) jv_pdusObj_incoming_sms[jv_i]);
jv_string_phone_received_Number =jv_current_message.getDisplayOriginatingAddress();
jv_string_phone_received_messageText = jv_current_message.getDisplayMessageBody();
}
//Here Below line is problem for me Always am getting null value for (jv_TheListener)
//Why value is not getting assigned for this (jv_TheListener) always
jv_TheListener.onSmsReceived(jv_string_phone_received_Number,jv_string_phone_received_messageText);
}
}
public void setSmsReceivedistener(Context context)
{
this.jv_TheListener = (TheListener)context;
}
}
Please provide me solution for above BroadCastClass code where am always getting null exception for (jv_TheListener)
log Cat ( I removed some lines for in code for not to confuse.. so dont refer linenumber based on below error)
04-18 23:45:12.268 4064-4064/com.talkeasy.elavarasans.creativeactionbar E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start receiver com.talkeasy.elavarasans.creativeactionbar.Message_Incomingsms: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2153)
at android.app.ActivityThread.access$1500(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.talkeasy.elavarasans.creativeactionbar.Message_Incomingsms.onReceive(Message_Incomingsms.java:53)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2146)
at android.app.ActivityThread.access$1500(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
Thanks in Advance...
I have three class in my app.
First extends Activity
public class TestProjActivity extends Activity {
/** Called when the activity is first created. */
String my ="";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new Runnable() {
public void run() {
Translation th = new Translation(this);
my = th.doSomeJob();
}
}).start();
Log.d("ONCREATE", my);
}
}
Second is DBHelper
public class DBHelper {
private final Context myContext;
public DBHelper(Context context) {
this.myContext = context;
}
}
and third one extends DBhelper
public class Translation extends DBHelper {
public Translation(Runnable runnable) {
super((Context) runnable);
}
public String doSomeJob(){
return "Yes I DID!";
}
}
future I will change this classes to do real job but now,
when I run this I get this error:
05-11 13:15:53.003: E/AndroidRuntime(512): Uncaught handler: thread Thread-8 exiting due to uncaught exception
05-11 13:15:53.028: E/AndroidRuntime(512): java.lang.ClassCastException: iKA.PROJ.TestProjActivity$1
05-11 13:15:53.028: E/AndroidRuntime(512): at another.pack.Translation.(Translation.java:10)
05-11 13:15:53.028: E/AndroidRuntime(512): at iKA.PROJ.TestProjActivity$1.run(TestProjActivity.java:20)
05-11 13:15:53.028: E/AndroidRuntime(512): at java.lang.Thread.run(Thread.java:1096)
05-11 13:15:53.053: I/dalvikvm(512): threadid=7: reacting to signal 3
05-11 13:15:53.053: E/dalvikvm(512): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
05-11 13:20:53.135: I/Process(512): Sending signal. PID: 512 SIG: 9
What do I wrong ?
You're trying to cast your Runnable into a Context. This is not possible
I think that you want to do is
Translation th = new Translation(TestProjActivity.this);
and
public Translation(Context context) {
super(context);
}
Translation constructor take Activity(Context). But Translation constructor signature take Runnable. I think this is your problem (wrong class cast from Context/Activity to Runnable).
I am developing an app for android that has to access another class, but i don't know why it doesn't work.
When run the App in android 2.3.3 it force closes, and I don't understand why. I think that the method is correct.
Log in the force close the phone android:
> app_vercode:1
device_model:u8800
build_version:111180
condition:1
processName:beta.tester
pid:13277
uid:10088
tag:null
shortMsg:java.lang.NullPointerException
longMsg:java.lang.NullPointerException: Unable to start activity ComponentInfo{beta.tester/beta.tester.BetaTesterActivity}: java.lang.NullPointerException
stackTrace:java.lang.RuntimeException: Unable to start activity ComponentInfo{beta.tester/beta.tester.BetaTesterActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at beta.tester.BetaTesterActivity.onCreate(BetaTesterActivity.java:23)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
... 11 more
Detail logs:
EDIT: This code already is correctly.
The code:
class BetaTesterActivity:
package beta.tester;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class BetaTesterActivity extends Activity {
public TextView text1;
private teste cmd;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1 = (TextView) findViewById(R.id.text1);
//Start the function
cmd = new teste();
cmd.start(this);
}
}
class teste:
package beta.tester;
public class teste {
//Function that I will start
public void start(BetaTesterActivity zav){
zav.text1.setText("Hello");
}
//
}
In class teste, you are creating a new BetaTesterActivity, which is useless. You need to use the instance created by the framework. Change your class teste to this:
public class teste {
//Function that I will start
public void start(BetaTesterActivity zav){
zav.text1.setText("Hello");
}
}
Then in the onCreate method of your activity class, you need to initialize cmd and then call start like this:
cmd.start(this);
I'm trying to create my first Android App (a game) but I'm having some difficulties getting started.
When I run my code I get this error log:
05-25 02:41:51.022: WARN/dalvikvm(634): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): FATAL EXCEPTION: main
05-25 02:41:51.040: ERROR/AndroidRuntime(634): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stickfigs.nmg/com.stickfigs.nmg.NMG}: java.lang.NullPointerException
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.os.Looper.loop(Looper.java:123)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at java.lang.reflect.Method.invokeNative(Native Method)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at java.lang.reflect.Method.invoke(Method.java:521)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at dalvik.system.NativeStart.main(Native Method)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): Caused by: java.lang.NullPointerException
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at com.stickfigs.nmg.NMG.onCreate(NMG.java:32)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-25 02:41:51.040: ERROR/AndroidRuntime(634): ... 11 more
05-25 02:41:51.062: WARN/ActivityManager(59): Force finishing activity com.stickfigs.nmg/.NMG
I think the problem is this "thread exiting with uncaught exception" part, I have no idea what the exception could be or what's causing it.
Here is my code:
NMGView.java:
package com.stickfigs.NMG;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
class NMGView extends SurfaceView implements SurfaceHolder.Callback {
class NMGThread extends Thread {
//State-tracking constants
public static final int STATE_LOSE = 1;
public static final int STATE_PAUSE = 2;
public static final int STATE_READY = 3;
public static final int STATE_RUNNING = 4;
public static final int STATE_WIN = 5;
/** The state of the game. One of READY, RUNNING, PAUSE, LOSE, or WIN */
private int mode;
/** Handle to the surface manager object we interact with */
private SurfaceHolder surfaceHolder;
public NMGThread(SurfaceHolder surfaceHolderc, Context contextc) {
// get handles to some important objects
surfaceHolder = surfaceHolderc;
context = contextc;
}
/**
* Restores game state from the indicated Bundle. Typically called when
* the Activity is being restored after having been previously
* destroyed.
*
* #param savedState Bundle containing the game state
*/
public synchronized void restoreState(Bundle savedState) {
synchronized (surfaceHolder) {
setState(STATE_PAUSE);
}
}
/**
* Sets the game mode. That is, whether we are running, paused, in the
* failure state, in the victory state, etc.
*
* #param mode one of the STATE_* constants
* #param message string to add to screen or null
*/
public void setState(int modec) {
synchronized (surfaceHolder) {
mode = modec;
}
}
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
/** Handle to the application context, used to e.g. fetch Drawables. */
private Context context;
/** The thread that actually draws the animation */
private NMGThread thread;
public NMGView(Context context, AttributeSet attrs) {
super(context, attrs);
// register our interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
// create thread only; it's started in surfaceCreated()
thread = new NMGThread(holder, context);
setFocusable(true); // make sure we get key events
}
/**
* Fetches the animation thread corresponding to this LunarView.
*
* #return the animation thread
*/
public NMGThread getThread() {
return thread;
}
}
NMG.java:
package com.stickfigs.nmg;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import com.stickfigs.nmg.NMGView.NMGThread;
public class NMG extends Activity {
/** Called when the activity is first created. */
/** A handle to the thread that's actually running the animation. */
private NMGThread nMGThread;
/** A handle to the View in which the game is running. */
private NMGView nMGView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Turn off the window's title bar
// TODO Turn off the status bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
// tell system to use the layout defined in our XML file
setContentView(R.layout.nmg_layout);
// get handles to the LunarView from XML, and its LunarThread
nMGView = (NMGView) findViewById(R.id.nmg);
nMGThread = nMGView.getThread();
if (savedInstanceState == null) {
// we were just launched: set up a new game
nMGThread.setState(NMGThread.STATE_READY);
Log.w(this.getClass().getName(), "SIS is null");
} else {
// we are being restored: resume a previous game
nMGThread.restoreState(savedInstanceState);
Log.w(this.getClass().getName(), "SIS is nonnull");
}
}
}
UPDATE: Here is my R.java and nmg_layout.xml:
R.java:
package com.stickfigs.nmg;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int nmg=0x7f050000;
}
public static final class layout {
public static final int nmg_layout=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
nmg_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.stickfigs.nmg.NMGView
android:id="#+id/nmg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
If you look through the stack trace, you will see a "Caused by..." line (sometimes more than one). The last one of those is the important one. It says that there was a null pointer exception on line 32 of NMG.java. That line, and the line before it, are:
nMGView = (NMGView) findViewById(R.id.nmg);
nMGThread = nMGView.getThread();
Evidently, no view with id R.id.nmg is in layout R.layout.nmg_layout. That's what's causing your problem.
In your XML file, the R.id.nmg do exist.
So I think the problem is caused by inflating the NMGView object from the resource.
You should examine your NMGView source code, especially in its constructor.
If you are using "multiDexEnabled true" in your "build.gradle(Module:app)" , remove this line from "defaultConfig" and sync project.
It works in my case !!!
This problems happens because most of the time the SurfaceView onDraw() method is running when you destroy the surfaceView then you get a NULL POINTER ERROR because the canvas doesn´t exist by that moment. I have fixed this problem catching all the drawing stuff with the NullPointerException:
#Override
public void onDraw(Canvas canvas) {
try {
//Drawing Stuff
}catch(NullPointerException e){
Log.e("NULL POINTER EXCEPTION","Canvas NULL POINTER");
}
}
If you implement onPause(), onDestroy() methods in your Main activity you will get the following order: first: E/onPause﹕ ON PAUSE --> next E/surfaceDestroyed﹕ SURFACE DESTROYED --> E/NULL POINTER EXCEPTION﹕ Canvas NULL POINTER --> finally
E/onDestroy﹕ ON DESTROY
this is surfaceDestroyed method I am using:
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
Log.e("surfaceDestroyed", "SURFACE DESTROYED ");
thread.setRunning(false);
try {
//thread.setRunning(false);
thread.join();
} catch (InterruptedException e) {
Log.e("Surface Thread Stopped","SURFACE THREAD STOPPED");
}
}