我已经阅读了与这些问题相关的所有答案,我确信没有一个能解决我的问题,我对这个错误感到很疯狂,请任何帮助将不胜感激
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dip"
android:orientation="vertical" >
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_scaned_value"/>
<TextView
android:id="@+id/scanedFormat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/title_scaned_value_empty"/>
<TextView
android:id="@+id/scanedValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/title_scaned_value_empty"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/title_scan"
android:onClick="commandScan"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="productes"
android:onClick="productes"/>
我与此布局相关的活动工作正常,但是当我单击按钮启动另一个活动时,会出现此错误。我正在使用 Zxing 库,这是我的 CaptureActivity:
package org.example.sherlock_;
import org.example.sherlock_.helpers.ExceptionHelper;
import android.content.Intent;
import android.graphics.Bitmap;
import com.google.zxing.Result;
import com.google.zxing.client.android.result.ResultHandler;
public class CaptureActivity extends com.google.zxing.client.android.CaptureActivity {
@Override
public void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
//super.handleDecodeInternally(rawResult, resultHandler, barcode);
try {
Intent resultIntent = new Intent();
resultIntent.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
resultIntent.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, resultHandler.getDisplayContents());
setResult(RESULT_OK, resultIntent);
finish();
} catch (Exception e) {
ExceptionHelper.manage(this, e);
}
}
}
我也发布了我的 MainActivity,因为我真的很生气 :)
package org.example.sherlock_;
import org.example.sherlock_.helpers.ExceptionHelper;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
public class MainActivity extends SherlockActivity {
private TextView scanedValue;
private TextView scanedFormat;
private final static int SCAN_CODE_REQUEST_CODE = 123456;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanedValue = (TextView)findViewById(R.id.scanedValue);
scanedFormat = (TextView)findViewById(R.id.scanedFormat);
}
@Override
protected void onActivityResult(int pRequestCode, int pResultCode, Intent pData) {
try {
if (pRequestCode == SCAN_CODE_REQUEST_CODE) {
if (pResultCode == RESULT_OK) {
String result = pData.getStringExtra
(com.google.zxing.client.android.Intents.Scan.RESULT);
String format = pData.getStringExtra
(com.google.zxing.client.android.Intents.Scan.RESULT_FORMAT);
if (scanedValue != null) {
if (result != null &&
!result.trim().equals("")) {
scanedValue.setText(result);
//if(db != null){
//String valor= result ;
//}
} else {
scanedValue.setText(getString(R.string.title_scaned_value_empty));
}
}
if (scanedFormat != null) {
if (format != null &&
!format.trim().equals("")) {
scanedFormat.setText(format);
//if(db != null){
//String tipus = format;
//}
} else {
scanedFormat.setText(getString(R.string.title_scaned_value_empty));
}
}
} else {
if (scanedValue != null)
scanedValue.setText(getString(R.string.title_scaned_value_empty));
if (scanedFormat != null)
scanedFormat.setText(getString(R.string.title_scaned_value_empty));
}
}
//Insertamos los datos en la tabla Usuarios
// db.execSQL("INSERT INTO Productes (codi, tipus, valor) " +
// "VALUES (" + i + ", '" + tipus +"', '"+ valor +"')");
// db.close();
//i+=i;
} catch (Exception e) {
ExceptionHelper.manage(this, e);
}
}
public void commandScan(View pView) {
try {
Intent captureIntent = new Intent(this, CaptureActivity.class);
captureIntent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(captureIntent, SCAN_CODE_REQUEST_CODE);
} catch (Exception e) {
ExceptionHelper.manage(this, e);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
Toast.makeText(this, "configuración pulsado"
, Toast.LENGTH_SHORT).show();
}
return true;
}
}