Reputation: 143
This is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity2);
Button n = (Button) findViewById(R.id.button);
Typeface typeface = Typeface.createFromAsset(getAssets(), "BebasNeue Bold.ttf");
n.setTypeface(typeface);
final TextView tv = (TextView) findViewById(R.id.textView);
Typeface face = Typeface.createFromAsset(getAssets(),
"OSP-DIN.ttf");
tv.setTypeface(face);
final String[] values = getResources().getStringArray(R.array.things_array);
n.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nextValue = values[RAND.nextInt(values.length)];
tv.setText(nextValue);
}
});
}
At the values[RAND, RAND is red and says it cannot be solved?
How can I fix this?
Matthew
logcat:
08-13 21:41:48.302 9865-9865/com.MR.brd E/Trace﹕ error opening trace file: No such file or directory (2) 08-13 21:41:48.351 9865-9865/com.MR.brd V/ActivityThread﹕ Class path: /data/app/com.MR.brd-1.apk, JNI path: /data/data/com.MR.brd/lib 08-13 21:41:48.566 9865-9865/com.MR.brd D/dalvikvm﹕ GC_FOR_ALLOC freed 52K, 4% free 8339K/8643K, paused 51ms, total 65ms 08-13 21:41:48.641 9865-9865/com.MR.brd I/dalvikvm-heap﹕ Grow heap (frag case) to 16.150MB for 8294416-byte allocation 08-13 21:41:48.716 9865-9872/com.MR.brd D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 3% free 16438K/16775K, paused 75ms, total 75ms 08-13 21:41:48.813 9865-9870/com.MR.brd D/dalvikvm﹕ GC_CONCURRENT freed 1K, 3% free 16438K/16775K, paused 15ms+1ms, total 97ms 08-13 21:41:48.948 9865-9865/com.MR.brd I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms 08-13 21:41:48.954 9865-9865/com.MR.brd D/libEGL﹕ loaded /vendor/lib/egl/libEGL_mtk.so 08-13 21:41:48.978 9865-9865/com.MR.brd D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_mtk.so 08-13 21:41:48.982 9865-9865/com.MR.brd D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_mtk.so 08-13 21:41:49.170 9865-9865/com.MR.brd E/MMUMapper﹕ fail to register MVA, unsupported format(0x5) 08-13 21:41:49.176 9865-9865/com.MR.brd D/OpenGLRenderer﹕ Enabling debug mode 0 08-13 21:41:49.436 9865-9865/com.MR.brd E/MMUMapper﹕ fail to register MVA, unsupported format(0x5) 08-13 21:41:55.045 9865-9865/com.MR.brd D/VelocityTracker﹕ Couldn't open '/dev/touch' (No such file or directory) 08-13 21:41:55.045 9865-9865/com.MR.brd D/VelocityTracker﹕ tpd read x fail: Bad file number 08-13 21:41:55.045 9865-9865/com.MR.brd D/VelocityTracker﹕ tpd read y fail: Bad file number 08-13 21:41:55.116 9865-9865/com.MR.brd V/Provider/Setting﹕ invalidate [system]: current 2613 != cached 0 08-13 21:41:55.119 9865-9865/com.MR.brd V/Provider/Setting﹕ from db cache, name = sound_effects_enabled value = 0 08-13 21:41:55.242 9865-9865/com.MR.brd W/Resources﹕ Converting to string: TypedValue{t=0x1/d=0x7f050001 a=-1 r=0x7f050001} 08-13 21:41:55.314 9865-9865/com.MR.brd I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms 08-13 21:41:55.341 9865-9865/com.MR.brd E/MMUMapper﹕ fail to register MVA, unsupported format(0x5) 08-13 21:41:55.507 9865-9865/com.MR.brd E/MMUMapper﹕ fail to register MVA, unsupported format(0x5) 08-13 21:41:55.547 9865-9865/com.MR.brd E/MMUMapper﹕ invalid operation for unregister MVA with VA(0x52d7d000) size(1536000) 08-13 21:41:55.547 9865-9865/com.MR.brd E/MMUMapper﹕ invalid operation for unregister MVA with VA(0x53264000) size(1536000) 08-13 21:41:55.560 9865-9865/com.MR.brd I/SurfaceTextureClient﹕ [void android::SurfaceTextureClient::init()] debug.stc.fps: 3000 ms 08-13 21:41:59.563 9865-9865/com.MR.brd V/Provider/Setting﹕ from settings cache , name = sound_effects_enabled value = 0 08-13 21:41:59.563 9865-9865/com.MR.brd W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000 08-13 21:41:59.564 9865-9865/com.MR.brd D/AndroidRuntime﹕ Shutting down VM 08-13 21:41:59.564 9865-9865/com.MR.brd W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x410458a8) 08-13 21:41:59.576 9865-9865/com.MR.brd E/AndroidRuntime﹕ FATAL EXCEPTION: main android.content.res.Resources$NotFoundException: String resource ID #0x0 at android.content.res.Resources.getText(Resources.java:230) at android.widget.TextView.setText(TextView.java:3856) at com.MR.brd.MyActivity2$1.onClick(MyActivity2.java:48) at android.view.View.performClick(View.java:4101) at android.view.View$PerformClick.run(View.java:17088) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:153) at android.app.ActivityThread.main(ActivityThread.java:5071) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at dalvik.system.NativeStart.main(Native Method) 08-13 21:42:01.384 9865-9865/com.MR.brd I/Process﹕ Sending signal. PID: 9865 SIG: 9
Upvotes: 0
Views: 279
Reputation: 2911
You have to do this :
Random r = new Random();
r.nextInt(values.length);
See that : http://www.tutorialspoint.com/java/util/random_nextint_inc_exc.htm
EDIT :
ArrayList<Integer> alReadyGet = new ArrayList<Integer>();
Random r = new Random();
n.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int nextValue = r.nextInt(values.length);
for (int i =0; i < alReadyGet.size(); i++) {
if (alReadyGet.get(i) == nextValue) {
nextValue = r.nextInt(values.length);
}
}
alReadyGet.add(nextValue);
tv.setText(values[nextValue]);
});
I think it will work :) Tell me :p
Upvotes: 0