我一直在设计API 7到API 19的Android应用程序,它一直运行良好,直到我将其中一个drawables更改为更具吸引力的背景(对于几个EditTexts)。错误如下。
05-09 07:00:43.129 13022-13022/vanwert.sdb E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.VerifyError: vanwert.sdb.SerialDilution$1
at vanwert.sdb.SerialDilution.onCreate(SerialDilution.java:134)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
错误的代码如下。错误发生在此代码的最后一行(第134行)。我删除了剩余的代码。如果我在我的新设备上运行应用程序Galaxy Note 3,它运行良好。如果我在旧的Galaxy Vibrant(我相信的android 2.3)上运行它就会出现这个错误。请帮忙。感谢。
package vanwert.sdb;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.text.InputFilter;
import android.text.InputType;
import android.text.method.DigitsKeyListener;
import android.text.method.TextKeyListener;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ScrollView;
import android.widget.Toast;
import java.io.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import static android.text.InputFilter.*;
import static android.view.View.OnClickListener;
public class SerialDilution extends Activity {
EditText CDA, CDB, CDC, CDD, CDE, CDF, CDG, CDH, CDI, CDJ,
CDK, CDL, CDM, CDN, CDO, CSB, CSC, CSD, CSE, CSF,
CSG, CSH, CSI, CSJ, CSK, CSL, CSM, CSN, CSO,
RVA, RVB, RVC, RVD, RVE, RVF, RVG, RVH, RVI, RVJ,
RVK, RVL, RVM, RVN, RVO, TVNA, TVNB, TVNC, TVND,
TVNE, TVNF, TVNG, TVNH, TVNI, TVNJ, TVNK, TVNL,
TVNM, TVNN, TVNO, VCSB, VCSC, VCSD, VCSE, VCSF,
VCSG, VCSH, VCSI, VCSJ, VCSK, VCSL, VCSM, VCSN,
VCSO, VDLB, VDLC, VDLD, VDLE, VDLF, VDLG, VDLH,
VDLI, VDLJ, VDLK, VDLL, VDLM, VDLN, VDLO;
String CDAs, CDBs, CDCs, CDDs, CDEs, CDFs, CDGs, CDHs, CDIs, CDJs, CDKs, CDLs, CDMs, CDNs, CDOs,
RVAs, RVBs, RVCs, RVDs, RVEs, RVFs, RVGs, RVHs, RVIs, RVJs, RVKs, RVLs, RVMs, RVNs, RVOs,
CSBs, CSCs, CSDs, CSEs, CSFs, CSGs, CSHs, CSIs, CSJs, CSKs, CSLs, CSMs, CSNs, CSOs,TVNAs,
TVNBs, TVNCs, TVNDs, TVNEs, TVNFs, TVNGs, TVNHs, TVNIs, TVNJs, TVNKs, TVNLs, TVNMs, TVNNs,
TVNOs, VCSBs, VCSCs, VCSDs, VCSEs, VCSFs, VCSGs, VCSHs, VCSIs, VCSJs, VCSKs, VCSLs, VCSMs,
VCSNs, VCSOs, VDLBs, VDLCs, VDLDs, VDLEs, VDLFs, VDLGs, VDLHs, VDLIs, VDLJs, VDLKs, VDLLs,
VDLMs, VDLNs, VDLOs;
String currentLanguage;
HorizontalScrollView HScrollView;
ScrollView MainScrollView;
Double CSBi, CSCi, CSDi, CSEi, CSFi, CSGi, CSHi, CSIi, CSJi, CSKi, CSLi, CSMi, CSNi, CSOi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table_calculator);
// set scrollview to start on left
CDA = (EditText) findViewById(R.id.CDA);
CDA.requestFocus();
// setting input type based on language
CSB = (EditText) findViewById(R.id.CSB);
CSC = (EditText) findViewById(R.id.CSC);
CSD = (EditText) findViewById(R.id.CSD);
CSE = (EditText) findViewById(R.id.CSE);
CSF = (EditText) findViewById(R.id.CSF);
CSG = (EditText) findViewById(R.id.CSG);
CSH = (EditText) findViewById(R.id.CSH);
CSI = (EditText) findViewById(R.id.CSI);
CSJ = (EditText) findViewById(R.id.CSJ);
CSK = (EditText) findViewById(R.id.CSK);
CSL = (EditText) findViewById(R.id.CSL);
CSM = (EditText) findViewById(R.id.CSM);
CSN = (EditText) findViewById(R.id.CSN);
CSO = (EditText) findViewById(R.id.CSO);
CSB.setFilters(new InputFilter[] { new LengthFilter(1) });
CSC.setFilters(new InputFilter[] { new LengthFilter(1) });
CSD.setFilters(new InputFilter[] { new LengthFilter(1) });
CSE.setFilters(new InputFilter[] { new LengthFilter(1) });
CSF.setFilters(new InputFilter[] { new LengthFilter(1) });
CSG.setFilters(new InputFilter[] { new LengthFilter(1) });
CSH.setFilters(new InputFilter[] { new LengthFilter(1) });
CSI.setFilters(new InputFilter[] { new LengthFilter(1) });
CSJ.setFilters(new InputFilter[] { new LengthFilter(1) });
CSK.setFilters(new InputFilter[] { new LengthFilter(2) });
CSL.setFilters(new InputFilter[] { new LengthFilter(2) });
CSM.setFilters(new InputFilter[] { new LengthFilter(2) });
CSN.setFilters(new InputFilter[] { new LengthFilter(2) });
CSO.setFilters(new InputFilter[] { new LengthFilter(2) });
Button Calc;
Calc = (Button) findViewById(R.id.CalcButton);
Calc.setOnClickListener(new View.OnClickListener() {
这是我的一些XML,但整个文件超出了字符限制。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:orientation="vertical"
android:background="#000000"
android:layout_width="42dp"
android:layout_height="fill_parent">
<Button
android:id="@+id/CalcButton"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/goodbutton"
android:text=" " />
<Button
android:id="@+id/CSVButton"
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="false"
android:background="@drawable/csvbutton"
android:layout_alignParentLeft="false"
android:layout_below="@+id/CalcButton"
android:layout_marginTop="5dp" />
答案 0 :(得分:0)
http://docs.oracle.com/javase/7/docs/api/java/lang/VerifyError.html
如果您只是使用较低的API获取错误,那么可能您在onClick()方法中调用了旧版本不支持的内容。我在动态更改TextView的背景时遇到了类似的问题。
我使用它来实现向后兼容。
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
// old api
setBackgroundDrawable();
} else {
//newer api
setBackground();
}
希望它有所帮助!
答案 1 :(得分:0)
感谢所有人。在@Woodstown的大力帮助下,我解决了这个问题。我的代码(在注释中超链接)在OnClick方法中声明了我的所有BigDecimal变量。当我在OnClick方法之前将所有BigDecimal变量声明为全局变量时,活动在旧的Android设备上打开并顺利运行。我确信Woodstown会帮助我进行其他优化,但这对我来说非常有用。
对于像我这样的新手,这基本上就是我的意思:
而不是:
package ......
import......
public class SerialDilution extends Activity {
@Override
public void onClick(View v) {
BigDecimal xyz;
// do something with BigDecimal xyz
BigDecimal abc;
// do something with BigDecimal abc
尝试:
package ......
import......
public class SerialDilution extends Activity {
BigDecimal xyz, abc;
@Override
public void onClick(View v) {
// now call method with BigDecimals xyx or abc
在方法修复我的问题之前简单地一起声明它们&#34;任意拒绝大方法&#34; (如日志级别&#34;详细&#34;在logcat上看到)和验证错误(见于日志级别&#34;错误&#34;在logcat上)。