我制作了一款使用zxing的应用。 它从integrated-zxing获得isbn代码并将POST发送到服务器。
...它在构建调试模式时工作正常,但在构建版本时不起作用。
我不知道出了什么问题。
请帮忙。它把我绑在椅子上。
这里有例外:
11-29 11:36:22.233 14848-14899/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ExceptionInInitializerError
at a.a.b.f.<init>(Unknown Source)
at a.a.b.e.<init>(Unknown Source)
at a.a.c.df.a(Unknown Source)
at a.a.c.b.a(Unknown Source)
at lemon.apple.aladinisbna.b.a.a(Unknown Source)
at lemon.apple.aladinisbna.b.a.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ExceptionInInitializerError
at a.a.b.l.<clinit>(Unknown Source)
at a.a.b.f.<init>(Unknown Source)
at a.a.b.e.<init>(Unknown Source)
at a.a.c.df.a(Unknown Source)
at a.a.c.b.a(Unknown Source)
at lemon.apple.aladinisbna.b.a.a(Unknown Source)
at lemon.apple.aladinisbna.b.a.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at java.util.Properties.load(Properties.java:246)
at a.a.b.k.d(Unknown Source)
at a.a.b.k.<clinit>(Unknown Source)
at a.a.b.l.<clinit>(Unknown Source)
at a.a.b.f.<init>(Unknown Source)
at a.a.b.e.<init>(Unknown Source)
at a.a.c.df.a(Unknown Source)
at a.a.c.b.a(Unknown Source)
at lemon.apple.aladinisbna.b.a.a(Unknown Source)
at lemon.apple.aladinisbna.b.a.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
11-29 11:36:22.258 2003-2022/? E/android.os.Debug﹕ !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error
11-29 11:36:23.778 1844-1844/? E/DataRouter﹕ usb connection is true
11-29 11:36:23.778 1844-1844/? E/DataRouter﹕ InvokeOemRequestHookRaw usbstatus true is success
11-29 11:36:25.778 1844-1844/? E/DataRouter﹕ usb connection is true
11-29 11:36:25.783 1844-1844/? E/DataRouter﹕ InvokeOemRequestHookRaw usbstatus true is success
11-29 11:36:27.783 1844-1844/? E/DataRouter﹕ usb connection is true
11-29 11:36:27.783 1844-1844/? E/DataRouter﹕ InvokeOemRequestHookRaw usbstatus true is success
11-29 11:36:29.213 14848-14848/? E/WindowManager﹕ Activity lemon.apple.aladinisbna.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@415ac750 that was originally added here
android.view.WindowLeaked: Activity lemon.apple.aladinisbna.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@415ac750 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:386)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
at android.view.Window$LocalWindowManager.addView(Window.java:537)
at android.app.Dialog.show(Dialog.java:278)
at android.app.ProgressDialog.show(ProgressDialog.java:116)
at android.app.ProgressDialog.show(ProgressDialog.java:99)
at lemon.apple.aladinisbna.b.a.onPreExecute(Unknown Source)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
at android.os.AsyncTask.execute(AsyncTask.java:511)
at lemon.apple.aladinisbna.i.a(Unknown Source)
at lemon.apple.aladinisbna.MainActivity.onActivityResult(Unknown Source)
at android.app.Activity.dispatchActivityResult(Activity.java:4649)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2988)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3035)
at android.app.ActivityThread.access$1100(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1189)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
这是代码:
//ISBNDownLoader.java
public class ISBNDownLoader extends AsyncTask<String, Void, Book> {
private Context context;
private ArrayAdapter<Book> adapter;
private ProgressDialog dialog;
public ISBNDownLoader(Context context, ArrayAdapter<Book> adapter) {
this.context = context;
this.adapter = adapter;
}
@Override
protected void onPreExecute() {// works fine until here...
dialog = ProgressDialog.show(context, "", "잠시만 기다려 주세요 ...", true);
}
@Override
protected Book doInBackground(String... params) {
String isbn = params[0];
return requestPostToAladin(isbn);
}
@Override
protected void onPostExecute(Book result) { // guess here is where the crash occur, I think
if (result == null) {
Toast.makeText(context, "알라딘에서 해당 도서를 찾을 수 없네요 ㅠㅠ", Toast.LENGTH_LONG).show();
} else {
Book.save(context, result);
adapter.insert(result, 0);
adapter.notifyDataSetChanged();
}
dialog.dismiss();
}
public Book requestPostToAladin(String isbn) {
// send POST to sever
// using jsoup
...
}
}
//ScanISBNFragment.java
public class ScanISBNFragment extends Fragment {
...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_scan) {
IntentIntegrator.initiateScan(getActivity()); // call zxing.
return true;
}
return super.onOptionsItemSelected(item);
}
public void search(String isbn) {
ISBNDownLoader isbnDownLoader = new ISBNDownLoader(getActivity(), (ArrayAdapter<Book>) listView.getAdapter());
isbnDownLoader.execute(isbn);
}
...
}
// MainActivity.java
public class MainActivity extends Activity { // LAUNCH Activity, and implement navigation drawer.
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// I have to implement this Main"Activity" because IntentIntegrator.initiateScan() supports Activity only.
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (scanResult != null) {
String contents = scanResult.getContents();
if (contents != null) {
Toast.makeText(this, contents, Toast.LENGTH_SHORT).show();
ScanISBNFragment placeholder = (ScanISBNFragment) getFragmentManager().findFragmentById(R.id.content_frame);
assert placeholder != null;
if (placeholder.isISBN(contents)) {
placeholder.search(contents); // here
} else {
Toast.makeText(this, "ISBN이 아니네요! 다시 찍어주세요.", Toast.LENGTH_SHORT).show();
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
...
}
我在Mac上使用Android Studio 0.3.6
所以,这是build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
signingConfigs {
release {
// secret!
storeFile file("****")
storePassword "****"
keyAlias "****"
keyPassword "****"
}
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
signingConfig signingConfigs.release
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.google.zxing:core:2.2'
compile 'com.embarkmobile:zxing-android-minimal:1.1.4@aar'
compile 'org.jsoup:jsoup:1.7.3'
}
解: 问题是由无效的proguard发生的。 所以..我只是删除proguard。那么,每件事都可以。
答案 0 :(得分:0)
在 onPostExecute
中进行更改@Override
protected void onPostExecute(Book result) { // guess here is where the crash occur, I think
if (dialog!= null || dialog.isShowing()) {
dialog.dismiss();
}
if (result == null) {
Toast.makeText(context, "알라딘에서 해당 도서를 찾을 수 없네요 ㅠㅠ", Toast.LENGTH_LONG).show();
} else {
Book.save(context, result);
adapter.insert(result, 0);
adapter.notifyDataSetChanged();
}
}