简体   繁体   中英

Android: android.content.res.Resources$NotFoundException: String resource ID

I created an class to use Google Analytics, I added functions but I get an error to access to this string: ProductAction.ACTION_PURCHASE, error code:

  08-19 08:50:14.944  16673-16947/fr.solutis.solutis E/AndroidRuntime﹕
  FATAL EXCEPTION: AsyncTask #1
 Process: fr.solutis.solutis, PID: 16673
 java.lang.RuntimeException: An error occured while executing doInBackground()
         at android.os.AsyncTask$3.done(AsyncTask.java:300)
         at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
         at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
         at java.util.concurrent.FutureTask.run(FutureTask.java:242)
         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:841)
  Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f08003a
         at android.content.res.Resources.getText(Resources.java:244)
         at android.content.res.Resources.getString(Resources.java:330)
         at fr.solutis.solutis.GoogleAnalytics.envoieTracker(GoogleAnalytics.java:38)
         at fr.solutis.solutis.DemandeGratuite$AsyncSoapCall.doInBackground(DemandeGratuite.java:1932)
         at fr.solutis.solutis.DemandeGratuite$AsyncSoapCall.doInBackground(DemandeGratuite.java:1915)
         at android.os.AsyncTask$2.call(AsyncTask.java:288)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:841)

GoogleAnalytics.java:

public class GoogleAnalytics{


    private Context context;
    public GoogleAnalytics(Context context) {
        this.context = context;
    }


    public void envoieTracker(String idApplication, int demandeId, String logement, String typeForm){

        DatabaseHandler db = new DatabaseHandler(context);

        String id = idApplication + demandeId;

        //if (code.equals("1")) {
            db.updateStatutDateEnvoie(demandeId);
            Product product = new Product()
                    .setId(id)
                    .setName(logement)
                    .setCategory(typeForm)
                    .setBrand("")
                    .setVariant("")
                    .setPrice(1)
                    .setCouponCode("")
                    .setQuantity(1);
            ProductAction productAction = new ProductAction(ProductAction.ACTION_PURCHASE)
                    .setTransactionId(id)
                    .setTransactionAffiliation(Resources.getSystem().getString(R.string.TransactionAffiliation))
                    .setTransactionRevenue(1)
                    .setTransactionTax(0)
                    .setTransactionShipping(0)
                    .setTransactionCouponCode("");
            HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
                    .addProduct(product)
                    .setProductAction(productAction);

            App app = new App();
            Tracker t = app.getTracker();
            t.setScreenName("Demande");
            t.send(builder.build());
        //}
    }
}

How I call it from my fragment:

            GoogleAnalytics ga= new GoogleAnalytics(getActivity());
            ga.envoieTracker(idApplication, demandeId, logement, typeForm);

Replace

Resources.getSystem().getString(R.string.TransactionAffiliation)

to

context.getResources().getString(R.string.TransactionAffiliation)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM