Soru & Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user yasinkafadar
yasinkafadar
09.01.2014 - 09:32

Selam Hasan,

Takip ettiğin eğitimde kodarı indir diye bir bölüm var sol tarafta oradan kodları indirip çalışan uygulamayı da görebilirsin.

Hatana gelecek olursa log da "com.example.test.MyListAdapter.getView(MyListAdapter.java:42) 01-09 09:31:29.019: " şu satıda hata olduğu görünüyor. Oğuz'unda dediği gibi resource bulamıyor. Yani main activity'nin xml'inin içine hem listview ı hemde textview ı koymuşsun böyle çalıştıramazsın. Listview'ı mainactivity'ine list in row una gelecek layout u da ayrı yapmalısın. Bunu örnek kodları indirince sende göreceksin.

Kolay gelsin.

Profile picture for user kcdroid
kcdroid
09.01.2014 - 04:40

Resources$NotFoundException Hatası almışsınız , yani bir yerde findViewById(R.id.xxxx)  methodunda gerek id'yi vermemişsiniz bu methodları kontrol edin Layout'daki id'lerden.

Profile picture for user www.hasansahin.com
www.hasansahin.com
09.01.2014 - 02:12

01-09 09:31:29.019: E/AndroidRuntime(273): FATAL EXCEPTION: main
01-09 09:31:29.019: E/AndroidRuntime(273): android.content.res.Resources$NotFoundException: Resource ID #0x7f080001 type #0x12 is not valid
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.content.res.Resources.getLayout(Resources.java:731)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-09 09:31:29.019: E/AndroidRuntime(273):     at com.example.test.MyListAdapter.getView(MyListAdapter.java:42)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.AbsListView.obtainView(AbsListView.java:1315)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.ListView.makeAndAddView(ListView.java:1727)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.ListView.fillDown(ListView.java:652)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.ListView.fillFromTop(ListView.java:709)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.ListView.layoutChildren(ListView.java:1580)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.AbsListView.onLayout(AbsListView.java:1147)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.View.layout(View.java:7035)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1238)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1044)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.View.layout(View.java:7035)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.View.layout(View.java:7035)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.View.layout(View.java:7035)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.View.layout(View.java:7035)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.os.Looper.loop(Looper.java:123)
01-09 09:31:29.019: E/AndroidRuntime(273):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-09 09:31:29.019: E/AndroidRuntime(273):     at java.lang.reflect.Method.invokeNative(Native Method)
01-09 09:31:29.019: E/AndroidRuntime(273):     at java.lang.reflect.Method.invoke(Method.java:521)
01-09 09:31:29.019: E/AndroidRuntime(273):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-09 09:31:29.019: E/AndroidRuntime(273):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-09 09:31:29.019: E/AndroidRuntime(273):     at dalvik.system.NativeStart.main(Native Method)
01-09 09:36:29.559: I/Process(273): Sending signal. PID: 273 SIG: 9

Profile picture for user www.hasansahin.com
www.hasansahin.com
09.01.2014 - 10:10

Country.java

[code]

package com.example.test;

 

import java.io.Serializable;

 

public class Country implements Serializable {

  private static final long serialVersionUID = 1L;

  private int id;

  private String countryName;

  private String countryCode;

 

  public Country() {

    super();

  }

 

  public Country(String countryName, String countryCode) {

    super();

  this.countryName = countryName;

  this.countryCode = countryCode;

}

 

  public String getCountryCode() {

    return countryCode;

  }

 

  public void setCountryCode(String countryCode) {

    this.countryCode = countryCode;

  }

 

  public int getId() {

    return id;

  }

 

  public void setId(int id) {

    this.id = id;

  }

 

  public String getCountryName() {

    return countryName;

  }

 

  public void setCountryName(String countryName) {

    this.countryName = countryName;

  }

}

[/code]

DBHelper.java

[code]

package com.example.test;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
 
public class DBHelper extends SQLiteOpenHelper {
  private static final String DATABASE_NAME   = "turkcellDB"; 
  // Contacts table name
  private static final String TABLE_COUNTRIES = "countries";
  public DBHelper(Context context) {
    super(context, DATABASE_NAME, null, 1);
   }
  public List<Country> getAllCountries() {
      List<Country> countries = new ArrayList<Country>();
      SQLiteDatabase db = this.getWritableDatabase();
 
      // String sqlQuery = "SELECT  * FROM " + TABLE_COUNTRIES;
      // Cursor cursor = db.rawQuery(sqlQuery, null);
 
      Cursor cursor = db.query(TABLE_COUNTRIES, new String[]{"id", "country_name", "country_code"}, null, null, null, null, null);
      while (cursor.moveToNext()) {
         Country country = new Country();
         country.setId(cursor.getInt(0));
         country.setCountryName(cursor.getString(1));
         country.setCountryCode(cursor.getString(2));
         countries.add(country);
      }
 
      return countries;
   }
  public void insertCountry(Country country) {
      SQLiteDatabase db = this.getWritableDatabase();
 
      ContentValues values = new ContentValues();
      values.put("country_name", country.getCountryName());
      values.put("country_code", country.getCountryCode());
 
      db.insert(TABLE_COUNTRIES, null, values);
      db.close();
   }
   @Override
   public void onCreate(SQLiteDatabase db) {
      String sql = "CREATE TABLE " + TABLE_COUNTRIES + "(id INTEGER PRIMARY KEY,country_name TEXT,country_code TEXT" + ")";
      Log.d("DBHelper", "SQL : " + sql);
      db.execSQL(sql);
   }
 
