やあみんな何時間も探してるんだけど、何も見つからないようだ。ユーザーのお気に入りの引用をリスト ビューに表示して保存したいのですが、リスト ビュー アクティビティに移動できないようです。すべての助けに感謝します!ここに私のコードがあります:
パブリッククラスのお気に入りを見ると、助けが必要です。
public class Startme extends Activity {
Random gen= new Random();
int num = 0;
String[] quotes={
"End of Quotes, hit next",
"QUOTE2",
"QUOTE3",
"QUOTE4",
"QUOTE5",};
public void favorite(View F) {
Intent intent = new Intent(Startme.this, Fav.class);
intent.putExtra("quotes",num);
}
public void next(View N){
num++;
if(num == 5)
num = 0;
TextView text = (TextView) findViewById(R.id.Quote);
text.setText( quotes[num]);
TextView number = (TextView) findViewById(R.id.Qn);
number.setText(""+num);
}
public void back(View B){
if(num==0)
num=4;
else
num--;
TextView text = (TextView) findViewById(R.id.Quote);
text.setText(quotes[num]);
TextView number = (TextView) findViewById(R.id.Qn);
number.setText(""+num);
}
public void rand(View G) {
num = gen.nextInt(5);
TextView text = (TextView) findViewById(R.id.Quote);
text.setText(quotes[num]);
TextView number = (TextView) findViewById(R.id.Qn);
number.setText(""+num);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.startquotes);
TextView Dark=(TextView)findViewById(R.id.Quote);
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/font1.ttf");
Dark.setTypeface(face);
num = gen.nextInt(5);
TextView text = (TextView) findViewById(R.id.Quote);
text.setText( quotes[num]);
TextView number = (TextView) findViewById(R.id.Qn);
number.setText(""+num);
}
public void favs(View F){
Intent intent = new Intent(this, Fav.class);
startActivity(intent);
}
}
インテントで作成したリストビュークラスは次のとおりです
public class Fav extends Activity {
public ArrayAdapter<String> lvAdapter;
public ListView lv;
String extras2;
String[] datos = new String[] {extras2};
@Override
public void onCreate(Bundle savedInstanceState) {
super.setContentView(R.layout.faves);
Bundle extras = getIntent().getExtras();
extras2 = extras.getString("quotes");
lvAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,datos);
lv = (ListView) findViewById(R.id.list);
lv.setAdapter(lvAdapter);
}
}
ログキャット
07-18 04:10:30.565: E/AndroidRuntime(7370): Uncaught handler: thread main exiting due to uncaught exception
07-18 04:10:30.597: E/AndroidRuntime(7370): java.lang.RuntimeException: Unable to start activity ComponentInfo{me.me.quote/me.me.quote.Fav}: java.lang.NullPointerException
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.os.Looper.loop(Looper.java:123)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.ActivityThread.main(ActivityThread.java:4363)
07-18 04:10:30.597: E/AndroidRuntime(7370): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 04:10:30.597: E/AndroidRuntime(7370): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 04:10:30.597: E/AndroidRuntime(7370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-18 04:10:30.597: E/AndroidRuntime(7370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-18 04:10:30.597: E/AndroidRuntime(7370): at dalvik.system.NativeStart.main(Native Method)
07-18 04:10:30.597: E/AndroidRuntime(7370): Caused by: java.lang.NullPointerException
07-18 04:10:30.597: E/AndroidRuntime(7370): at me.me.quote.Fav.onCreate(Fav.java:34)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-18 04:10:30.597: E/AndroidRuntime(7370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-18 04:10:30.597: E/AndroidRuntime(7370): ... 11 more