AndroidstudioでOCRを使ったアプリを作っていますが、タイトルのエラーが解消できません。
エラー文をみてonCreate()の前でgoodsListの宣言をすればいいのかと思い、試してみましたが、そうなるとconvertResponseToStringのgoodsListが使えなくなります。
私の知識では八方塞がりです。
詳しい方ご教授願います。
java
1public static String convertResponseToString(BatchAnnotateImagesResponse response, List gooosList) { 2 StringBuilder message = new StringBuilder("I found these things:\n\n"); 3 4 TextAnnotation label = response.getResponses().get(0).getFullTextAnnotation(); 5 String str = null; 6 str = label.getText(); 7 8 String matchdate = null; 9 String regaxdate = null; 10 String regaxprice = null; 11 ArrayList<String> priceList = new ArrayList<>(); 12 goodsList = null; 13 14 int firstidx = 0; 15 int lastidx = 0; 16 17 //日付取得の処理 18 regaxdate = "\d{4}-\d{1,2}-\d{1,2}|\d{4}/\d{1,2}/\d{1,2}|\d{4}年\d{1,2}月\d{1,2}日"; 19 Pattern pdate = Pattern.compile(regaxdate); 20 Matcher mdate = pdate.matcher(str); 21 if (mdate.find()) { 22 matchdate = mdate.group(); 23 } 24 25 //値段取得の処理 26 regaxprice = "¥([,0-9]+)"; 27 Pattern pprice = Pattern.compile(regaxprice); 28 Matcher mprice = pprice.matcher(str); 29 while(mprice.find()) { 30 priceList.add(mprice.group()); 31 } 32 33 //品名取得の処理 34 String regaxkei = ".*計.*"; 35 Pattern pkei = Pattern.compile(regaxkei); 36 Matcher mkeinohou = pkei.matcher(str); //計マッチ 37 38 39 if(mkeinohou.find()) { 40 String matchdatehinmei = mdate.group(); 41 firstidx = str.indexOf(matchdatehinmei) + matchdatehinmei.length(); 42 String matchkeihinmei = mkeinohou.group(); 43 lastidx = str.indexOf(matchkeihinmei); 44 String datekarakei = str.substring(firstidx, lastidx); 45 datekarakei.replaceAll("[,0-9]+", ""); 46 datekarakei.replaceAll("\\", ""); 47 goodsList = Arrays.asList(datekarakei.split("\n")); 48 message.append(goodsList); 49 50 handler.post(new Runnable() { 51 @Override 52 public void run() { 53 ResitoActivity RA = new ResitoActivity(); 54 ArrayAdapter arrayAdapter = new ArrayAdapter(RA, R.layout.resitolayout, goodsList); 55 ListView listView = null; 56 listView.findViewById(R.id.resitolist); 57 listView.setAdapter(arrayAdapter); 58 } 59 }); 60 } else { 61 message.append("'計'がマッチしませんでした。"); 62 }
エラー文
java.lang.IllegalStateException: System services not available to Activities before onCreate()
at android.app.Activity.getSystemService(Activity.java:5883)
at android.view.LayoutInflater.from(LayoutInflater.java:229)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:210)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:204)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:190)
at com.example.tamayamaryo.recipebook_sotuken.ResitoActivity$7.run(ResitoActivity.java:433)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6572)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)