我正在尝试制作一个小型qr代码扫描程序,它使用Zxing库中的类。我的代码似乎很好,我无法识别任何明显的错误。当我尝试运行它时,应用程序强制关闭。
这是logcat:
01-25 07:07:30.263: E/AndroidRuntime(5530): FATAL EXCEPTION: main
01-25 07:07:30.263: E/AndroidRuntime(5530):
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo
{zeero.damian.qrcodescanner/zeero.damian.qrcodescanner.QR_Scanner}:
java.lang.ClassNotFoundException:
zeero.damian.qrcodescanner.QR_Scanner in loader
dalvik.system.PathClassLoader[/data/app/zeero.damian.qrcodescanner-
2.apk]
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:1618)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:1716)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.ActivityThread.access$1500(ActivityThread.java:124)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.os.Handler.dispatchMessage(Handler.java:99)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.os.Looper.loop(Looper.java:130)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.ActivityThread.main(ActivityThread.java:3806)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
java.lang.reflect.Method.invokeNative(Native Method)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
java.lang.reflect.Method.invoke(Method.java:507)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:839)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
dalvik.system.NativeStart.main(Native Method)
01-25 07:07:30.263: E/AndroidRuntime(5530): Caused by:
java.lang.ClassNotFoundException:
zeero.damian.qrcodescanner.QR_Scanner in loader
dalvik.system.PathClassLoader[/data/app/zeero.damian.qrcodescanner-
2.apk]
01-25 07:07:30.263: E/AndroidRuntime(5530): at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-25 07:07:30.263: E/AndroidRuntime(5530): at
android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:1610)
01-25 07:07:30.263: E/AndroidRuntime(5530): ... 11 more
01-25 07:07:30.263: W/ActivityManager(1468): Force finishing
activity zeero.damian.qrcodescanner/.QR_Scanner
01-25 07:07:30.423: E/NetlinkEvent(1351): NetlinkEvent::FindParam():
Parameter 'UDEV_LOG' not found
这是我的MainActivity类
package zeero.damian.qrscanner;
import zeero.damian.qrcodescanner.R;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private Button scanBtn;
private TextView formatTxt;
private TextView contentTxt;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
scanBtn = (Button)findViewById(R.id.scan_button);
formatTxt = (TextView)findViewById(R.id.scan_format);
contentTxt = (TextView)findViewById(R.id.scan_content);
scanBtn.setOnClickListener(this);
}
// Press the scan button to begin //
public void onClick(View v){
if(v.getId()==R.id.scan_button){
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent){
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if(scanningResult != null){
/*
* If scan is successful any code here will be executed,
* here the app will display the code format, and any
* Information it holds. This can be added to or replaced
* to do something else on a successful scan.
*/
String scanContent = scanningResult.getContents();
String scanFormat = scanningResult.getFormatName();
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
}
else{
/*
* if the code scan fails, this block will be executed.
* Here a pop up alert will alert the user that the scan
* was unsuccessful, but like above, this can be changed to
* whatever you want it to do.
*/
Toast toast = Toast.makeText(getApplicationContext(),
"Scan was unsuccessful!"+ "\n" +
"Please try again...", Toast.LENGTH_SHORT);
toast.show();
}
}
}
答案 0 :(得分:0)
该异常表示您正在尝试在某处启动名为zeero.damian.qrcodescanner.QR_Scanner的Activity。我在你发布的代码中没有看到这个,但是这个例外的一个常见原因是忘记在你的清单中注册活动