Antoni Antoni - 4 months ago 25
Android Question

android.content.res.Resources$NotFoundException: String resource id #0x64

I make an app with background services and broadcast receiver, and my app consists of a

MainActivity.java
and
myServiceRunner.java
. When I start the background service, it gives me this error,
android.content.res.Resources$NotFoundException: String resource id #0x64
.

I put these codes inside protected void onCreate(Bundle savedInstanceState):

IntentFilter mainFilter=new IntentFilter("liren.action.GOSERVICE3");
receiver=new MyMainLocalReceiver();
registerReceiver(receiver, mainFilter);



MyMainLocalReceiver.java


public class MyMainLocalReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {

try
{
int serviceData=intent.getIntExtra("serviceData",0);
//Toast.makeText(getApplicationContext(), serviceData,Toast.LENGTH_SHORT).show();

tvStepsCount.setText(serviceData);
}
catch (Exception e)
{
tvStepsCount.setText(e.toString());
}

}
}


Inside myServiceRunner extends Service class, I have added these codes inside onStartCommand method.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Thread triggerService=new Thread(new Runnable() {
@Override
public void run() {
for(;;)
{
try
{
Intent myFilteredResponse = new Intent("liren.action.GOSERVICE3");
myFilteredResponse.putExtra("serviceData",100);
sendBroadcast(myFilteredResponse);
Thread.sleep(5000);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
});
triggerService.start();
return super.onStartCommand(intent, flags, startId);
}



manifest.xml


I have added these:

<service android:name=".myServiceRunner"></service>
<receiver android:name=".RecordSaved$MyMainLocalReceiver"></receiver>


I could not figure out the error, can anyone help me please? Thanks :)

Answer

You are using .SetText(). but you are passing int type. that's a problem. so you need to convert your int to String

Try like,

tvStepsCount.setText("" + serviceData); // concat with empty string