2016-08-20 78 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

移除「實現View.OnClickListener」由ThePerson提供

+0

這是如何解決堆棧跟蹤?你有一個索引超出例外 –

+0

哦,我知道有很多事情是錯誤的,但我想這個問題是專門爲「類必須被宣佈爲抽象或實現抽象方法」errpr –

+0

這是一個非常標準的Java編譯錯誤 - 它很簡單如果你瞭解繼承和接口實現,那麼去修復它 –

相關問題