2016-04-04 6 views
1

zu laden Ich verwende NavigationBar so in einem der Fragmente bekomme ich Fehler beim Implementieren klicken auf Kartenansicht. Obwohl der Klick funktioniert, wie es mit Toast getestet wurde, funktioniert die Verwendung von Absicht, um zu einer anderen Aktivität zu gelangen, nicht.Ich erhalte Fehler beim Versuch, eine Aktivität aus der Adapterklasse

java.lang.RuntimeException: Unable to start activity ComponentInfo{minor.da.com.donationapp/minor.da.com.donationapp.SecondPage}: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class <unknown> 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:148) 
     at android.app.ActivityThread.main(ActivityThread.java:5417) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class <unknown> 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:539) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
     at android.app.Activity.setContentView(Activity.java:2172) 
     at minor.da.com.donationapp.SecondPage.onCreate(SecondPage.java:15) 
     at android.app.Activity.performCreate(Activity.java:6251) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 

XML

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

    <TextView 
     android:layout_width="241dp" 
     android:layout_height="202dp" 
     android:textAppearance="@android:color/darker_gray" 
     android:text="Hello link to your card view" 
     android:id="@+id/textView2" 
     android:gravity="center|center_horizontal|fill" 
     android:enabled="true" 
     android:editable="false" 
     android:textAlignment="@android:integer/config_shortAnimTime" 
     android:textColor="#f4086172" 
     android:textStyle="bold|italic" /> 
</LinearLayout> 

Adapter-Klasse CODE

import android.content.Context; 
import android.content.Intent; 
import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

import java.util.Collections; 
import java.util.List; 


public class vizAdapter extends RecyclerView.Adapter<vizAdapter.Myviewholder>  { 
private LayoutInflater inflater; 
private Context context; 

List<information> data= Collections.emptyList(); 
public vizAdapter(Context context, List<information> data){ 
    inflater = LayoutInflater.from(context); 
    this.context=context; 
    this.data=data; 

} 
@Override 
public Myviewholder onCreateViewHolder(ViewGroup parent, int viewType) { 

    View view=inflater.inflate(R.layout.custom_row, parent, false); 
    Myviewholder holder=new Myviewholder(view); 
    return holder; 
} 

@Override 
public void onBindViewHolder(Myviewholder holder, int position) { 
    information current=data.get(position); 
    holder.text.setText(current.title); 
    holder.icon.setImageResource(current.iconId); 

} 


@Override 
public int getItemCount() { 
    return data.size(); 
} 


class Myviewholder extends RecyclerView.ViewHolder{ 
    TextView text; 
    ImageView icon; 
    public Myviewholder(View itemView) { 

     super(itemView); 
     text= (TextView) itemView.findViewById(R.id.listtext); 
     icon= (ImageView) itemView.findViewById(R.id.listicon); 
     getView(itemView); 


    } 
} 
public View getView(View v){ 

    v.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent i=new Intent(context,SecondPage.class); 
      i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
      context.startActivity(i); 
      Toast.makeText(context,"hello successful",Toast.LENGTH_SHORT); 
     } 
    }); 
    return v; 
} 

}

             
+1

Ihr Layout-Code benötigt? –

+0

danke @ PhanVănLinh ich bin neu hier, vielen Dank für Ihre Hilfe. – 7rocker

+0

@ 7rocker ist das XML in Ihrer Frage das Layout der 'SecondPage' Aktivität. Wenn nicht, bitte posten Sie das 'SecondPage' Layout –

Antwort

Verwandte Themen