2013-06-19 5 views
0

조각 활동의 데이터를 다른 클래스로 전달하려고합니다. 그러나 "생성자 의도 (새 View.OnClickListener() {}, 클래스)가 정의되지 않았습니다."라는 오류가 발생합니다. 이 코드 여기Android - 생성자가 정의되지 않았습니다. 오류

'Intent intent = new Intent(this, WebSocket_Connector.class);' 

는 code..how 내가 'ID'문자열 값을 전달할 수있다? 텐트 constrcutor의

public class Myoffers_Fragment extends Fragment { 

    private final WebSocketConnection mConnection = new WebSocketConnection(); 

    public static Fragment newInstance(Myoffers context, int pos, float scale) 
    { 
     Bundle b = new Bundle(); 
     b.putInt("pos", pos); 
     b.putFloat("scale", scale); 
     return Fragment.instantiate(context, Myoffers_Fragment.class.getName(), b); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     if (container == null) { 
      return null; 
     } 

     LinearLayout l = (LinearLayout) inflater.inflate(R.layout.mf, container, false); 

     int pos = this.getArguments().getInt("pos"); 
     TextView tv = (TextView) l.findViewById(R.id.text); 
     tv.setText("Product " + pos); 



     ImageButton product_photo = (ImageButton) l.findViewById(R.id.myoffer_image); 


     if (pos == 0) { 
      product_photo.setImageResource(R.drawable.myoffers_0); 
      product_photo.setOnClickListener(new ImageButton.OnClickListener(){ 
       public void onClick(View v){ 
        String id1 = "Product0"; 
        Intent intent = new Intent(this, WebSocket_Connector.class); 
        intent.putExtra("KeyToAccessData", id1); 
        startActivity(intent); 
        Log.d(TAG, "Current product is : " + id1); 
        Log.d(TAG, id1 + "is sent to server!"); 
       } 
      }); 
     } 

답변

3

하나가 있었던 파라미터 Context.class 객체 걸린다. 따라서 귀하의 this은 유효한 컨텍스트 또는 활동이어야합니다.

매개 변수

  1. packageContext이 클래스를 구현하는 응용 프로그램 패키지의 컨텍스트 : 문서에서.
  2. 의도에 사용되는 구성 요소 클래스입니다.

new Intent(getActivity(), WebSocket_Connector.class); 
+0

감사를 시도 해달라고. 그것은 작동합니다. – user2500696

+0

환영합니다 – Blackbelt

+0

마음에 들지 않으면 "Android - Autobahn Websocket 보내는 메시지 오류 (NullPointerException)"질문을 확인해주세요. .. 아무도 대답하지 않습니다. :( – user2500696

0

로 변경

new Intent(this, WebSocket_Connector.class); 

왜이

Intent intent = new Intent(Myoffers_Fragment.this, WebSocket_Connector.class); 
관련 문제