Turkcell | Geleceği Yazanlar

Soru & Cevap

Android listview unfortunately has stopped hatasi

25.02.2015 - 21:44

merhaba arkadaslar. Sql Server veritabanindaki verilerimi listview ile goslermek istiyorum. bunun icin String dizi donduren method yazdim ve. bu methodun degerlerini String diziye artardim. bi diziyi Adapter ile Listview ile birlesdirdim ama uygulamayi calisdirdigimda "unfortunately has stopped" hatasi geliyor. Nerde hata yapmisim bulamiyorum. yardim edin bir zahmet.

 

Connection.java

[code]

package com.nursultan.borc_al;

import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import net.sourceforge.jtds.jdbc.Driver;

public class Connection {

    private java.sql.Connection baglanti;
    private Statement statement;
    private ResultSet rs;
    
  
    public Connection(){
        try {
            
            DriverManager.registerDriver(new Driver());
            baglanti = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=test1;user=example;password=***********;");
            statement = baglanti.createStatement();
            
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    
    
    private int borcumAdiCount(){
        int  count = 0;
        try {
            String sql = "SELECT count(*) from ExampleDB.dbo.tbl_borclarim";
            rs = statement.executeQuery(sql);
            
                     if(rs.next()){
                       count = rs.getInt(1);
                    }
        return count;
                    
        } catch (Exception e) {
            e.printStackTrace();
                    return 0;
        }
                

        }
        
        
        public String[] borcAdi(){
            
            
             String arrayBorcumAdi[] = new String[borcumAdiCount()];
            
            try {
                String adSql = "SELECT * from ExampleDB.dbo.tbl_borclarim";
                rs = statement.executeQuery(adSql);
                
                      int i =0;
                     while(rs.next()){
                      String array_borcum = rs.getString("borcum");
              arrayBorcumAdi [i] = array_borcum;
                      i++;
                     }    
            } catch (Exception e) {
                e.printStackTrace();
            }
                    
            return arrayBorcumAdi;
        }
        
        
        
        
        
        private int borcumCount(){
            int  count = 0;
            try {
                String sql = "SELECT count(*) from ExampleDB.dbo.tbl_borclarim";
                rs = statement.executeQuery(sql);
                
                         if(rs.next()){
                           count = rs.getInt(1);
                        }
            return count;
                        
            } catch (Exception e) {
                e.printStackTrace();
                        return 0;
            }
                    

            }
                
                
                
            public String[] borcum(){
                
            String arrayBorcum[] = new String[borcumCount()];
            
            try {
                String borcSql = "SELECT * from ExampleDB.dbo.tbl_borclarim";
                rs = statement.executeQuery(borcSql);
                
                         int i =0;
                         while(rs.next()){
                          String array_borcum = rs.getString("borclarim_adi");
                  arrayBorcum [i] = array_borcum;
                          i++;      
                                
                }
                        
            } catch (Exception e) {
                e.printStackTrace();
                        return null;
            }
                return arrayBorcum;
        }
    

}

 

[/code]

 

Borclarim.java

[code]

package com.nursultan.borc_al;

import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import net.sourceforge.jtds.jdbc.Driver;

public class Connection {

    private java.sql.Connection baglanti;
    private Statement statement;
    private ResultSet rs;
    
    public Connection(){
        try {
            
            DriverManager.registerDriver(new Driver());
            baglanti = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=ExampleDB;user=example;password=root;");
            statement = baglanti.createStatement();
            
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    
    
    private int borcumAdiCount(){
        int  count = 0;
        try {
            String sql = "SELECT count(*) from ExampleDB.dbo.tbl_borclarim";
            rs = statement.executeQuery(sql);
            
                     if(rs.next()){
                       count = rs.getInt(1);
                    }
        return count;
                    
        } catch (Exception e) {
            e.printStackTrace();
                    return 0;
        }
                

        }
        
        
        public String[] borcAdi(){
            
            
             String arrayBorcumAdi[] = new String[borcumAdiCount()];
            
            try {
                String adSql = "SELECT * from ExampleDB.dbo.tbl_borclarim";
                rs = statement.executeQuery(adSql);
                
                      int i =0;
                     while(rs.next()){
                      String array_borcum = rs.getString("borcum");
              arrayBorcumAdi [i] = array_borcum;
                      i++;
                     }    
            } catch (Exception e) {
                e.printStackTrace();
            }
                    
            return arrayBorcumAdi;
        }
        
        
        
        
        
        private int borcumCount(){
            int  count = 0;
            try {
                String sql = "SELECT count(*) from ExampleDB.dbo.tbl_borclarim";
                rs = statement.executeQuery(sql);
                
                         if(rs.next()){
                           count = rs.getInt(1);
                        }
            return count;
                        
            } catch (Exception e) {
                e.printStackTrace();
                        return 0;
            }
                    

            }
                
                
                
            public String[] borcum(){
                
            String arrayBorcum[] = new String[borcumCount()];
            
            try {
                String borcSql = "SELECT * from ExampleDB.dbo.tbl_borclarim";
                rs = statement.executeQuery(borcSql);
                
                         int i =0;
                         while(rs.next()){
                          String array_borcum = rs.getString("borclarim_adi");
                  arrayBorcum [i] = array_borcum;
                          i++;      
                                
                }
                        
            } catch (Exception e) {
                e.printStackTrace();
                        return null;
            }
                return arrayBorcum;
        }
    

}

 

[/code]

 

 

 

2954 Görüntülenme

1 Cevap

Burhan Aras
26.02.2015 - 20:03

Aldığın hata mesajını ve Yazdığın Activity'i paylaşırsan yardımcı olalım.

Sitede yorum yapabilmek için giriş yapın ya da üye olun.

Nursultan
01.03.2015 - 19:01
Boyle hata mesaji aliyorum 03-01 16:55:20.572: E/AndroidRuntime(1397): FATAL EXCEPTION: main 03-01 16:55:20.572: E/AndroidRuntime(1397): Process: com.nursultan.borc_al, PID: 1397 03-01 16:55:20.572: E/AndroidRuntime(1397): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nursultan.borc_al/com.nursultan.borc_al.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nursultan.borc_al/com.nursultan.borc_al.Borclarim}: java.lang.NullPointerException 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.access$800(ActivityThread.java:135) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.os.Handler.dispatchMessage(Handler.java:102) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.os.Looper.loop(Looper.java:136) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.main(ActivityThread.java:5001) 03-01 16:55:20.572: E/AndroidRuntime(1397): at java.lang.reflect.Method.invokeNative(Native Method) 03-01 16:55:20.572: E/AndroidRuntime(1397): at java.lang.reflect.Method.invoke(Method.java:515) 03-01 16:55:20.572: E/AndroidRuntime(1397): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 03-01 16:55:20.572: E/AndroidRuntime(1397): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 03-01 16:55:20.572: E/AndroidRuntime(1397): at dalvik.system.NativeStart.main(Native Method) 03-01 16:55:20.572: E/AndroidRuntime(1397): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nursultan.borc_al/com.nursultan.borc_al.Borclarim}: java.lang.NullPointerException 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2024) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.widget.TabHost.setCurrentTab(TabHost.java:413) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.widget.TabHost.addTab(TabHost.java:240) 03-01 16:55:20.572: E/AndroidRuntime(1397): at com.nursultan.borc_al.MainActivity.onCreate(MainActivity.java:60) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.Activity.performCreate(Activity.java:5231) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 03-01 16:55:20.572: E/AndroidRuntime(1397): ... 11 more 03-01 16:55:20.572: E/AndroidRuntime(1397): Caused by: java.lang.NullPointerException 03-01 16:55:20.572: E/AndroidRuntime(1397): at com.nursultan.borc_al.Borclarim.onCreate(Borclarim.java:37) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.Activity.performCreate(Activity.java:5231) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 03-01 16:55:20.572: E/AndroidRuntime(1397): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 03-01 16:55:20.572: E/AndroidRuntime(1397): ... 21 more

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