2013-07-25 4 views
0

android.I 프로젝트를 만들었습니다. 두 개의 Java 클래스와 두 xml 클래스가 있습니다. 내 프로젝트에 오류가 있습니다.내 프로젝트에 약간의 논리 오류가 있습니다

이 프로그램에서는 마지막 줄에 오류가 있습니다 (colleg.setadapter (adapter)). 그렇지 않으면이 파일에 문제가 없습니다. 주요 활동 :

package com.example.collegedetails; 

import android.content.ContentValues; 
import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 

public class Database extends SQLiteOpenHelper { 

    public static final String DATABASE_NAME = "collegeinfo"; 

    public Database(Context context) { 
     super(context, DATABASE_NAME, null, 1); 
    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     /* 
     * Create the employee table and populate it with sample data. In step 
     * 6, we will move these hardcoded statements to an XML document. 
     */ 
     String sql = "CREATE TABLE IF NOT EXISTS college (" 
       + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "Code INTEGER, " 
       + "CName TEXT)"; 
     db.execSQL(sql); 

     ContentValues values = new ContentValues(); 

     values.put("Code", "1309"); 
     values.put("CName", "MEENAKSHI SUNDARAJAN ENGINEERING COLLEGE"); 
     db.insert("college", null, values); 

     values.put("Code", "1447"); 
     values.put("CName", "JAWAHAR ENGINEERING COLLEGE"); 
     db.insert("college", null, values); 

     values.put("Code", "1450"); 
     values.put("CName", "LOYOLA ENGINEERING COLLEGE"); 
     db.insert("college", null, values); 

     values.put("Code", "2005"); 
     values.put("CName", "GOVERNMENT COLLEGE OF ENGINEERING"); 
     db.insert("college", null, values); 

     values.put("Code", "2005"); 
     values.put("CName", "PSG COLLEGE OF TECHNOLOGY"); 
     db.insert("college", null, values); 

     values.put("Code", "2007"); 
     values.put("CName", "COIMBATORE INSTITUTE OF TECHNOLOGY"); 
     db.insert("college", null, values); 

     values.put("Code", "2360"); 
     values.put("CName", "SUGUNA COLLEGE OF ENGINEERING ENGINEERING"); 
     db.insert("college", null, values); 

    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     db.execSQL("DROP TABLE IF EXISTS college"); 
     onCreate(db); 
    } 

} 

나는이 파일의 오류가 없다 :

package com.example.collegedetails; 



import android.os.Bundle; 
import android.app.Activity; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.view.Menu; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.ListAdapter; 
import android.widget.ListView; 
import android.widget.SimpleCursorAdapter; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

    protected EditText searchText; 
    protected SQLiteDatabase db; 
    protected Cursor cursor; 
    protected ListAdapter adapter; 
    protected TextView colleg; 


/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    db = (new Database(this)).getWritableDatabase(); 
    searchText = (EditText) findViewById (R.id.searchText); 
    colleg = (TextView) findViewById (R.id.text); 
} 

@SuppressWarnings("deprecation") 
public void search(View view) { 
    // || is the concatenation operation in SQLite 

      cursor = db.rawQuery("SELECT _id, CName FROM college", 
              new String []{"%" + Integer.parseInt(searchText.getText().toString() + "%")}); 
      adapter = new SimpleCursorAdapter(
          this, 
          R.layout.listitem, 
          cursor, 
          new String[] {"CName"}, 
          new int[] {R.id.clgName}); 
      colleg.setAdapter(adapter); 
} 

} 

나는이 파일 Database.java에 대한 오류가 없습니다. Activity_main.xml :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

       <EditText 
         android:id="@+id/searchText" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"/> 

       <Button 
         android:id="@+id/searchButton" 
         android:text="Search" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:onClick="search"/> 

     </LinearLayout> 

     <TextView 
       android:id="@+id/text" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"/> 

</LinearLayout> 

나는이 파일에 오류가 없다 ... listitem.xml :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:padding="8dp" > 

    <TextView 
     android:id="@+id/clgName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 






</RelativeLayout> 
+0

오류 스택 추적을 추가하십시오. 그것이 없으면 무엇이 잘못되었는지를 말하기 어렵습니다. – AlexVogel

답변

0

당신이 텍스트 뷰에 어댑터를 설정하고 있는가? 그것은 불가능. 컴파일 오류가 발생해야합니다.

아마도 당신이 원하는 것은 TextView를 ListView로 변경 한 다음 어댑터를 설정하는 것입니다.

관련 문제