마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

에러로그와 코드좀 봐주세요 ㅠ

0 추천

 

package com.book.minipangkakao;
 
import android.app.*;  
import android.content.Intent;
import android.database.*;  
import android.os.Bundle;  
import android.util.*;  
import android.view.*;  
import android.view.View.*;  
import android.widget.*;
 
public class TestInput extends Activity implements OnClickListener{
DBHandler dbHandler;  
    EditText edtName;  
    Cursor cursor = null;  
    String[] arr = null; 
    TextView tvi;
    MainView mainview;
    int s = 0;
    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);  
        setContentView(R.layout.testrank);
        
        Button btn = (Button)findViewById(R.id.button1);          
        btn.setOnClickListener(this);  
        
        s = MainView.score;
        s *=100;
        
        edtName = (EditText)findViewById(R.id.editText1);
        TextView tvi = (TextView)findViewById(R.id.textView3);
        tvi.setText(" "+s);
    }
    
    public void onClick(View v){
    dbHandler = DBHandler.open(this);
    String sc = tvi.getText().toString();
    try {                          
            long re = dbHandler.insert(  
                    edtName.getText().toString(),   
                    sc);  // 랭킹 등록 다이얼로그 버튼 누르면 - 인풋창 - 대신 스코어는 텍스트 두개줘서 하나 제목 
            // 다른 하나 점수 넘겨받기 - 그다음에 이 함수로 전달하면 될까?
            if(re == 0){  
                Toast.makeText(this, "추가 실패", 2000).show();  
            }else{  
                Toast.makeText(this, "추가 성공", 2000).show();  
                cursor = dbHandler.selectAll();  
                arr = new String[cursor.getCount()];  
                int count = 0;  
                while(cursor.moveToNext()){  
                    String code = cursor.getString(0);  
                    String sang = cursor.getString(1);  
                    String price = cursor.getString(2);  
                    arr[count] = code + " " + sang + " " + price;  
                    count++;  
                }  
                cursor.close();  
                  
              
            }            
    } catch (Exception e) {  
        Log.i("disp", "err:" + e);  
    }
    Intent intent2 = new Intent(TestInput.this, ListTest.class);
    startActivity(intent2);
    }
}
 
아마 빨간부분이 문제가 되는거같은데 로그를봐도 널포인터익셉션이라고만나오니 뭐가 문제인지를 모르겠네요..
참고로 에디트텍스트로 입력받은 값과, 텍스트뷰에 표시된 값을 DB로 전달하는게 목표입니다.
코딩잘하고싶다 (980 포인트) 님이 2013년 7월 3일 질문

1개의 답변

0 추천

 TextView tvi = (TextView)findViewById(R.id.textView3);

지역변수로 선언을 하셨네요.

등가교환 (1,110 포인트) 님이 2013년 7월 3일 답변
아 이런 기본적인 실수를.... 해결했습니다. ㅋ 이제 랭킹 점수에따라 정렬만 하면 얼추 앱 완성이네요 ㅠ 딱 10일 걸렸네요... 간단한 게임인데도ㅠ
...