Android:android.content.res.Resources $ NotFoundException:字符串资源ID

时间:2016-08-19 12:54:42

标签: android google-analytics android-resources

我创建了一个使用Google Analytics的类,我添加了函数但是访问此字符串时收到错误:ProductAction.ACTION_PUR​​CHASE,错误代码:

function slider2_Callback(hObject, eventdata, handles)
    value = round(get(handles.slider2, 'Value'));
    set(handles.slider2, 'Value', value);

    % Do whatever you need to do in this callback
end

GoogleAnalytics.java:

  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)

我如何从我的片段中调用它:

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());
        //}
    }
}

1 个答案:

答案 0 :(得分:0)

替换

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

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