无法启动actvity componentinfo-Android应用程序条形码扫描仪

用户名

我正在尝试实现一个扫描器以读取代码,然后在我的应用程序中使用它来显示和过滤数据。下面是该应用程序的代码段,摘录自在线教程。

尝试运行应用程序时出现以下错误

    **FATAL EXCEPTION: main
Process: com.example.barcodescanningapp, PID: 27516
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.barcodescanningapp/com.example.barcodescanningapp.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(27516): Caused by: java.lang.NullPointerException
at com.example.barcodescanningapp.MainActivity.onCreate(MainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)**

我无法确定我的零点异常来自何处。请帮忙。

public class MainActivity extends ActionBarActivity implements OnClickListener{
private Button scanBtn;
private TextView formatTxt, contentTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
    scanBtn = (Button)findViewById(R.id.scan_button);
    formatTxt = (TextView)findViewById(R.id.scan_format);
    contentTxt = (TextView)findViewById(R.id.scan_content);
    scanBtn.setOnClickListener(this);
}

public void onClick(View v){
    //respond to clicks
    if(v.getId()==R.id.scan_button){
        //scan
        IntentIntegrator scanIntegrator = new IntentIntegrator(this);
        scanIntegrator.initiateScan();
        }

    }

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    //retrieve scan result
    IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if (scanningResult != null) {
        //we have a result
        String scanContent = scanningResult.getContents();
        String scanFormat = scanningResult.getFormatName();
        formatTxt.setText("FORMAT: " + scanFormat);
        contentTxt.setText("CONTENT: " + scanContent);
        }
    else{
        Toast toast = Toast.makeText(getApplicationContext(), 
            "No scan data received!", Toast.LENGTH_SHORT);
        toast.show();
    }

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}
}   
佐兰

您的按钮和文本视图位于片段布局中,而不处于活动布局中,因此您必须将部分代码移动到onCreateView上,如下所示:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_main);

    scanBtn = (Button)findViewById(R.id.scan_button);
    formatTxt = (TextView)findViewById(R.id.scan_format);
    contentTxt = (TextView)findViewById(R.id.scan_content);
    scanBtn.setOnClickListener(this);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在不安装实际的zxing应用程序的情况下集成Zxing条形码扫描仪(无法解析符号:.android.CaptureActivity)?

来自分类Dev

条形码扫描仪意图启动,但无法扫描二维码?

来自分类Dev

Android应用程序无法启动活动componentinfo

来自分类Dev

Android应用程序空指针无法启动活动ComponentInfo

来自分类Dev

应用无法启动活动componentinfo(Android)

来自分类Dev

Android Studio条形码扫描仪应用程序。通过意图扫描

来自分类Dev

Android关于无法启动活动componentinfo

来自分类Dev

Android App无法启动活动ComponentInfo

来自分类Dev

android studio 无法启动 Activity ComponentInfo

来自分类Dev

为什么1000个CCD条形码接触扫描仪无法识别零?

来自分类Dev

html5和jquery应用程序的条形码扫描仪

来自分类Dev

从条形码扫描仪应用程序访问数据以在SQLite查询中使用

来自分类Dev

用于html5和jquery应用程序的条形码扫描仪

来自分类Dev

运行Windows“条形码扫描仪示例”应用程序

来自分类Dev

单击按钮时应用崩溃。无法启动活动ComponentInfo

来自分类Dev

Android JSON:java.lang.RuntimeException:无法启动活动ComponentInfo

来自分类Dev

java.lang.RuntimeException:无法启动活动ComponentInfo Android清单

来自分类Dev

无法启动活动ComponentInfo,仅来自android N的错误

来自分类Dev

Android Studio:java.lang.RuntimeException:无法启动活动ComponentInfo

来自分类Dev

Java / Android:无法启动活动ComponentInfo {...}:java.lang.NullPointerException

来自分类Dev

片段-无法启动活动ComponentInfo {}:java.lang.NullPointerException Android

来自分类Dev

java.lang.RuntimeException:无法在Android中启动活动ComponentInfo

来自分类Dev

无法实例化活动 ComponentInfo(应用程序不断停止)

来自分类Dev

无法启动活动ComponentInfo解析

来自分类Dev

Android无法启动活动-java.lang.RuntimeException:无法启动活动ComponentInfo

来自分类Dev

无法实例化活动ComponentInfo-Android

来自分类Dev

Android无法实例化活动ComponentInfo

来自分类Dev

RuntimeException:无法实例化活动componentinfo Android

来自分类Dev

如何使用Web服务将条形码扫描仪以批处理模式连接到Web应用程序?

Related 相关文章

  1. 1

    如何在不安装实际的zxing应用程序的情况下集成Zxing条形码扫描仪(无法解析符号:.android.CaptureActivity)?

  2. 2

    条形码扫描仪意图启动,但无法扫描二维码?

  3. 3

    Android应用程序无法启动活动componentinfo

  4. 4

    Android应用程序空指针无法启动活动ComponentInfo

  5. 5

    应用无法启动活动componentinfo(Android)

  6. 6

    Android Studio条形码扫描仪应用程序。通过意图扫描

  7. 7

    Android关于无法启动活动componentinfo

  8. 8

    Android App无法启动活动ComponentInfo

  9. 9

    android studio 无法启动 Activity ComponentInfo

  10. 10

    为什么1000个CCD条形码接触扫描仪无法识别零?

  11. 11

    html5和jquery应用程序的条形码扫描仪

  12. 12

    从条形码扫描仪应用程序访问数据以在SQLite查询中使用

  13. 13

    用于html5和jquery应用程序的条形码扫描仪

  14. 14

    运行Windows“条形码扫描仪示例”应用程序

  15. 15

    单击按钮时应用崩溃。无法启动活动ComponentInfo

  16. 16

    Android JSON:java.lang.RuntimeException:无法启动活动ComponentInfo

  17. 17

    java.lang.RuntimeException:无法启动活动ComponentInfo Android清单

  18. 18

    无法启动活动ComponentInfo,仅来自android N的错误

  19. 19

    Android Studio:java.lang.RuntimeException:无法启动活动ComponentInfo

  20. 20

    Java / Android:无法启动活动ComponentInfo {...}:java.lang.NullPointerException

  21. 21

    片段-无法启动活动ComponentInfo {}:java.lang.NullPointerException Android

  22. 22

    java.lang.RuntimeException:无法在Android中启动活动ComponentInfo

  23. 23

    无法实例化活动 ComponentInfo(应用程序不断停止)

  24. 24

    无法启动活动ComponentInfo解析

  25. 25

    Android无法启动活动-java.lang.RuntimeException:无法启动活动ComponentInfo

  26. 26

    无法实例化活动ComponentInfo-Android

  27. 27

    Android无法实例化活动ComponentInfo

  28. 28

    RuntimeException:无法实例化活动componentinfo Android

  29. 29

    如何使用Web服务将条形码扫描仪以批处理模式连接到Web应用程序?

热门标签

归档