2016-08-20 10 views
0

ここでの最終的なゲームは、オートコンプリートテキストビューからユーザー入力を収集し、配列を分割して別のアクティビティに送ります。私はgetItemAtPositionを使用して、選択した位置のデータにアクセスし、それを分割して別のアクティビティに送信しようとしましたが、1)getItemAtPositionを使用する必要があるかどうか正確ではなく、 ...少し抽象....」のエラー 'パブリッククラスDestinationActivityが延び' を実装私はonItemClickListenerを呼び出すと 'クラスは抽象であるか、抽象を実装する必要があります'エラーを解決する方法

コードスニペット:?

public class DestinationActivity extends AppCompatActivity implements View.OnClickListener { 

AutoCompleteTextView actv; 
Button bContinue; 
String[] splitString; 
final String TAG = this.getClass().getName(); 

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

    String[] airports = getResources().getStringArray(R.array.airport_array); 

    actv = (AutoCompleteTextView)findViewById(R.id.actvDestination); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1,airports); 
    actv.setThreshold(1); 
    actv.setAdapter(adapter); 


    actv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { 

       /*getItemAtPosition() 
       splitString = actv.getText().toString().split(":"); 
       splitString[0] = splitString[0].trim(); 
       splitString[1] = splitString[1].trim();*/ 
      } 
     }); 

logcat

08-20 12:08:07.969 21346-21346/com.example.alibasmaci.maral E/AndroidRuntime: FATAL EXCEPTION: main 
                       Process: com.example.alibasmaci.maral, PID: 21346 
                       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.alibasmaci.maral/com.example.alibasmaci.maral.DestinationActivity}: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
                        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:5017) 
                        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:779) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
                        at dalvik.system.NativeStart.main(Native Method) 
                       Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 
                        at com.example.alibasmaci.maral.DestinationActivity.onCreate(DestinationActivity.java:35) 
                        at android.app.Activity.performCreate(Activity.java:5231) 
                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)  
                        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:5017)  
                        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:779)  
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)  
                        at dalvik.system.NativeStart.main(Native Method)  
08-20 12:08:15.849 22158-22158/com.example.alibasmaci.maral E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.example.alibasmaci.maral.FlightTypeActivity.access$super 
08-20 12:08:15.849 22158-22158/com.example.alibasmaci.maral W/dalvikvm: VFY: unable to resolve check-cast 23 (Landroid/app/ActivityManager$TaskDescription;) in Lcom/example/alibasmaci/maral/FlightTypeActivity; 
08-20 12:08:15.959 22158-22158/com.example.alibasmaci.maral W/dalvikvm: VFY: unable to resolve virtual method 4273: Landroid/support/v4/app/Fragment;.performDestroyView()V 
08-20 12:08:15.959 22158-22158/com.example.alibasmaci.maral W/dalvikvm: VFY: unable to resolve virtual method 4272: Landroid/support/v4/app/Fragment;.performDestroy()V 
08-20 12:08:15.969 22158-22158/com.example.alibasmaci.maral W/dalvikvm: VFY: unable to resolve virtual method 4273: Landroid/support/v4/app/Fragment;.performDestroyView()V 
08-20 12:08:15.969 22158-22158/com.example.alibasmaci.maral W/dalvikvm: VFY: unable to resolve virtual method 4272: Landroid/support/v4/app/Fragment;.performDestroy()V 

任意の考え

+2

スタックトレースを投稿できますか? –

+0

"View.OnClickListenerを実装する"を削除します。 – ThePerson

+1

例外については、 'クラスは抽象メソッドを抽象化するか、抽象メソッドを実装する必要がありますが、ここでは' onClick(View v) 'メソッドを' View.OnClickListener' –

答えて

0

ThePersonの「Implements View.OnClickListener」を削除

+0

これはどのようにスタックトレースを解決しますか?あなたはIndex Out of Bounds例外を持っています –

+0

ああ、私は多くのことが間違っていることを認識していますが、この質問は「クラスは抽象宣言されているか抽象メソッドを実装していなければなりません」と考えましたerrpr –

+0

これはかなり標準的なJavaコンパイルエラーです継承とインターフェイスの実装を理解している場合は修正する –

関連する問題