   @Override
   public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_COUNTRIES);
      onCreate(db);
   }
}

[/code]

MainActivity.java

[code]

package com.example.test;

import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.SharedPreferences;
import android.widget.ListView;

public class MainActivity extends Activity {

    @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
     
          final ListView customListView = (ListView) findViewById(R.id.listview);
          DBHelper dbHelper = new DBHelper(getApplicationContext());
     
          SharedPreferences settings = getSharedPreferences("SQL", 0);
          boolean firstTime = settings.getBoolean("firstTime", true);
     
          if (firstTime) {
             dbHelper.insertCountry(new Country("Turkiye", "90"));
             dbHelper.insertCountry(new Country("Amerika", "1"));
             dbHelper.insertCountry(new Country("Ingiltere", "44"));
             dbHelper.insertCountry(new Country("Almanya", "49"));
     
             SharedPreferences.Editor editor = settings.edit();
             editor.putBoolean("firstTime", false);
             editor.commit();
          }
     
          List<Country> countries = dbHelper.getAllCountries();
          MyListAdapter myListAdapter = new MyListAdapter(MainActivity.this, countries);
          customListView.setAdapter(myListAdapter);
       }
    
}

[/code]

MyListAdapter.java

[code]

package com.example.test;

import java.util.List;
 
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
 
public class MyListAdapter extends BaseAdapter {
 
   private LayoutInflater inflater;
   private List<Country>  countryList;
 
   public MyListAdapter(Activity activity, List<Country> countries) {
      inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      countryList = countries;
   }
 
   @Override
   public int getCount() {
      return countryList.size();
   }
 
   @Override
   public Object getItem(int position) {
      return countryList.get(position);
   }
 
   @Override
   public long getItemId(int position) {
      return position;
   }
 
   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
      View vi = convertView;
      if (convertView == null)
         vi = inflater.inflate(com.example.test.R.id.listview, null); // create layout from

      TextView textView = (TextView) vi.findViewById(R.id.row_textview); // user name
 
      Country country = countryList.get(position);
 
      textView.setText(country.getCountryName());
      return vi;
   }
}

[/code]

activity_main.xml

[code]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="horizontal"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin" >

 

    <TextView

        android:id="@+id/row_textview"

        android:layout_width="fill_parent"

        android:layout_height="30dp"

        android:layout_gravity="center" />

  <ListView

        android:id="@+id/listview"

        android:layout_width="fill_parent"

        android:layout_height="30dp"

        android:layout_gravity="center" />

</LinearLayout>

[/code]

aldığım hata ise

Sorry!

The application test(process com.

example.test) has stopped

unexpectedly. Please  try again.

Force close

Yasin Kafadar
09.01.2014 - 01:18
Logcat'deki hata logunuda gönderebilir misin?
Hasan
09.01.2014 - 02:55
01-09 09:31:29.019: E/AndroidRuntime(273): FATAL EXCEPTION: main 01-09 09:31:29.019: E/AndroidRuntime(273): android.content.res.Resources$NotFoundException: Resource ID #0x7f080001 type #0x12 is not valid 01-09 09:31:29.019: E/AndroidRuntime(273): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.content.res.Resources.getLayout(Resources.java:731) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.LayoutInflater.inflate(LayoutInflater.java:318) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 01-09 09:31:29.019: E/AndroidRuntime(273): at com.example.test.MyListAdapter.getView(MyListAdapter.java:42) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.AbsListView.obtainView(AbsListView.java:1315) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.ListView.makeAndAddView(ListView.java:1727) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.ListView.fillDown(ListView.java:652) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.ListView.fillFromTop(ListView.java:709) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.ListView.layoutChildren(ListView.java:1580) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.AbsListView.onLayout(AbsListView.java:1147) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.View.layout(View.java:7035) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1238) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.LinearLayout.onLayout(LinearLayout.java:1044) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.View.layout(View.java:7035) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.View.layout(View.java:7035) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.View.layout(View.java:7035) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.View.layout(View.java:7035) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.os.Handler.dispatchMessage(Handler.java:99) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.os.Looper.loop(Looper.java:123) 01-09 09:31:29.019: E/AndroidRuntime(273): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-09 09:31:29.019: E/AndroidRuntime(273): at java.lang.reflect.Method.invokeNative(Native Method) 01-09 09:31:29.019: E/AndroidRuntime(273): at java.lang.reflect.Method.invoke(Method.java:521) 01-09 09:31:29.019: E/AndroidRuntime(273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-09 09:31:29.019: E/AndroidRuntime(273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-09 09:31:29.019: E/AndroidRuntime(273): at dalvik.system.NativeStart.main(Native Method) 01-09 09:36:29.559: I/Process(273): Sending signal. PID: 273 SIG: 9