简体   繁体   English

ListView onClick的意图

[英]Intent of ListView onClick

Hello i want to go to another activity when i click a element of a listview but i want to pass the data of that listview to the other activity. 您好,当我单击列表视图的元素时,我想转到另一个活动,但我想将该列表视图的数据传递给另一个活动。 I have search but always crash when it goes to the other activity. 我有搜索,但在进行其他活动时总是崩溃。 If i print the string it works correct, here is my code 如果我打印字符串,它可以正常工作,这是我的代码

 listaEmpresas.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Object x = arrayadapter.getItem(position);
            String titulo  = (String) x;
            Log.i("info", titulo);


            Intent i = new Intent(Display.this, MasInfo.class);
            i.putExtra("titulo", x.toString());
            startActivity(i);
        }
    });

And in the other side i have 在另一边

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mas_info);

    Bundle bundle = getIntent().getExtras();
    String titulo = bundle.getString("titulo");
}

here is the error 这是错误

 FATAL EXCEPTION: main
                                                                          Process: juanjoserodrigo.chilereclama, PID: 22293
                                                                          java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{juanjoserodrigo.chilereclama/juanjoserodrigo.chilereclama.MasInfo}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2371)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2522)
                                                                              at android.app.ActivityThread.access$800(ActivityThread.java:167)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                              at android.os.Looper.loop(Looper.java:179)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5537)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
                                                                           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                              at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:151)
                                                                              at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
                                                                              at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
                                                                              at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
                                                                              at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
                                                                              at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                                              at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                                                                              at juanjoserodrigo.chilereclama.MasInfo.<init>(MasInfo.java:15)
                                                                              at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                              at java.lang.Class.newInstance(Class.java:1572)
                                                                              at android.app.Instrumentation.newActivity(Instrumentation.java:1070)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2361)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2522) 
                                                                              at android.app.ActivityThread.access$800(ActivityThread.java:167) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                                              at android.os.Looper.loop(Looper.java:179) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5537) 
                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)

Since the getItem returns an int, your error is probably telling you that you cannot cast an integer to string. 由于getItem返回一个int,所以您的错误可能是告诉您不能将整数转换为字符串。 That should be your problem. 那应该是你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM