开发者

Unable to create link to other activity?

开发者 https://www.devze.com 2023-02-15 00:15 出处:网络
i am new to android i am unable to create link from my current list view to other activities: This is my code:

i am new to android i am unable to create link from my current list view to other activities: This is my code:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_advanced_main);
        ListView lv1 = (ListView)findViewById(android.R.id.list);

        ArrayList<HashMap<String,Object>> mylist = new ArrayList<HashMap<String,Object>>();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("image", R.drawable.mj_icon);
        map.put("text1", "Michael Jackson");
        map.put("text2", "King Of Pop");
        map.put("to",R.drawable.arrow_icon );
        mylist.add(map);
        map = new HashMap<String,Object>();
        map.put("image", R.drawable.sachin_icon);
        map.put("text1", "Sachin Tendulkar");
        map.put("text2", "The Master Blaster");
        map.put("to",R.drawable.arrow_icon );
        mylist.add(map);
        map = new HashMap<String,Object>();
        map.put("image", R.drawable.hrithik_icon);
        map.put("text1", "Hrithik Roshan");
        map.put("text2", "Bollywood Actor");
        map.put("to",R.drawable.arrow_icon );
        mylist.add(map);
        map = new HashMap<String,Object>();
       map.put("image", R.drawable.maradona_icon);
        map.put("text1", "Diego Maradona");
        map.put("text2", "The God Of Soccer");
        map.put("to",R.drawable.arrow_icon);
        mylist.add(map);


        SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.list_advanced,
                new String[] {"image", "text1", "text2", "to"}, new int[] {R.id.movieicon, R.id.name, R.id.description, R.id.img});


        setListAdapter(mSchedule);

       lv1=getListView();
        lv1.setTextFilterEnabled(true);
        lv1.setOnItemClickListener(new OnItemClickListener(){
            public void onItemClick(AdapterView<?> parent,View view,int position,long id){

                switch(position)
                {
                case 0:
                Intent obj = new Intent(advancedlistview.this,michaeljackson.class);
                startActivityForResult(obj,0);
                Log.i("test","tst");
                break;
                case 1:

              Intent obj1 = new Intent(advancedlistview.this,Sachin.class);
                System.out.println("hello");
              startActivity(obj1); 
            break;
    开发者_如何学Python            case 2:
                     Intent obj2 = new Intent(advancedlistview.this,Hrithik.class);
                    startActivity(obj2); 
                    break;
                case 3:
                    Intent obj3 = new Intent(advancedlistview.this,Maradona.class);
                    startActivity(obj3);
                    break;
                }
            }
        });


    }

My log cat is::

03-03 12:35:05.093: DEBUG/AndroidRuntime(4899): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 03-03 12:35:05.093: DEBUG/AndroidRuntime(4899): CheckJNI is ON 03-03 12:35:05.632: DEBUG/AndroidRuntime(4899): --- registering native functions --- 03-03 12:35:07.531: DEBUG/AndroidRuntime(4899): Shutting down VM 03-03 12:35:07.563: DEBUG/dalvikvm(4899): Debugger has detached; object registry had 1 entries 03-03 12:35:07.563: INFO/AndroidRuntime(4899): NOTE: attach of thread 'Binder Thread #3' failed 03-03 12:35:08.950: DEBUG/AndroidRuntime(4909): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 03-03 12:35:08.950: DEBUG/AndroidRuntime(4909): CheckJNI is ON 03-03 12:35:09.585: DEBUG/AndroidRuntime(4909): --- registering native functions --- 03-03 12:35:11.784: INFO/ActivityManager(61): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.ex.dp/.demoProject1 } 03-03 12:35:11.877: DEBUG/AndroidRuntime(4909): Shutting down VM 03-03 12:35:11.877: INFO/AndroidRuntime(4909): NOTE: attach of thread 'Binder Thread #3' failed 03-03 12:35:11.877: DEBUG/dalvikvm(4909): Debugger has detached; object registry had 1 entries 03-03 12:35:15.608: DEBUG/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol 03-03 12:40:15.687: DEBUG/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol 03-03 12:45:15.735: DEBUG/SntpClient(61): request time failed: java.net.SocketException: Address family not supported by protocol

My console is giving error:

[2011-03-03 12:35:08 - ddms]null java.lang.NullPointerException at com.android.ddmlib.Client.sendAndConsume(Client.java:571) at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142) at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) at com.android.ddmlib.Client.getJdwpPacket(Client.java:670) at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)


Are your classes listed in the AndroidManifest.xml file? Android Manifest Info

Each Activity has to be in the manifest or the app will crash. Try This:

<activity android:name=".michaeljackson" android:label="michaeljackson" />
<activity android:name=".Sachin" android:label="Sachin" />
<activity android:name=".Hrithik" android:label="Hrithik" />
<activity android:name=".Maradona" android:label="Maradona" />


I think your context is incorrect. Try switching

advancedlistview.this

for

getApplicationContext();

If that doesn't work, please post your stack trace.

Edit: you have a comma in your first startActivityForResult(obj --> , <-- 0) I dont think you meant to have that there. Also, try using curly brackets in your switch statement to separate the blocks.

0

精彩评论

暂无评论...
验证码 换一张
取 消