Können sie bitte einen Blick auf diese haben? MainActivity.java Code:Programm nicht geöffnet, aber es gibt keinen Kompilierung-Fehler
package com.mi47.test;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView;
gridView = (GridView)findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (parent.getId()==R.id.grid_view){
switch(position){
case 0:{
startActivity(new Intent(this,DotDraw.class));
break;
}
case 1:{
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
break;
}
case 2:{
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
break;
}
case 3:{
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
break;
}
case 4:{
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
break;
}
case 5:{
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
break;
}
default:{
Toast.makeText(MainActivity.this, "Click Inside" + position, Toast.LENGTH_SHORT).show();
}
}
}
}
@Override
public void onClick(View v) {
}
}
activity_main.xml Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="3"
android:verticalSpacing="72dp"
android:horizontalSpacing="48dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
kompiliert ohne Warnung/Fehler. Die DotDraw-Klasse ist nur eine neue Seite, die geöffnet wird, nichts Wichtiges. Irgendeine Idee, warum Programm immer schließt?
Logcat: 03-15 18: 41: 12,567 8655-8655 /? E/Android Runtime: FATAL AUSNAHME: Haupt Prozess: com.mi47.test, PID: 8655 java.lang.RuntimeException: Kann Aktivität ComponentInfo {com.mi47.test/com.mi47.test.MainActivity} starten: java. lang.RuntimeException: Rufen Sie setOnClickListener nicht für eine AdapterView auf. Sie wollen wahrscheinlich setOnItemClickListener statt bei android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2665) bei android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2726) bei android.app.ActivityThread.-wrap12 (ActivityThread. Java) bei android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1477) bei android.os.Handler.dispatchMessage (Handler.java:102) bei android.os.Looper.loop (Looper.java: 154) bei android.app.ActivityThread.main (ActivityThread.java:6119) bei java.lang.reflect.Method.invoke (native Methode) bei com.android.internal.os.ZygoteInit $ MethodAndArg sCaller.run (ZygoteInit.java:886) bei com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776) verursacht durch: java.lang.RuntimeException: rufen Sie SetOnClickListener nicht für ein AdapterView auf. Wahrscheinlich möchten Sie setOnItemClickListener stattdessen bei android.widget.AdapterView.setOnClickListener (AdapterView.java: 800) bei com.mi47.test.MainActivity.onCreate (MainActivity.java:24) bei android.app.Activity.performCreate (Activity .java-: 6679) bei android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1118) bei android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2618) bei android.app.ActivityThread.handleLaunchActivity (ActivityThread.java : 2726) bei android.app.ActivityThread.-wrap12 (ActivityThread.java) bei android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1477) bei android.os.Handler.dispatchMessage (Handler.java:102) bei android.os.Looper.loop (Looper.java:154) bei android.app.ActivityThread.main (ActivityThread.java:6119) bei java.lang.reflect.Method.invoke (Native Methode) bei com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:886) bei com.android.internal.os.ZygoteInit.main (ZygoteInit .java: 776)
poste den logcat Fehler während des Absturzes – rafsanahmad007
Füge den lgcat Fehler hier ein und zeige auch die dotdraw Klasse Danke –
Beachten Sie, dass der Compiler nicht (kann nicht!) Ihnen sagen, ob Ihr Programm korrekt ist. Es kann Ihnen nur Fehler sagen, die es so schlecht machen, dass es es nicht verarbeiten kann. "es kompiliert" ist überhaupt kein Indikator für Korrektheit. – dsh