2017-12-21 4 views
0

Ich versuche, mit Listenansicht zu arbeiten und auf klicken Sie auf eine andere Aktivität öffnen, aber wenn ich die App auf Mobile laufen es zwingen zu stoppen. Unten ist mein Code für HaupttätigkeitForce Stop, wenn App in Moblie ausgeführt

public class MainActivity extends AppCompatActivity implements 
AdapterView.OnItemClickListener { 
String TopicList[]={"jan","Feb"}; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ListView listView=(ListView) findViewById(R.id.topic); 
    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(this); 
} 

@Override 
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
    if (position==0){ 

     Intent myInternt= new Intent(view.getContext(),Vlookup.class); 
     startActivityForResult(myInternt,0); 

    } 
    if (position==1){ 

     Intent myInternt= new Intent(view.getContext(),Hlookup.class); 
     startActivityForResult(myInternt,1); 
    } 
} 
    } 

Blockquote

unterhalb meiner Maindest.xml Datei `

Code hier eingeben

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name=".Vlookup" /> 
    <activity android:name=".Hlookup"></activity> 
</application> 
+0

die Stack-Trace Ausnahme Post – elmorabea

+0

stellen Sie sicher, Vlookup.class und Hlookup.class werden in Manifest deklariert. –

+0

poste deine 'logcat' –

Antwort

0

Ersetzen Sie diese Zeile aus dem Code : -

ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1); 

von: -

ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList); 

Sie hinzufügen, nicht Liste daher an Adapter stürzt, Und auch das Manifest prüfen, ob die Aktivität wird hinzugefügt.

+0

Erledigt, aber gleiche Ausgabe ArrayAdapter Adapter = neuer ArrayAdapter (this, android.R.layout.simple_list_item_1, TopicList); –

0

Vergewissern Sie sich, definiert MainActivity, Vlookup und HLOOKUP in Ihrem Manifest

<activity android:name=".MainActivity"/> 
    <activity android:name=".Vlookup"/> 
    <activity android:name=".Hlookup"/> 

und ersetzen

ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1); 

von

ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,TopicList); 
Verwandte Themen